Skip to content

Commit

Permalink
Merge pull request #927 from JcGKitten/master
Browse files Browse the repository at this point in the history
BUG: Set rest server credentials in repository URL
  • Loading branch information
Kidswiss authored Mar 7, 2024
2 parents 4e8a420 + dd64772 commit b9cd317
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
4 changes: 3 additions & 1 deletion api/v1/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package v1
import (
"fmt"
"reflect"
"strings"

corev1 "k8s.io/api/core/v1"

Expand Down Expand Up @@ -275,5 +276,6 @@ func (in *RestServerSpec) EnvVars(vars map[string]*corev1.EnvVarSource) map[stri

// String returns "rest:URL"
func (in *RestServerSpec) String() string {
return fmt.Sprintf("rest:%s", in.URL)
protocol, url, _ := strings.Cut(in.URL, "://")
return fmt.Sprintf("rest:%s://%s:%s@%s", protocol, "$(USER)", "$(PASSWORD)", url)
}
2 changes: 1 addition & 1 deletion api/v1/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ var tests = map[string]struct {
cfg.RestPasswordEnvName: {SecretKeyRef: newSecretRef("password")},
cfg.RestUserEnvName: {SecretKeyRef: newSecretRef("user")},
},
expectedRepositoryString: "rest:https://server",
expectedRepositoryString: "rest:https://$(USER):$(PASSWORD)@server",
},
}

Expand Down
15 changes: 14 additions & 1 deletion operator/executor/envvarconverter.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ func (e *EnvVarConverter) setEntry(key string, value envVarEntry) {
// are set the string will have precedence.
func (e *EnvVarConverter) Convert() []corev1.EnvVar {
vars := make([]corev1.EnvVar, 0)
var repositoryVar corev1.EnvVar
var repositoryVarSet bool
for key, value := range e.Vars {

envVar := corev1.EnvVar{
Name: key,
}
Expand All @@ -59,7 +62,17 @@ func (e *EnvVarConverter) Convert() []corev1.EnvVar {
} else if value.stringEnv != nil {
envVar.Value = *value.stringEnv
}
vars = append(vars, envVar)
if key == cfg.ResticRepositoryEnvName {
// set repository env var at the end so the rest backend url
// can use previous set rest server credentials
repositoryVar = envVar
repositoryVarSet = true
} else {
vars = append(vars, envVar)
}
}
if repositoryVarSet {
vars = append(vars, repositoryVar)
}
return vars
}
Expand Down

0 comments on commit b9cd317

Please sign in to comment.