-
Notifications
You must be signed in to change notification settings - Fork 48
Add API calls logging #4755
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add API calls logging #4755
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
69e7ba6
Investigate 4712 case
lukaszgryglicki ee11137
Fix typos
lukaszgryglicki b5be8bb
Dump repo
lukaszgryglicki 9ae1c0c
Merge pull request #4752 from linuxfoundation/unicron-4712-notify-cla…
lukaszgryglicki 0ab0695
Add logging v3/v4 API calls
lukaszgryglicki d979108
Go fmt
lukaszgryglicki 95e67b9
Merge pull request #4754 from linuxfoundation/unicron-add-logging-go-…
lukaszgryglicki ba3649c
Merge branch 'main' into dev
lukaszgryglicki e022325
Fix a single typo
lukaszgryglicki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -255,3 +255,5 @@ cover.out | |
|
|
||
| # Local env vars | ||
| .env | ||
| src.txt | ||
| src.txt.* | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| #!/usr/bin/env python3 | ||
| import argparse, os, sys, pathlib, io, subprocess, shutil | ||
|
|
||
| DEFAULT_EXCLUDE_DIRS = {".git", ".hg", ".svn", ".idea", ".vscode", "dist", "build", "out", "target", ".next", ".nuxt", ".tox", "__pycache__"} | ||
| DEFAULT_EXCLUDE_GLOBS = {"*.min.js", "*.map", "*.lock", "*.jar", "*.zip", "*.gz", "*.tgz", "*.bz2", "*.7z", "*.png", | ||
| "*.jpg", "*.jpeg", "*.gif", "*.webp", "*.ico", "*.pdf", "*.woff", "*.woff2", "*.ttf", "*.otf", | ||
| "*.mp4", "*.mov", "*.avi", "*.mp3", "*.flac", "*.wav", "*.iso", "*.bin", "*.secret"} | ||
| DEFAULT_INCLUDE_EXTS = { | ||
| ".go",".ts",".tsx",".js",".jsx",".json",".yml",".yaml",".toml",".ini",".env",".md",".txt", | ||
| ".proto",".graphql",".sql",".py",".rs",".java",".c",".h",".cpp",".hpp",".cc",".m",".mm", | ||
| ".rb",".php",".pl",".sh",".bash",".zsh",".fish",".ps1",".bat",".dockerfile",".gradle",".properties" | ||
| } | ||
| ALSO_ALLOW_NAME = {"dockerfile", "makefile", "makefile.win"} | ||
|
|
||
| def is_text_file(path: str, max_probe=65536) -> bool: | ||
| try: | ||
| with open(path, "rb") as f: | ||
| chunk = f.read(max_probe) | ||
| if b"\x00" in chunk: | ||
| return False | ||
| chunk.decode("utf-8", errors="strict") | ||
| return True | ||
| except Exception: | ||
| return False | ||
|
|
||
| def should_keep_by_ext(p: pathlib.Path, include_exts) -> bool: | ||
| if include_exts and p.suffix.lower() not in include_exts: | ||
| if p.name.lower() not in ALSO_ALLOW_NAME: | ||
| return False | ||
| return True | ||
|
|
||
| def should_exclude_by_glob(rel: str) -> bool: | ||
| from pathlib import PurePath | ||
| pp = PurePath(rel) | ||
| for g in DEFAULT_EXCLUDE_GLOBS: | ||
| if pp.match(g): | ||
| return True | ||
| return False | ||
|
|
||
| def git_available() -> bool: | ||
| return shutil.which("git") is not None | ||
|
|
||
| def iter_files_git(repo_root: pathlib.Path): | ||
| """ | ||
| Yields repo files not ignored by .gitignore/.git/info/exclude/global ignores. | ||
| Uses: git ls-files --cached --others --exclude-standard | ||
| """ | ||
| cmd = ["git", "-C", str(repo_root), "ls-files", "-z", "--cached", "--others", "--exclude-standard", "--"] | ||
| out = subprocess.check_output(cmd) | ||
| for rel_b in out.split(b"\x00"): | ||
| if not rel_b: | ||
| continue | ||
| rel = rel_b.decode("utf-8", errors="replace") | ||
| p = repo_root / rel | ||
| if p.is_file(): | ||
| yield p | ||
|
|
||
| def iter_files_walk(repo_root: pathlib.Path): | ||
| """ | ||
| Fallback: walk the tree and filter manually (does NOT perfectly mirror .gitignore). | ||
| """ | ||
| for root, dirs, files in os.walk(repo_root): | ||
| # prune common junk dirs | ||
| dirs[:] = [d for d in dirs if d not in DEFAULT_EXCLUDE_DIRS] | ||
| for name in files: | ||
| p = pathlib.Path(root) / name | ||
| rel = p.relative_to(repo_root).as_posix() | ||
| if should_exclude_by_glob(rel): | ||
| continue | ||
| yield p | ||
|
|
||
| def iter_repo_files(repo_root: pathlib.Path, use_git: bool): | ||
| if use_git: | ||
| yield from iter_files_git(repo_root) | ||
| else: | ||
| # use git if available and .git exists | ||
| if (repo_root/".git").exists() and git_available(): | ||
| yield from iter_files_git(repo_root) | ||
| else: | ||
| yield from iter_files_walk(repo_root) | ||
|
|
||
| def write_repo(repo_root: pathlib.Path, out_prefix: pathlib.Path, max_mb: float, force_git: bool): | ||
| repo_root = repo_root.resolve() | ||
| max_bytes = int(max_mb * (1024**2)) | ||
| chunk_idx = 1 | ||
| bytes_in_chunk = 0 | ||
|
|
||
| def open_chunk(idx): | ||
| suffix = "" if idx == 1 else f".part{idx}" | ||
| path = out_prefix if idx == 1 else out_prefix.with_name(out_prefix.name + suffix) | ||
| return path, io.open(path, "w", encoding="utf-8", newline="\n") | ||
|
|
||
| out_path, fh = open_chunk(chunk_idx) | ||
|
|
||
| count = 0 | ||
| for p in iter_repo_files(repo_root, force_git): | ||
| rel = p.relative_to(repo_root).as_posix() | ||
| if should_exclude_by_glob(rel): | ||
| continue | ||
| if not should_keep_by_ext(p, DEFAULT_INCLUDE_EXTS): | ||
| continue | ||
| if not is_text_file(str(p)): | ||
| continue | ||
|
|
||
| header = f"File: {rel}\nContents:\n" | ||
| try: | ||
| with io.open(p, "r", encoding="utf-8") as rf: | ||
| content = rf.read() | ||
| except UnicodeDecodeError: | ||
| with io.open(p, "r", encoding="latin-1") as rf: | ||
| content = rf.read() | ||
|
|
||
| block = header + content.rstrip() + "\n\n" | ||
| block_bytes = len(block.encode("utf-8")) | ||
|
|
||
| if bytes_in_chunk + block_bytes > max_bytes and bytes_in_chunk > 0: | ||
| fh.close() | ||
| chunk_idx += 1 | ||
| out_path, fh = open_chunk(chunk_idx) | ||
| bytes_in_chunk = 0 | ||
|
|
||
| fh.write(block) | ||
| bytes_in_chunk += block_bytes | ||
| count += 1 | ||
|
|
||
| fh.close() | ||
| return chunk_idx, count | ||
|
|
||
| def main(): | ||
| ap = argparse.ArgumentParser(description="Dump repo sources to 'File: ...\\nContents:\\n...' format, honoring .gitignore.") | ||
| ap.add_argument("--repo", default=".", help="Path to repo root (default: .)") | ||
| ap.add_argument("--out", default="src.txt", help="Output filename/prefix") | ||
| ap.add_argument("--max-mb", type=float, default=100.0, help="Max size per output file in MB (default: 100MB)") | ||
| ap.add_argument("--git-mode", action="store_true", help="Force using 'git ls-files' (best accuracy for .gitignore).") | ||
| args = ap.parse_args() | ||
|
|
||
| repo_root = pathlib.Path(args.repo) | ||
| out_prefix = pathlib.Path(args.out) | ||
|
|
||
| try: | ||
| chunks, files = write_repo(repo_root, out_prefix, args.max_mb, args.git_mode) | ||
| print(f"Wrote {chunks} file(s); included {files} text source files. Upload the first file and any '.partN' files too.") | ||
| except subprocess.CalledProcessError as e: | ||
| print("Warning: Git mode failed; falling back to walk() (may include gitignored files).", file=sys.stderr) | ||
| chunks, files = write_repo(repo_root, out_prefix, args.max_mb, force_git=False) | ||
| print(f"Wrote {chunks} file(s); included {files} text source files. Upload the first file and any '.partN' files too.") | ||
|
|
||
| if __name__ == "__main__": | ||
| sys.exit(main()) | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| #!/bin/bash | ||
| # API_URL=https://api-gw.platform.linuxfoundation.org/cla-service | ||
| # API_URL=https://api-gw.dev.platform.linuxfoundation.org/cla-service | ||
| # STAGE=prod ./utils/scan.sh projects project_id d8cead54-92b7-48c5-a2c8-b1e295e8f7f1 | ||
| # STAGE=prod ./utils/scan.sh projects-cla-groups project_name 'Cloud Native Computing Foundation (CNCF)' | ||
| # STAGE=prod ./utils/scan.sh companies company_name 'Red Hat, Inc.' | ||
| # STAGE=prod ./utils/scan.sh users lf_username lgryglicki | ||
| # API_URL=https://api-gw.platform.linuxfoundation.org/cla-service ./utils/notify_cla_managers_example_post.sh | ||
|
|
||
| if [ -z "$TOKEN" ] | ||
| then | ||
| # source ./auth0_token.secret | ||
| TOKEN="$(cat ./auth0.token.secret)" | ||
| fi | ||
|
|
||
| if [ -z "$TOKEN" ] | ||
| then | ||
| echo "$0: TOKEN not specified and unable to obtain one" | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [ -z "$XACL" ] | ||
| then | ||
| XACL="$(cat ./x-acl.secret)" | ||
| fi | ||
|
|
||
| if [ -z "$XACL" ] | ||
| then | ||
| echo "$0: XACL not specified and unable to obtain one" | ||
| exit 2 | ||
| fi | ||
|
|
||
| if [ -z "$API_URL" ] | ||
| then | ||
| export API_URL="http://localhost:5001" | ||
| fi | ||
|
|
||
| data='{ | ||
| "companyName": "Cloud Native Computing Foundation (CNCF)", | ||
| "claGroupID": "d8cead54-92b7-48c5-a2c8-b1e295e8f7f1", | ||
| "userID": "2c895887-d33a-11ef-9205-4e2baeedbda2", | ||
|
lukaszgryglicki marked this conversation as resolved.
|
||
| "list": [ | ||
| { "email": "lukaszgryglicki@o2.pl", "name": "Lukasz Gryglicki 1" }, | ||
| { "email": "lgryglicki@cncf.io", "name": "Lukasz Gryglicki 2" }, | ||
| { "email": "lgryglicki@contractor.linuxfoundation.org", "name": "Lukasz Gryglicki 3" } | ||
|
lukaszgryglicki marked this conversation as resolved.
|
||
| ] | ||
| }' | ||
|
|
||
| curl -s -XPOST -H "X-ACL: ${XACL}" -H "Authorization: Bearer ${TOKEN}" -H "Content-Type: application/json" "${API_URL}/v4/notify-cla-managers" -d "$data" | jq -r '.' | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.