Skip to content
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
6 changes: 6 additions & 0 deletions pkg/assetsclient/oci/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ func NewClient() (*Client, error) {
client := auth.Client{
Credential: auth.StaticCredential(config.registry, auth.Credential{
AccessToken: config.accessToken,
Username: config.username,
Password: config.password,
}),
}

Expand All @@ -79,6 +81,8 @@ func NewClientForRepository(repo string) (*Client, error) {
client := auth.Client{
Credential: auth.StaticCredential(config.registry, auth.Credential{
AccessToken: config.accessToken,
Username: config.username,
Password: config.password,
}),
}

Expand All @@ -101,6 +105,8 @@ func (*factory) NewClient(ctx context.Context) (assetsclient.Client, error) {
client := auth.Client{
Credential: auth.StaticCredential(config.registry, auth.Credential{
AccessToken: config.accessToken,
Username: config.username,
Password: config.password,
}),
}

Expand Down
44 changes: 34 additions & 10 deletions pkg/assetsclient/oci/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,16 @@ const (
envOCIRegistry = "OCI_REGISTRY"
envOCIRepository = "OCI_REPOSITORY"
envOCIAccessToken = "OCI_ACCESS_TOKEN"
envOCIUsername = "OCI_USERNAME"
envOCIPassword = "OCI_PASSWORD"
)

type ociConfig struct {
registry string
repository string
accessToken string
username string
password string
}

func newOCIConfig() (ociConfig, error) {
Expand All @@ -50,13 +54,23 @@ func newOCIConfig() (ociConfig, error) {
config.repository = val

val = os.Getenv(envOCIAccessToken)
if val == "" {
return ociConfig{}, fmt.Errorf("environment variable %s is not set", envOCIAccessToken)
if val != "" {
base64AccessToken := base64.StdEncoding.EncodeToString([]byte(val))
config.accessToken = base64AccessToken
} else {
val = os.Getenv(envOCIUsername)
if val == "" {
return ociConfig{}, fmt.Errorf("environment variable %s is not set", envOCIUsername)
}
config.username = val

val = os.Getenv(envOCIPassword)
if val == "" {
return ociConfig{}, fmt.Errorf("environment variable %s is not set", envOCIPassword)
}
config.password = val
}

base64AccessToken := base64.StdEncoding.EncodeToString([]byte(val))
config.accessToken = base64AccessToken

return config, nil
}

Expand All @@ -70,12 +84,22 @@ func newOCIConfigWithoutRepository() (ociConfig, error) {
config.registry = val

val = os.Getenv(envOCIAccessToken)
if val == "" {
return ociConfig{}, fmt.Errorf("environment variable %s is not set", envOCIAccessToken)
if val != "" {
base64AccessToken := base64.StdEncoding.EncodeToString([]byte(val))
config.accessToken = base64AccessToken
} else {
val = os.Getenv(envOCIUsername)
if val == "" {
return ociConfig{}, fmt.Errorf("environment variable %s is not set", envOCIUsername)
}
config.username = val

val = os.Getenv(envOCIPassword)
if val == "" {
return ociConfig{}, fmt.Errorf("environment variable %s is not set", envOCIPassword)
}
config.password = val
}

base64AccessToken := base64.StdEncoding.EncodeToString([]byte(val))
config.accessToken = base64AccessToken

return config, nil
}