Skip to content

Commit

Permalink
GH-129 - Allow . (dot) in key name
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Bongiorno committed Sep 15, 2021
1 parent fa7e3b1 commit 94f255f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 21 deletions.
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 94f255f

Please sign in to comment.