Skip to content

Commit

Permalink
fix: add validation to xray url
Browse files Browse the repository at this point in the history
  • Loading branch information
josh-barker-coles committed Dec 1, 2020
1 parent 2bb2b6d commit ec3b1ca
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions pkg/artifactory/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"net/http"
url "net/url"

artifactoryold "github.com/atlassian/go-artifactory/v2/artifactory"
"github.com/atlassian/go-artifactory/v2/artifactory/transport"
Expand Down Expand Up @@ -200,11 +201,20 @@ func createXrayClient(d *schema.ResourceData) (*xray.XrayServicesManager, error)
apiKey := d.Get("api_key").(string)
accessToken := d.Get("access_token").(string)

url := d.Get("xray_url").(string)
if url[len(url)-1] != '/' {
url += "/"
xrayURL := d.Get("xray_url").(string)
if xrayURL == "" {
return nil, fmt.Errorf("xray_url must have a value")
}
details.SetUrl(url)

_, err := url.Parse(xrayURL)
if err != nil {
return nil, err
}

if xrayURL[len(xrayURL)-1] != '/' {
xrayURL += "/"
}
details.SetUrl(xrayURL)

if username != "" && password != "" {
details.SetUser(username)
Expand Down

0 comments on commit ec3b1ca

Please sign in to comment.