Skip to content

Commit f660862

Browse files
committed
Get Artifactory token outside constructor
This will make it possible to avoid setting environment variables in most of the tests which is nice since setting environment variables cannot be done in parallel.
1 parent ceaa12d commit f660862

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

storage/artifactory.go

+1-8
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ import (
2424
"github.com/coder/code-marketplace/util"
2525
)
2626

27-
const ArtifactoryTokenEnvKey = "ARTIFACTORY_TOKEN"
28-
2927
type ArtifactoryError struct {
3028
Status int `json:"status"`
3129
Message string `json:"message"`
@@ -61,12 +59,7 @@ type Artifactory struct {
6159
uri string
6260
}
6361

64-
func NewArtifactoryStorage(ctx context.Context, uri, repo string, logger slog.Logger) (*Artifactory, error) {
65-
token := os.Getenv(ArtifactoryTokenEnvKey)
66-
if token == "" {
67-
return nil, xerrors.Errorf("the %s environment variable must be set", ArtifactoryTokenEnvKey)
68-
}
69-
62+
func NewArtifactoryStorage(ctx context.Context, uri, repo, token string, logger slog.Logger) (*Artifactory, error) {
7063
if !strings.HasSuffix(uri, "/") {
7164
uri = uri + "/"
7265
}

storage/storage.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ type Storage interface {
127127
WalkExtensions(ctx context.Context, fn func(manifest *VSIXManifest, versions []string) error) error
128128
}
129129

130+
const ArtifactoryTokenEnvKey = "ARTIFACTORY_TOKEN"
131+
130132
// NewStorage returns a storage instance based on the provided extension
131133
// directory or Artifactory URL. If neither or both are provided an error is
132134
// returned.
@@ -136,7 +138,11 @@ func NewStorage(ctx context.Context, options *Options) (Storage, error) {
136138
} else if options.Artifactory != "" && options.Repo == "" {
137139
return nil, xerrors.Errorf("must provide repository")
138140
} else if options.Artifactory != "" {
139-
return NewArtifactoryStorage(ctx, options.Artifactory, options.Repo, options.Logger)
141+
token := os.Getenv(ArtifactoryTokenEnvKey)
142+
if token == "" {
143+
return nil, xerrors.Errorf("the %s environment variable must be set", ArtifactoryTokenEnvKey)
144+
}
145+
return NewArtifactoryStorage(ctx, options.Artifactory, options.Repo, token, options.Logger)
140146
} else if options.ExtDir != "" {
141147
return NewLocalStorage(options.ExtDir, options.Logger)
142148
}

0 commit comments

Comments
 (0)