Skip to content

Commit

Permalink
fix env var + add test
Browse files Browse the repository at this point in the history
  • Loading branch information
hadarshjfrog committed Sep 22, 2024
1 parent c1ab812 commit 80e61ff
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
10 changes: 6 additions & 4 deletions jas/analyzermanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const (
jfPasswordEnvVariable = "JF_PASS"
jfTokenEnvVariable = "JF_TOKEN"
jfPlatformUrlEnvVariable = "JF_PLATFORM_URL"
jfPlatformXrayUrlEnvVariable = "JF_PLATFORM_XRAY_URL"
logDirEnvVariable = "AM_LOG_DIRECTORY"
notEntitledExitCode = 31
unsupportedCommandExitCode = 13
Expand Down Expand Up @@ -142,10 +143,11 @@ func isCI() bool {

func GetAnalyzerManagerEnvVariables(serverDetails *config.ServerDetails) (envVars map[string]string, err error) {
envVars = map[string]string{
jfUserEnvVariable: serverDetails.User,
jfPasswordEnvVariable: serverDetails.Password,
jfPlatformUrlEnvVariable: serverDetails.Url,
jfTokenEnvVariable: serverDetails.AccessToken,
jfUserEnvVariable: serverDetails.User,
jfPasswordEnvVariable: serverDetails.Password,
jfPlatformUrlEnvVariable: serverDetails.Url,
jfPlatformXrayUrlEnvVariable: serverDetails.XrayUrl,
jfTokenEnvVariable: serverDetails.AccessToken,
}
if !isCI() {
analyzerManagerLogFolder, err := coreutils.CreateDirInJfrogHome(filepath.Join(coreutils.JfrogLogsDirName, analyzerManagerLogDirName))
Expand Down
1 change: 1 addition & 0 deletions jas/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func CreateJasScanner(scanner *JasScanner, jfrogAppsConfig *jfrogappsconfig.JFro

func getJasEnvVars(serverDetails *config.ServerDetails, vars map[string]string) (map[string]string, error) {
amBasicVars, err := GetAnalyzerManagerEnvVariables(serverDetails)
log.Debug("Adding the following environment variables to the analyzer manager", amBasicVars)
if err != nil {
return nil, err
}
Expand Down
34 changes: 34 additions & 0 deletions jas/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,40 @@ func TestGetAnalyzerManagerEnvVariables(t *testing.T) {
jfTokenEnvVariable: "token",
},
},
{
name: "Valid server details xray only",
serverDetails: &config.ServerDetails{
Url: "",
XrayUrl: "url/xray",
User: "user",
Password: "password",
AccessToken: "token",
},
expectedOutput: map[string]string{
jfPlatformUrlEnvVariable: "",
jfPlatformXrayUrlEnvVariable: "url/xray",
jfUserEnvVariable: "user",
jfPasswordEnvVariable: "password",
jfTokenEnvVariable: "token",
},
},
{
name: "Valid server details both url and xray",
serverDetails: &config.ServerDetails{
Url: "url",
XrayUrl: "url/xray",
User: "user",
Password: "password",
AccessToken: "token",
},
expectedOutput: map[string]string{
jfPlatformUrlEnvVariable: "url",
jfPlatformXrayUrlEnvVariable: "url/xray",
jfUserEnvVariable: "user",
jfPasswordEnvVariable: "password",
jfTokenEnvVariable: "token",
},
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
Expand Down

0 comments on commit 80e61ff

Please sign in to comment.