Skip to content

Commit

Permalink
Fix provider crashes when url attribute is used
Browse files Browse the repository at this point in the history
Vs env var.
  • Loading branch information
alexhung committed Apr 15, 2024
1 parent 1efb2b4 commit d97fb47
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions pkg/platform/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,25 @@ func (p *PlatformProvider) Configure(ctx context.Context, req provider.Configure
return
}

if config.Url.ValueString() != "" {
url = config.Url.ValueString()
}

if url == "" {
resp.Diagnostics.AddError(
"Missing URL Configuration",
"While configuring the provider, the url was not found in the JFROG_URL environment variable or provider configuration block url attribute.",
)
return
}

platformClient, err := client.Build(url, productId)
if err != nil {
resp.Diagnostics.AddError(
"Error creating Resty client",
err.Error(),
)
return
}

oidcAccessToken, err := util.OIDCTokenExchange(ctx, platformClient, config.OIDCProviderName.ValueString())
Expand All @@ -75,6 +88,7 @@ func (p *PlatformProvider) Configure(ctx context.Context, req provider.Configure
"Failed OIDC ID token exchange",
err.Error(),
)
return
}

// use token from OIDC provider, which should take precedence over
Expand All @@ -101,18 +115,6 @@ func (p *PlatformProvider) Configure(ctx context.Context, req provider.Configure
myJFrogAPIToken = config.MyJFrogAPIToken.ValueString()
}

if config.Url.ValueString() != "" {
url = config.Url.ValueString()
}

if url == "" {
resp.Diagnostics.AddError(
"Missing URL Configuration",
"While configuring the provider, the url was not found in the JFROG_URL environment variable or provider configuration block url attribute.",
)
return
}

var myJFrogClient *resty.Client
if len(myJFrogAPIToken) > 0 {
c, err := client.Build("https://my.jfrog.com", productId)
Expand All @@ -121,6 +123,7 @@ func (p *PlatformProvider) Configure(ctx context.Context, req provider.Configure
"Error creating Resty client for MyJFrog",
err.Error(),
)
return
}

c, err = client.AddAuth(c, "", myJFrogAPIToken)
Expand All @@ -129,6 +132,7 @@ func (p *PlatformProvider) Configure(ctx context.Context, req provider.Configure
"Error adding Auth to Resty client for MyJFrog",
err.Error(),
)
return
}

myJFrogClient = c
Expand All @@ -140,6 +144,7 @@ func (p *PlatformProvider) Configure(ctx context.Context, req provider.Configure
"Error adding Auth to Resty client",
err.Error(),
)
return
}

if config.CheckLicense.IsNull() || config.CheckLicense.ValueBool() {
Expand Down

0 comments on commit d97fb47

Please sign in to comment.