Skip to content

Commit

Permalink
Merge pull request #130 from jfrog/GH-129-allow-dots-and-dashes-in-re…
Browse files Browse the repository at this point in the history
…po-name

Gh 129 allow dots and dashes in repo name
  • Loading branch information
chb0github authored Sep 15, 2021
2 parents c9fc095 + 94f255f commit cbabc8c
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 24 deletions.
4 changes: 2 additions & 2 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ attach:
dlv --listen=:2345 --headless=true --api-version=2 --accept-multiclient attach $$(pgrep terraform-provider-artifactory)

acceptance: fmtcheck
TF_ACC=1
export TF_ACC=1
test -n ARTIFACTORY_USERNAME && test -n ARTIFACTORY_PASSWORD && test -n ARTIFACTORY_URL \
&& go test -v -parallel 1 ./pkg/... timeout 120m
&& go test -v -parallel 20 ./pkg/...


fmt:
Expand Down
5 changes: 4 additions & 1 deletion pkg/artifactory/resource_artifactory_local_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,10 @@ func resourceLocalRepositoryDelete(d *schema.ResourceData, m interface{}) error
}

func resourceLocalRepositoryExists(d *schema.ResourceData, m interface{}) (bool, error) {
_, err := m.(*resty.Client).R().Head(repositoriesEndpoint + d.Id())
newClient := m.(*resty.Client)
_, err := newClient.AddRetryCondition(func(response *resty.Response, err error) bool {
return response.StatusCode() == 400
}).R().Head(repositoriesEndpoint + d.Id())
// artifactory returns 400 instead of 404. but regardless, it's an error
return err == nil, err
}
29 changes: 29 additions & 0 deletions pkg/artifactory/resource_artifactory_remote_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,36 @@ import (

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)
func TestAccLocalAllowDotsAndDashesInKeyGH129(t *testing.T) {
_, fqrn, name := mkNames("terraform-local-test-repo-basic", "artifactory_remote_repository")

key := fmt.Sprintf("debian-remote.teleport%d",randomInt())
localRepositoryBasic := fmt.Sprintf(`
resource "artifactory_remote_repository" "%s" {
key = "%s"
package_type = "debian"
repo_layout_ref = "simple-default"
url = "https://deb.releases.teleport.dev/"
notes = "managed by terraform"
property_sets = ["artifactory"]
includes_pattern = "**/*"
content_synchronisation {
enabled = false
}
}
`,name, key )
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
CheckDestroy: testAccCheckRepositoryDestroy(fqrn),
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: localRepositoryBasic,
Check: resource.TestCheckResourceAttr(fqrn, "key", key),
},
},
})
}
func TestKeyHasSpecialCharsFails(t *testing.T) {
const failKey = `
resource "artifactory_remote_repository" "terraform-remote-test-repo-basic" {
Expand Down
20 changes: 0 additions & 20 deletions pkg/artifactory/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,27 +160,7 @@ func mkLens(d *schema.ResourceData) func(key string, value interface{}) []error
}
}

// HashStrings hashcode was moved to internal in terraform-plugin-sdk, and schema does not expose a wrapper of hashcode.Strings
func HashStrings(strings []string) string {
var buf bytes.Buffer

for _, s := range strings {
buf.WriteString(fmt.Sprintf("%s-", s))
}

return fmt.Sprintf("%d", schema.HashString(buf.String()))
}
func cascadingErr(hasErr *bool) func(error) {
if hasErr == nil {
panic("hasError cannot be nil")
}
return func(err error) {
if err != nil {
fmt.Println(err)
*hasErr = true
}
}
}

func sendConfigurationPatch(content []byte, m interface{}) error {

Expand Down
2 changes: 1 addition & 1 deletion pkg/artifactory/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ func validateIsEmail(address interface{}, _ string) ([]string, []error) {

var repoKeyValidator = validation.All(
validation.StringDoesNotMatch(regexp.MustCompile("^[0-9].*"), "repo key cannot start with a number"),
validation.StringDoesNotContainAny(" !@#$%^&*()_+={}[]:;<>,./?~`|\\"),
validation.StringDoesNotContainAny(" !@#$%^&*()_+={}[]:;<>,/?~`|\\"),
)

func fileExist(value interface{}, _ string) ([]string, []error) {
Expand Down

0 comments on commit cbabc8c

Please sign in to comment.