Skip to content
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

DEVOPS-3537 Use ENV var instead of command line flag #153

Merged
merged 4 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,29 @@ For a full list of functionalities, run `ridectl --help`

## Installing `ridectl`

# Mac-os
### Mac-os
```
curl -L "https://github.com/Ridecell/ridectl/releases/latest/download/ridectl_macos.zip" -o ./ridectl_macos.zip
unzip ridectl_macos.zip
chmod 0755 ridectl
sudo cp ridectl /usr/local/bin/ridectl
```
**Note:** When running `ridectl` for first time, Mac OS will not allow the binary to execute. So, to solve this issue, navigate to `System Prefrences` > `Security & Privacy` and in `General` section, allow `ridectl` to open.
# Linux
### Linux
```
curl -L "https://github.com/Ridecell/ridectl/releases/latest/download/ridectl_linux.zip" -o ./ridectl_linux.zip
unzip ridectl_linux.zip
chmod 0755 ridectl
sudo cp ridectl /usr/local/bin/ridectl
```

## Environment variables

List of environment variables used by `ridectl`:

| Environment variable | Value | Description |
| -------------------- | ------------- | ---------------- |
| `RIDECTL_SKIP_UPGRADE` | `true\|false` | If set `true`, skips auto-upgrade of ridectl version; used in Github actions workflows |
| `RIDECTL_SKIP_AWS_SSO` | `true\|false` | If set `true`, ridectl uses default AWS configuration instead of AWS SSO; used in Github actions workflows |
| `EDITOR` | `vim`, `code`, etc | Sets editor's binary path for `ridectl edit` command |
| `RIDECTL_TSH_CHECK` | `true\|false` | If set `false`, ridectl does not check for tsh login profile; used in Github actions workflows |
9 changes: 7 additions & 2 deletions pkg/cmd/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package cmd

import (
"context"
"os"
"regexp"
"strings"

Expand All @@ -26,13 +27,16 @@ import (
"github.com/aws/aws-sdk-go-v2/config"
"github.com/manifoldco/promptui"
"github.com/pkg/errors"
"github.com/pterm/pterm"
)

func getAWSConfig(roleName, region string) (aws.Config, error) {
var cfg aws.Config

// If no-aws-sso flag is provided, do not use AWS SSO creds, instead load default configuration.
if noAWSSSO {
// If RIDECTL_SKIP_AWS_SSO env var is set to true, do not use AWS SSO creds, instead load default configuration.
noAWSSSO := os.Getenv("RIDECTL_SKIP_AWS_SSO")

if noAWSSSO == "true" {
// Load the Shared AWS Configuration (~/.aws/config)
cfg, err := config.LoadDefaultConfig(context.TODO(), config.WithRegion(region))
if err != nil {
Expand All @@ -45,6 +49,7 @@ func getAWSConfig(roleName, region string) (aws.Config, error) {
startUrl, accountId := utils.LoadAWSAccountInfo(ridectlConfigFile)
if startUrl == "" || accountId == "" {
updateAWSAccountInfo = true
pterm.Info.Println("If you don't know what to do, refer FAQs: https://docs.google.com/document/d/1v6lbH4NgN6rHBHpELWrcQ4CyqwVeSgeP/preview")

prompt := promptui.Prompt{
Label: "Enter AWS SSO Start url",
Expand Down
2 changes: 0 additions & 2 deletions pkg/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ var (
versionFlag bool
version string
inCluster bool
noAWSSSO bool
ridectlHomeDir string
ridectlConfigFile string
)
Expand Down Expand Up @@ -73,7 +72,6 @@ func init() {
rootCmd.PersistentFlags().StringVar(&kubeconfigFlag, "kubeconfig", "", "(optional) absolute path to the kubeconfig file")
rootCmd.Flags().BoolVar(&versionFlag, "version", false, "--version")
rootCmd.PersistentFlags().BoolVar(&inCluster, "incluster", false, "(optional) use in cluster kube config")
rootCmd.PersistentFlags().BoolVar(&noAWSSSO, "no-aws-sso", false, "(optional) do not use AWS SSO for AWS authentication; use shared default configuration instead.")

// Display announcement banner if present
displayAnnouncementBanner()
Expand Down