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

update(build/registry): allow optional auth to update-index cmd #219

Merged
merged 1 commit into from
Jan 29, 2024
Merged
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
19 changes: 17 additions & 2 deletions build/registry/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,24 @@ func doPushToOCI(registryFilename, gitTag string) (*string, error) {
}

func rulesOciRepos(registryEntries *Registry, ociRepoPrefix string) (map[string]string, error) {
var user, token string
var repo *repository.Repository
var err error
ociClient := authn.NewClient(authn.WithCredentials(&auth.EmptyCredential))
var foundUser, foundToken bool
var cred *auth.Credential

user, foundUser = os.LookupEnv(RegistryUserEnv)
token, foundToken = os.LookupEnv(RegistryTokenEnv)

if !foundUser && !foundToken {
cred = &auth.EmptyCredential
} else {
cred = &auth.Credential{
Username: user,
Password: token,
}
}
ociClient := authn.NewClient(authn.WithCredentials(cred))
ociEntries := make(map[string]string)

for _, entry := range registryEntries.Rulesfiles {
Expand Down Expand Up @@ -255,7 +270,7 @@ func main() {

updateIndexCmd := &cobra.Command{
Use: "update-index <registryFilename> <indexFilename>",
Short: "Update an index file for artifacts distribution using registry data",
Short: "Update an index file for artifacts distribution using registry data, authenticates to the registry if REGISTRY_USER, REGISTRY_TOKEN are set",
Args: cobra.ExactArgs(2),
DisableFlagsInUseLine: true,
RunE: func(c *cobra.Command, args []string) error {
Expand Down
Loading