Skip to content

Commit 0d79309

Browse files
mclasmeierMoritz Clasmeier
andauthored
Export ROX_USERNAME (expected by some test suites) (#95)
Co-authored-by: Moritz Clasmeier <mclasmeier@redhat.com>
1 parent 862c463 commit 0d79309

2 files changed

Lines changed: 19 additions & 14 deletions

File tree

cmd/subshell.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,22 @@ func spawnSubshell(d *deployer.Deployer, log *logger.Logger) error {
3232
endpoint, password, caCertFile, kubeContext, exposure := d.GetDeploymentInfo()
3333

3434
if endpoint != "" {
35-
env = append(env, fmt.Sprintf("API_ENDPOINT=%s", endpoint))
36-
env = append(env, fmt.Sprintf("ROX_ENDPOINT=%s", endpoint))
37-
env = append(env, fmt.Sprintf("ROX_BASE_URL=https://%s", endpoint))
35+
env = append(env, fmt.Sprintf("API_ENDPOINT=%q", endpoint))
36+
env = append(env, fmt.Sprintf("ROX_ENDPOINT=%q", endpoint))
37+
env = append(env, fmt.Sprintf("ROX_BASE_URL='https://%s'", endpoint))
3838
}
3939

4040
if password != "" {
41-
env = append(env, fmt.Sprintf("ROX_ADMIN_PASSWORD=%s", password))
41+
env = append(env, fmt.Sprintf("ROX_ADMIN_PASSWORD=%q", password))
4242
}
4343

4444
if caCertFile != "" {
45-
env = append(env, fmt.Sprintf("ROX_CA_CERT_FILE=%s", caCertFile))
45+
env = append(env, fmt.Sprintf("ROX_CA_CERT_FILE=%q", caCertFile))
4646
}
4747

48+
env = append(env, fmt.Sprintf("ROX_USERNAME=%q", deployer.AdminUsername))
4849
env = append(env, "ROXIE_SHELL=1")
49-
env = append(env, fmt.Sprintf("name=acs@%s", kubeContext))
50+
env = append(env, fmt.Sprintf("name='acs@%s'", kubeContext))
5051

5152
haproxyAvailable := isHAProxyAvailable()
5253

@@ -60,7 +61,7 @@ func spawnSubshell(d *deployer.Deployer, log *logger.Logger) error {
6061
if err != nil {
6162
log.Warningf("Failed to start HAProxy: %v", err)
6263
} else {
63-
env = append(env, fmt.Sprintf("ROXIE_HAPROXY_CFG_FILE=%s", haproxyConfigPath))
64+
env = append(env, fmt.Sprintf("ROXIE_HAPROXY_CFG_FILE=%q", haproxyConfigPath))
6465
haproxyStarted = true
6566
defer cleanupHAProxy(haproxyCmd, haproxyConfigPath)
6667
}

internal/deployer/deployer.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ var (
3232

3333
pauseReconcileAnnotationKey = "stackrox.io/pause-reconcile"
3434

35+
// AdminUsername is the default admin username for StackRox Central
36+
AdminUsername = "admin"
37+
3538
// TODO(#91): at some point this will get out of date. If we filter by the app.../part-of
3639
// label anyway, then maybe we should just delete all resource kinds present on cluster?
3740
// also we should use the fully-qualified types
@@ -1071,14 +1074,15 @@ func (d *Deployer) cleanupTempDir(path string, description string) {
10711074
func (d *Deployer) writeEnvrcFile(ctx context.Context, exposure string, portForwardWanted bool) error {
10721075
endpoint := strings.TrimPrefix(d.centralEndpoint, "https://")
10731076

1074-
content := fmt.Sprintf(`export API_ENDPOINT="%s"
1075-
export ROX_ENDPOINT="%s"
1076-
export ROX_BASE_URL="https://%s"
1077-
export ROX_ADMIN_PASSWORD="%s"
1078-
export ROX_CA_CERT_FILE="%s"
1079-
`, endpoint, endpoint, endpoint, d.centralPassword, d.roxCACertFile)
1077+
var content strings.Builder
1078+
fmt.Fprintf(&content, "export API_ENDPOINT=%q\n", endpoint)
1079+
fmt.Fprintf(&content, "export ROX_ENDPOINT=%q\n", endpoint)
1080+
fmt.Fprintf(&content, "export ROX_BASE_URL='https://%s'\n", endpoint)
1081+
fmt.Fprintf(&content, "export ROX_USERNAME=%q\n", AdminUsername)
1082+
fmt.Fprintf(&content, "export ROX_ADMIN_PASSWORD=%q\n", d.centralPassword)
1083+
fmt.Fprintf(&content, "export ROX_CA_CERT_FILE=%q\n", d.roxCACertFile)
10801084

1081-
if err := os.WriteFile(d.envrcFile, []byte(content), 0600); err != nil {
1085+
if err := os.WriteFile(d.envrcFile, []byte(content.String()), 0600); err != nil {
10821086
return fmt.Errorf("failed to write envrc file: %w", err)
10831087
}
10841088

0 commit comments

Comments
 (0)