Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add repo key validator #53

Merged
merged 4 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 1.22.0 (Mar 11, 2024)

IMPROVEMENTS:

* Add `RepoKey` validation

PR: [#53](https://github.com/jfrog/terraform-provider-shared/pull/53)

## 1.21.3 (Jan 3, 2024)

IMPROVEMENTS:
Expand Down
5 changes: 4 additions & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import (
"fmt"
"net/http"
"net/url"
"os"
"regexp"
"slices"
"strings"

"github.com/go-resty/resty/v2"
Expand Down Expand Up @@ -34,7 +36,8 @@ func Build(URL, productId string) (*resty.Client, error) {
return nil
}

if response.StatusCode() >= http.StatusBadRequest {
tfLogLevel := strings.ToLower(os.Getenv("TF_LOG"))
if response.StatusCode() >= http.StatusBadRequest && slices.Contains([]string{"debug", "trace"}, tfLogLevel) {
return fmt.Errorf("\n%d %s %s\n%s", response.StatusCode(), response.Request.Method, response.Request.URL, string(response.Body()[:]))
}
return nil
Expand Down
4 changes: 4 additions & 0 deletions validator/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ var CommaSeperatedList = validation.ToDiagFunc(
validation.StringMatch(regexp.MustCompile(`.+(?:,.+)*`), "must be comma separated string"),
)

var RepoKey = validation.ToDiagFunc(
validation.StringDoesNotContainAny(" !@#$%^&*()+={}[]:;<>,/?~`|\\"),
)

var ProjectKey = validation.ToDiagFunc(
validation.StringMatch(regexp.MustCompile(`^[a-z][a-z0-9\-]{1,31}$`), "project_key must be 2 - 32 lowercase alphanumeric and hyphen characters"),
)
Expand Down
Loading