Skip to content

misc: add proper parsing of token for org relay#44

Merged
sheensantoscapadngan merged 2 commits intomainfrom
misc/add-proper-parsing-of-token-for-org-relay
Oct 23, 2025
Merged

misc: add proper parsing of token for org relay#44
sheensantoscapadngan merged 2 commits intomainfrom
misc/add-proper-parsing-of-token-for-org-relay

Conversation

@sheensantoscapadngan
Copy link
Member

@sheensantoscapadngan sheensantoscapadngan commented Oct 23, 2025

Description 📣

This PR adds ENV parsing of token value for org relay in systemd install

Type ✨

  • Bug fix
  • New feature
  • Improvement
  • Breaking change
  • Documentation

Tests 🛠️

# Here's some code block to paste some code snippets

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Greptile Overview

Greptile Summary

Added environment variable parsing for the token parameter in the relay systemd install command. The change allows users to specify the INFISICAL_TOKEN via environment variable in addition to the --token flag, consistent with how relay-auth-secret is already handled.

Key changes:

  • Modified relaySystemdInstallCmd to use GetCmdFlagOrEnvWithDefaultValue for token parsing (packages/cmd/relay.go:170)
  • Added INFISICAL_TOKEN_ENV_NAME constant to centralize the env var name (packages/gateway-v2/constants.go:16)
  • Updated error message to reflect both flag and env parsing

Improvements:

  • The change follows existing patterns in the codebase (similar to how relay-auth-secret is handled on line 204)
  • Validation logic at line 213-214 still works correctly to ensure token is required for non-instance types

Confidence Score: 4/5

  • This PR is safe to merge with minimal risk
  • The changes are straightforward and follow existing patterns in the codebase. The logic correctly handles token parsing from both flags and environment variables, with proper validation. One minor style issue was identified regarding hardcoded string usage in a different file (systemd.go), but this doesn't affect functionality.
  • No files require special attention - changes are simple and consistent with existing code patterns

Important Files Changed

File Analysis

Filename Score Overview
packages/cmd/relay.go 4/5 Added env variable parsing for token in systemd install command; error message updated appropriately
packages/gateway-v2/constants.go 5/5 Added INFISICAL_TOKEN_ENV_NAME constant for consistency

Sequence Diagram

sequenceDiagram
    participant User
    participant CLI as relay systemd install
    participant Util as GetCmdFlagOrEnvWithDefaultValue
    participant Systemd as InstallRelaySystemdService
    participant FS as File System

    User->>CLI: sudo infisical relay systemd install
    CLI->>Util: GetCmdFlagOrEnvWithDefaultValue("token", ["INFISICAL_TOKEN"], "")
    Util->>Util: Check --token flag
    alt Flag not empty
        Util-->>CLI: Return flag value
    else Flag empty
        Util->>Util: Check INFISICAL_TOKEN env
        alt Env not empty
            Util-->>CLI: Return env value
        else Env empty
            Util-->>CLI: Return "" (default)
        end
    end
    
    CLI->>CLI: Validate: if type != "instance" && token == ""
    alt Validation fails
        CLI->>User: Error: token is required
    else Validation passes
        CLI->>Systemd: InstallRelaySystemdService(token, ...)
        Systemd->>FS: Write /etc/infisical/relay.conf
        Note over Systemd,FS: Includes token config
        Systemd->>FS: Write /etc/systemd/system/infisical-relay.service
        Systemd->>CLI: Success
        CLI->>User: Successfully installed
    end
Loading

Additional Comments (1)

  1. packages/relay/systemd.go, line 74 (link)

    style: hardcoded string should use constant gatewayv2.INFISICAL_TOKEN_ENV_NAME for consistency

2 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@sheensantoscapadngan sheensantoscapadngan merged commit 8aae7ea into main Oct 23, 2025
3 checks passed
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