Skip to content

Commit ecb74bb

Browse files
committed
Improve repositores code
Signed-off-by: Michael Sverdlov <michaelsv@jfrog.com>
1 parent f280aa5 commit ecb74bb

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

artifactory/commands/buildtoollogin/buildtoollogin_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,14 @@ func TestBuildToolLoginCommand_Pipenv(t *testing.T) {
156156
}
157157

158158
func testBuildToolLoginCommandPip(t *testing.T, buildTool project.ProjectType) {
159-
// Retrieve the home directory and construct the pip.conf file path.
160-
homeDir, err := os.UserHomeDir()
161-
assert.NoError(t, err)
159+
162160
var pipConfFilePath string
163161
if coreutils.IsWindows() {
164-
pipConfFilePath = filepath.Join(homeDir, "pip", "pip.ini")
162+
pipConfFilePath = filepath.Join(os.Getenv("APPDATA"), "pip", "pip.ini")
165163
} else {
164+
// Retrieve the home directory and construct the pip.conf file path.
165+
homeDir, err := os.UserHomeDir()
166+
assert.NoError(t, err)
166167
pipConfFilePath = filepath.Join(homeDir, ".config", "pip", "pip.conf")
167168
}
168169

artifactory/commands/utils/npmcmdutils.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,15 @@ func GetNpmRepositoryUrl(repositoryName, artifactoryUrl string) string {
103103

104104
// GetNpmAuthKeyValue generates the correct authentication key and value for npm or Yarn, based on the repo URL.
105105
func GetNpmAuthKeyValue(serverDetails *config.ServerDetails, repoUrl string) (key, value string) {
106-
keySuffix := ""
107-
if serverDetails.GetAccessToken() != "" {
106+
var keySuffix string
107+
switch {
108+
case serverDetails.GetAccessToken() != "":
108109
keySuffix = NpmConfigAuthTokenKey
109110
value = serverDetails.GetAccessToken()
110-
} else if serverDetails.GetUser() != "" && serverDetails.GetPassword() != "" {
111+
case serverDetails.GetUser() != "" && serverDetails.GetPassword() != "":
111112
keySuffix = NpmConfigAuthKey
112113
value = basicAuthBase64Encode(serverDetails.GetUser(), serverDetails.GetPassword())
113-
} else {
114+
default:
114115
return "", ""
115116
}
116117

0 commit comments

Comments
 (0)