Skip to content

Commit

Permalink
Add basic auth option for the oci client
Browse files Browse the repository at this point in the history
Signed-off-by: Roman Hros <roman.hros@dnation.cloud>
  • Loading branch information
chess-knight authored and janiskemper committed Sep 2, 2024
1 parent 5030a18 commit fe31669
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
2 changes: 2 additions & 0 deletions config/manager/credentials.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ data:
oci-registry: ${OCI_REGISTRY_B64:=""}
oci-repository: ${OCI_REPOSITORY_B64:=""}
oci-access-token: ${OCI_ACCESS_TOKEN_B64:=""}
oci-username: ${OCI_USERNAME_B64:=""}
oci-password: ${OCI_PASSWORD_B64:=""}
10 changes: 10 additions & 0 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ spec:
secretKeyRef:
name: cso-cluster-stack-variables
key: oci-access-token
- name: OCI_USERNAME
valueFrom:
secretKeyRef:
name: cso-cluster-stack-variables
key: oci-username
- name: OCI_PASSWORD
valueFrom:
secretKeyRef:
name: cso-cluster-stack-variables
key: oci-password
args:
- --leader-elect=true
- --log-level=info
Expand Down
2 changes: 2 additions & 0 deletions pkg/assetsclient/oci/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,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
24 changes: 19 additions & 5 deletions pkg/assetsclient/oci/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,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 @@ -51,12 +55,22 @@ 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

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

return config, nil
}

0 comments on commit fe31669

Please sign in to comment.