Skip to content

Chore/token extraction#1523

Merged
KambleSahil3 merged 3 commits intomainfrom
chore/token-extraction
Nov 24, 2025
Merged

Chore/token extraction#1523
KambleSahil3 merged 3 commits intomainfrom
chore/token-extraction

Conversation

@KambleSahil3
Copy link
Copy Markdown
Contributor

@KambleSahil3 KambleSahil3 commented Nov 21, 2025

What ?

  • multi architecture token extraction

Summary by CodeRabbit

  • Bug Fixes
    • Improved API key/token extraction reliability by adding case-insensitive pattern matching and an alternative fallback parsing method, increasing robustness across varied log formats.
    • Minor formatting adjustment to the extraction logic.
    • Added consideration for cross-platform (BSD/macOS) compatibility in the extraction steps.

✏️ Tip: You can customize this high-level summary in your review settings.

Signed-off-by: sahil.kamble@ayanworks.com <sahil.kamble@ayanworks.com>
Signed-off-by: sahil.kamble@ayanworks.com <sahil.kamble@ayanworks.com>
@KambleSahil3 KambleSahil3 self-assigned this Nov 21, 2025
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Nov 21, 2025

Walkthrough

Two shell scripts in the agent-provisioning module were changed to improve token extraction from container logs: primary extraction now uses case-insensitive sed matching, and a fallback awk-based extraction runs if the primary result is empty.

Changes

Cohort / File(s) Summary
Token extraction logic enhancement
apps/agent-provisioning/AFJ/scripts/docker_start_agent.sh, apps/agent-provisioning/AFJ/scripts/start_agent.sh
Replaced previous sed extraction with a printf → sed pipeline using case-insensitive "KEY: ..." pattern. Added a fallback that uses awk to locate flexible "API KEY"/"APIKEY" appearances and take the last field when primary extraction is empty. Minor formatting/newline adjustment.

Sequence Diagram(s)

sequenceDiagram
    participant Container as Container logs
    participant Script as Start script
    participant Sed as sed (case-insensitive)
    participant Awk as awk fallback
    participant Output as Token output

    Container->>Script: provide logs
    Script->>Sed: run printf | sed -En (case-insensitive KEY:)
    Sed-->>Script: token (may be empty)
    alt token non-empty
        Script->>Output: print token
    else token empty
        Script->>Awk: scan logs for API[ _]?KEY pattern, extract last field
        Awk-->>Script: token (fallback)
        Script->>Output: print token
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Changes are homogeneous across two scripts and focus on shell text-processing logic.
  • Pay attention to:
    • sed flags and portability (BSD/macOS vs GNU sed) and the use of -E/-n
    • correctness of the case-insensitive pattern and edge cases in log formats
    • awk field extraction behavior when lines contain extra punctuation or quoting

Poem

🐰
I hop through logs both thick and thin,
Sniffing "KEY:" to find the win.
If sed naps, awk leaps in view —
A token found, the start is true. ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title 'Chore/token extraction' clearly and concisely summarizes the main change: updating token extraction logic across multiple shell scripts to support multi-architecture environments.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore/token-extraction

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
apps/agent-provisioning/AFJ/scripts/start_agent.sh (1)

246-247: Consider using [[ for conditional expressions in bash.

In bash scripts, [[ is preferred over [ for conditional tests as it's safer and supports additional operators. The SonarCloud analysis flagged this pattern.

Apply this diff:

- [ -z "$token" ] && \
- token=$(printf "%s" "$container_logs" | awk '/[Aa][Pp][Ii][ -]*[Kk][Ee][Yy]/ {print $NF; exit}')
+ [[ -z "$token" ]] && \
+ token=$(printf "%s" "$container_logs" | awk '/[Aa][Pp][Ii][ -]*[Kk][Ee][Yy]/ {print $NF; exit}')

Note: This refactor is specific to start_agent.sh (which uses #!/bin/bash). The corresponding file docker_start_agent.sh uses #!/bin/sh (POSIX shell) where [ is the standard and [[ is not available.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ffcd2f1 and bf85ee4.

📒 Files selected for processing (2)
  • apps/agent-provisioning/AFJ/scripts/docker_start_agent.sh (1 hunks)
  • apps/agent-provisioning/AFJ/scripts/start_agent.sh (1 hunks)
🧰 Additional context used
🪛 GitHub Check: SonarCloud Code Analysis
apps/agent-provisioning/AFJ/scripts/start_agent.sh

[failure] 246-246: Use '[[' instead of '[' for conditional tests. The '[[' construct is safer and more feature-rich.

See more on https://sonarcloud.io/project/issues?id=credebl_platform&issues=AZqmu1IOWA287qJVF6QN&open=AZqmu1IOWA287qJVF6QN&pullRequest=1523

Comment thread apps/agent-provisioning/AFJ/scripts/docker_start_agent.sh Outdated
Comment thread apps/agent-provisioning/AFJ/scripts/start_agent.sh Outdated
Signed-off-by: sahil.kamble@ayanworks.com <sahil.kamble@ayanworks.com>
@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
apps/agent-provisioning/AFJ/scripts/start_agent.sh (1)

246-246: Minor: Consider using [[ for safer conditional testing.

SonarCloud suggests using [[ instead of [ for conditional tests, which is a bash best practice. While the current code works correctly, [[ provides better robustness and clarity:

- if [ -z "$token" ]; then
+ if [[ -z "$token" ]]; then
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bf85ee4 and 79f6ac3.

📒 Files selected for processing (2)
  • apps/agent-provisioning/AFJ/scripts/docker_start_agent.sh (1 hunks)
  • apps/agent-provisioning/AFJ/scripts/start_agent.sh (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/agent-provisioning/AFJ/scripts/docker_start_agent.sh
🧰 Additional context used
🪛 GitHub Check: SonarCloud Code Analysis
apps/agent-provisioning/AFJ/scripts/start_agent.sh

[failure] 246-246: Use '[[' instead of '[' for conditional tests. The '[[' construct is safer and more feature-rich.

See more on https://sonarcloud.io/project/issues?id=credebl_platform&issues=AZqmu1IOWA287qJVF6QN&open=AZqmu1IOWA287qJVF6QN&pullRequest=1523

🔇 Additional comments (2)
apps/agent-provisioning/AFJ/scripts/start_agent.sh (2)

242-243: Fixed: sed regex now uses correct unescaped parentheses for extended mode.

The critical issue from the previous review has been successfully resolved. The capture group now correctly uses ([^ ]*) instead of the previously incorrect \([^ ]*\) when running with the -E (extended regex) flag.


245-249: Fallback extraction strategy is sound.

The awk-based fallback appropriately handles cases where BSD/macOS sed may fail. The approach of searching for case-insensitive "API KEY" or "API-KEY" patterns and extracting the last field is reasonable for multi-architecture compatibility.

@KambleSahil3 KambleSahil3 merged commit a9e78e9 into main Nov 24, 2025
8 checks passed
@KambleSahil3 KambleSahil3 deleted the chore/token-extraction branch November 24, 2025 05:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants