From 2ca8b273b36cdd637503580740f54be91e60f5b8 Mon Sep 17 00:00:00 2001 From: Josh Barker Date: Tue, 1 Dec 2020 17:37:17 +1100 Subject: [PATCH] fix: update error message when xray is not configured in provider --- pkg/artifactory/provider.go | 2 +- pkg/artifactory/resource_artifactory_watch.go | 20 ++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/pkg/artifactory/provider.go b/pkg/artifactory/provider.go index de14e2aca..fa5e9a264 100644 --- a/pkg/artifactory/provider.go +++ b/pkg/artifactory/provider.go @@ -4,7 +4,7 @@ import ( "context" "fmt" "net/http" - url "net/url" + "net/url" artifactoryold "github.com/atlassian/go-artifactory/v2/artifactory" "github.com/atlassian/go-artifactory/v2/artifactory/transport" diff --git a/pkg/artifactory/resource_artifactory_watch.go b/pkg/artifactory/resource_artifactory_watch.go index afaf835a3..3c510f6fd 100644 --- a/pkg/artifactory/resource_artifactory_watch.go +++ b/pkg/artifactory/resource_artifactory_watch.go @@ -213,7 +213,7 @@ func resourceWatchCreate(d *schema.ResourceData, m interface{}) error { client := m.(*ArtClient).XrayClient if client == nil { - return fmt.Errorf("you must specify the xray_url in the provider to manage a watch") + return fmt.Errorf("xray client is nil. please configure xray settings in provider") } params, err := unpackWatch(d, m) @@ -235,7 +235,7 @@ func resourceWatchRead(d *schema.ResourceData, m interface{}) error { client := m.(*ArtClient).XrayClient if client == nil { - return fmt.Errorf("you must specify the xray_url in the provider to manage a watch") + return fmt.Errorf("xray client is nil. please configure xray settings in provider") } watch, resp, err := client.GetWatch(d.Id()) @@ -254,7 +254,7 @@ func resourceWatchUpdate(d *schema.ResourceData, m interface{}) error { client := m.(*ArtClient).XrayClient if client == nil { - return fmt.Errorf("you must specify the xray_url in the provider to manage a watch") + return fmt.Errorf("xray client is nil. please configure xray settings in provider") } params, err := unpackWatch(d, m) @@ -275,7 +275,7 @@ func resourceWatchDelete(d *schema.ResourceData, m interface{}) error { client := m.(*ArtClient).XrayClient if client == nil { - return fmt.Errorf("you must specify the xray_url in the provider to manage a watch") + return fmt.Errorf("xray client is nil. please configure xray settings in provider") } name := d.Get("name").(string) @@ -292,11 +292,10 @@ func resourceWatchExists(d *schema.ResourceData, m interface{}) (bool, error) { client := m.(*ArtClient).XrayClient if client == nil { - return false, fmt.Errorf("you must specify the xray_url in the provider to manage a watch") + return false, fmt.Errorf("xray client is nil. please configure xray settings in provider") } - watchName := d.Id() - _, resp, err := client.GetWatch(watchName) + _, resp, err := client.GetWatch(d.Id()) if resp.StatusCode == http.StatusNotFound { return false, nil @@ -375,8 +374,10 @@ func unpackRepositoryPaths(repositoryPaths interface{}, params *xrayutils.WatchP repositoryPathsRaw := repositoryPaths.(*schema.Set).List() if len(repositoryPathsRaw) == 1 { repositoryPaths := repositoryPathsRaw[0].(map[string]interface{}) + includePatterns := castToStringArr(repositoryPaths["include_patterns"].(*schema.Set).List()) sort.Strings(includePatterns) + excludePatterns := castToStringArr(repositoryPaths["exclude_patterns"].(*schema.Set).List()) sort.Strings(excludePatterns) @@ -391,13 +392,16 @@ func unpackAllRepositories(allRepositoriesRaw []interface{}, params *xrayutils.W if allRepositoriesRaw[0] != nil { allRepositories := allRepositoriesRaw[0].(map[string]interface{}) + names := castToStringArr(allRepositories["names"].(*schema.Set).List()) sort.Strings(names) packageTypes := castToStringArr(allRepositories["package_types"].(*schema.Set).List()) sort.Strings(packageTypes) + paths := castToStringArr(allRepositories["paths"].(*schema.Set).List()) sort.Strings(paths) + mimeTypes := castToStringArr(allRepositories["mime_types"].(*schema.Set).List()) sort.Strings(mimeTypes) @@ -458,8 +462,10 @@ func unpackRepository(repositoriesRaw []interface{}, artClient *artifactoryold.A packageTypes := castToStringArr(repository["package_types"].(*schema.Set).List()) sort.Strings(packageTypes) + paths := castToStringArr(repository["paths"].(*schema.Set).List()) sort.Strings(paths) + mimeTypes := castToStringArr(repository["mime_types"].(*schema.Set).List()) sort.Strings(mimeTypes)