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

Support GITHUB_TOKEN for HTTP Requests to github.com #912

Merged
merged 16 commits into from
Jan 11, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
config update
Listener430 committed Jan 9, 2025

Unverified

This user has not yet uploaded their public signing key.
commit 1d531073fc3431268ad3672fe98873cfcea27905
14 changes: 11 additions & 3 deletions internal/exec/validate_stacks.go
Original file line number Diff line number Diff line change
@@ -98,7 +98,7 @@ func ValidateStacks(atmosConfig schema.AtmosConfiguration) error {
} else if u.FileExists(atmosManifestJsonSchemaFileAbsPath) {
atmosManifestJsonSchemaFilePath = atmosManifestJsonSchemaFileAbsPath
} else if u.IsURL(atmosConfig.Schemas.Atmos.Manifest) {
atmosManifestJsonSchemaFilePath, err = downloadSchemaFromURL(atmosConfig.Schemas.Atmos.Manifest)
atmosManifestJsonSchemaFilePath, err = downloadSchemaFromURL(atmosConfig)
if err != nil {
return err
}
@@ -363,7 +363,10 @@ func checkComponentStackMap(componentStackMap map[string]map[string][]string) ([
}

// downloadSchemaFromURL downloads the Atmos JSON Schema file from the provided URL
func downloadSchemaFromURL(manifestURL string) (string, error) {
func downloadSchemaFromURL(atmosConfig schema.AtmosConfiguration) (string, error) {

manifestURL := atmosConfig.Schemas.Atmos.Manifest

parsedURL, err := url.Parse(manifestURL)
if err != nil {
return "", fmt.Errorf("invalid URL '%s': %w", manifestURL, err)
@@ -379,7 +382,12 @@ func downloadSchemaFromURL(manifestURL string) (string, error) {
atmosManifestJsonSchemaFilePath := filepath.Join(tempDir, fileName)
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
RegisterCustomDetectors()

// Register custom detectors if InjectGithubToken is enabled
if atmosConfig.Core.InjectGithubToken {
RegisterCustomDetectors()
}

client := &getter.Client{
Ctx: ctx,
Dst: atmosManifestJsonSchemaFilePath,
8 changes: 4 additions & 4 deletions internal/exec/vendor_model.go
Original file line number Diff line number Diff line change
@@ -244,7 +244,6 @@ func downloadAndInstall(p *pkgAtmosVendor, dryRun bool, atmosConfig schema.Atmos
name: p.name,
}
}

// Create temp directory
tempDir, err := os.MkdirTemp("", fmt.Sprintf("atmos-vendor-%d-*", time.Now().Unix()))
if err != nil {
@@ -268,9 +267,10 @@ func downloadAndInstall(p *pkgAtmosVendor, dryRun bool, atmosConfig schema.Atmos
switch p.pkgType {
case pkgTypeRemote:
// Use go-getter to download remote packages

// Register custom detectors
RegisterCustomDetectors()
// Register custom detectors if InjectGithubToken is enabled
if atmosConfig.Core.InjectGithubToken {
RegisterCustomDetectors()
}

client := &getter.Client{
Ctx: ctx,
11 changes: 9 additions & 2 deletions internal/exec/vendor_model_component.go
Original file line number Diff line number Diff line change
@@ -126,7 +126,10 @@ func installComponent(p *pkgComponentVendor, atmosConfig schema.AtmosConfigurati
case pkgTypeRemote:
tempDir = filepath.Join(tempDir, sanitizeFileName(p.uri))

RegisterCustomDetectors()
// Register custom detectors if InjectGithubToken is enabled
if atmosConfig.Core.InjectGithubToken {
RegisterCustomDetectors()
}
client := &getter.Client{
Ctx: context.Background(),
// Define the destination where the files will be stored. This will create the directory if it doesn't exist
@@ -188,7 +191,11 @@ func installMixin(p *pkgComponentVendor, atmosConfig schema.AtmosConfiguration)
defer cancel()
switch p.pkgType {
case pkgTypeRemote:
RegisterCustomDetectors()

// Register custom detectors if InjectGithubToken is enabled
if atmosConfig.Core.InjectGithubToken {
RegisterCustomDetectors()
}
client := &getter.Client{
Ctx: ctx,
Dst: filepath.Join(tempDir, p.mixinFilename),
6 changes: 5 additions & 1 deletion internal/exec/vendor_utils.go
Original file line number Diff line number Diff line change
@@ -709,7 +709,11 @@ func (d *CustomGitHubDetector) Detect(src, _ string) (string, bool, error) {

token := os.Getenv("GITHUB_TOKEN")
if token != "" {
u.User = url.UserPassword("x-access-token", token)
user := u.User.Username()
pass, _ := u.User.Password()
if user == "" && pass == "" {
u.User = url.UserPassword("x-access-token", token)
}
}

// Convert the URL to a git URL
3 changes: 3 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
@@ -88,6 +88,8 @@ var (
Frequency: "daily",
},
},
Core: schema.CoreConfig{
InjectGithubToken: true},
}
)

@@ -114,6 +116,7 @@ func InitCliConfig(configAndStacksInfo schema.ConfigAndStacksInfo, processStacks
// Default configuration values
v.SetDefault("components.helmfile.use_eks", true)
v.SetDefault("components.terraform.append_user_agent", fmt.Sprintf("Atmos/%s (Cloud Posse; +https://atmos.tools)", version.Version))
v.SetDefault("core.inject_github_token", true)

// Process config in system folder
configFilePath1 := ""
5 changes: 5 additions & 0 deletions pkg/schema/schema.go
Original file line number Diff line number Diff line change
@@ -35,6 +35,7 @@ type AtmosConfiguration struct {
// registry through to the yaml parsing functions when !store is run and to pass the registry to the hooks
// functions to be able to call stores from within hooks.
Stores store.StoreRegistry `yaml:"stores_registry,omitempty" json:"stores_registry,omitempty" mapstructure:"stores_registry"`
Core CoreConfig `yaml:"core,omitempty" json:"core,omitempty" mapstructure:"core,omitempty"`
}

type Terminal struct {
@@ -157,6 +158,10 @@ type Version struct {
Check VersionCheck `yaml:"check,omitempty" mapstructure:"check"`
}

type CoreConfig struct {
InjectGithubToken bool `yaml:"inject_github_token,omitempty" mapstructure:"inject_github_token"`
}

type ArgsAndFlagsInfo struct {
AdditionalArgsAndFlags []string
SubCommand string
4 changes: 3 additions & 1 deletion website/docs/cli/configuration/configuration.mdx
Original file line number Diff line number Diff line change
@@ -110,6 +110,8 @@ settings:
terminal:
max_width: 120 # Maximum width for terminal output
pager: true # Use pager for long output
core:
inject_github_token: true
```
</File>

@@ -670,7 +672,7 @@ setting `ATMOS_STACKS_BASE_PATH` to a path in `/localhost` to your local develop
| ATMOS_LOGS_FILE | logs.file | The file to write Atmos logs to. Logs can be written to any file or any standard file descriptor, including `/dev/stdout`, `/dev/stderr` and `/dev/null`). If omitted, `/dev/stdout` will be used |
| ATMOS_LOGS_LEVEL | logs.level | Logs level. Supported log levels are `Trace`, `Debug`, `Info`, `Warning`, `Off`. If the log level is set to `Off`, Atmos will not log any messages (note that this does not prevent other tools like Terraform from logging) |
| ATMOS_SETTINGS_LIST_MERGE_STRATEGY | settings.list_merge_strategy | Specifies how lists are merged in Atmos stack manifests. The following strategies are supported: `replace`, `append`, `merge` |
| ATMOS_VERSION_CHECK_ENABLED | version.check.enabled | Enable/disable Atmos version checks for updates to the newest release |
| ATMOS_VERSION_CHECK_ENABLED | version.check.enabled | Enable/disable Atmos version checks for updates to the newest release |

### Context