Skip to content

Added support to fetch credentials based on profile from existing Turbot CLI configuration. #1

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sdsubhajitdas
Copy link

@sdsubhajitdas sdsubhajitdas commented May 7, 2025

Environment Configuration Changes Summary

1. Support for Two Credential Methods

  • Set 1: Direct Environment Variables
    • TURBOT_GRAPHQL_ENDPOINT
    • TURBOT_ACCESS_KEY_ID
    • TURBOT_SECRET_ACCESS_KEY
  • Set 2: CLI Credentials YAML File
    • TURBOT_CLI_PROFILE (required)
    • TURBOT_CLI_CREDENTIALS_PATH (optional, defaults to $HOME/.config/turbot/credentials.yml)

2. Validation Logic

  • Ensures at least one complete set of credentials is provided.
  • Throws clear, specific error messages if neither set is provided, indicating what is missing and what is required.

3. YAML Credentials Parsing

  • If using CLI credentials, reads the YAML file from the specified or default path.
  • Extracts credentials for the specified profile.
  • Maps YAML fields to config:
    • workspaceTURBOT_GRAPHQL_ENDPOINT (appends /api/latest/graphql)
    • accessKeyTURBOT_ACCESS_KEY_ID
    • secretKeyTURBOT_SECRET_ACCESS_KEY

4. Robustness and Error Handling

  • Checks for the existence of the credentials file, the specified profile, and required fields.
  • Provides clear error messages for missing or misconfigured credentials.

5. TypeScript Non-Null Assertion

  • Uses the ! operator to assure TypeScript that environment variables are set after validation.

Result:

  • The configuration is now flexible, robust, and user-friendly, supporting both direct environment variable credentials and profile-based YAML credentials, with clear validation and error reporting.

…in env.ts. Added support for reading credentials from a YAML file and improved error messaging for missing variables.
@sdsubhajitdas sdsubhajitdas requested a review from Copilot May 7, 2025 04:59
@sdsubhajitdas sdsubhajitdas self-assigned this May 7, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for fetching credentials based on a profile from an existing Turbot CLI configuration.

  • Introduces CLI-based credential lookup by reading a YAML file from a default or provided path.
  • Adds logic to differentiate between direct environment variable credentials and CLI credentials.
Comments suppressed due to low confidence (2)

src/config/env.ts:9

  • [nitpick] The variable name 'set1' is ambiguous. Consider renaming it to something more descriptive like 'directCredentialVars' to better convey its purpose.
const set1 = [

src/config/env.ts:15

  • [nitpick] The variable name 'set2' is ambiguous. Consider renaming it to something like 'cliCredentialEnvVars' for clarity.
const set2 = [

Comment on lines 51 to +52
// Export validated environment variables
const config = {
TURBOT_GRAPHQL_ENDPOINT: process.env.TURBOT_GRAPHQL_ENDPOINT!,
TURBOT_ACCESS_KEY_ID: process.env.TURBOT_ACCESS_KEY_ID!,
TURBOT_SECRET_ACCESS_KEY: process.env.TURBOT_SECRET_ACCESS_KEY!,
let config: any = {
Copy link
Preview

Copilot AI May 7, 2025

Choose a reason for hiding this comment

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

Avoid using 'any' for the config variable. Defining a proper type or interface would improve type safety and maintainability.

Copilot uses AI. Check for mistakes.

Copy link
Contributor

Choose a reason for hiding this comment

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

agreed

Copy link
Contributor

@e-gineer e-gineer left a comment

Choose a reason for hiding this comment

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

Please review and fix comments.

if (endpoint.endsWith('/')) {
endpoint = endpoint.slice(0, -1);
}
endpoint = `${endpoint}/api/latest/graphql`;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should it always add this to the endpoint? Or should we check for it first?

(This might be something to improve across both credential models!)

hasSet2 = true;
} else {
throw new Error(
`❌ TURBOT_CLI_CREDENTIALS_PATH is required because the default credentials path could not be determined (HOME is not set).`
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's remove the emoji's. They are not really required and smell like an LLM.

Comment on lines 51 to +52
// Export validated environment variables
const config = {
TURBOT_GRAPHQL_ENDPOINT: process.env.TURBOT_GRAPHQL_ENDPOINT!,
TURBOT_ACCESS_KEY_ID: process.env.TURBOT_ACCESS_KEY_ID!,
TURBOT_SECRET_ACCESS_KEY: process.env.TURBOT_SECRET_ACCESS_KEY!,
let config: any = {
Copy link
Contributor

Choose a reason for hiding this comment

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

agreed

@e-gineer
Copy link
Contributor

e-gineer commented May 7, 2025

Please update the README with these new credential model. You should definitely include examples. I think the CLI profile method you've added should be the preferred / first example.

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