Skip to content

Commit 8a8723e

Browse files
authored
Merge pull request #48 from clarafeb1/patch-1
capability_validate
2 parents 6360236 + 898c2b5 commit 8a8723e

File tree

7 files changed

+18
-13
lines changed

7 files changed

+18
-13
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ jobs:
3333
uses: golangci/golangci-lint-action@v2
3434

3535
- name: fmt
36-
run: gofmt -l . && test -z $(gofmt -l .)
36+
run: go fmt ./... && git diff && test -z "$(git status --porcelain)"

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 1.7.1 (March 30, 2023)
2+
3+
FEATURES:
4+
5+
* **New Capability Validation**: Adding `-` as a valid character in capability names
6+
17
## 1.7.0 (February 8, 2022)
28

39
FEATURES:

internal/splunkconfig/config/appid.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ type AppID string
2424

2525
// validate returns an error if AppID is invalid. As per Splunk's app.conf .spec:
2626
// * id must adhere to these cross-platform folder name restrictions:
27-
// * must contain only letters, numbers, "." (dot), and "_" (underscore)
28-
// characters.
27+
// - must contain only letters, numbers, "." (dot), and "_" (underscore)
28+
// characters.
29+
//
2930
// "-" (dash) characters are also permitted as many official Splunk apps have them in their IDs
3031
func (appID AppID) validate() error {
3132
validRegex := regexp.MustCompile("^[A-Za-z0-9_.-]+$")

internal/splunkconfig/config/capabilityname.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ type CapabilityName string
2424

2525
// validate returns an error if the CapabilityName is invalid. Splunk's documentation defines valid capability names:
2626
//
27-
// Only alphanumeric characters and "_" (underscore) are allowed in capability names.
27+
// Only alphanumeric characters, "_" (underscore), and "-" (dash) are allowed in capability names.
2828
func (capabilityName CapabilityName) validate() error {
29-
validRegex := regexp.MustCompile("^[a-zA-Z0-9_]+$")
29+
validRegex := regexp.MustCompile("^[a-zA-Z0-9_-]+$")
3030

3131
if !validRegex.MatchString(string(capabilityName)) {
32-
return fmt.Errorf("invalid CapabilityName %s, may only consist of alphanumeric characters and underscores", capabilityName)
32+
return fmt.Errorf("invalid CapabilityName %s, may only consist of alphanumeric characters, underscores, and dashes", capabilityName)
3333
}
3434

3535
return nil

internal/splunkconfig/config/capabilityname_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@ func TestCapability_validate(t *testing.T) {
2020
tests := validatorTestCases{
2121
// empty name is invalid
2222
{CapabilityName(""), true},
23-
// symbols (including dashes) are invalid
24-
{CapabilityName("-"), true},
25-
// valid name contains lowercase, uppercase, number, underscore
26-
{CapabilityName("aA_1"), false},
23+
// valid name contains lowercase, uppercase, number, underscore, dash
24+
{CapabilityName("aA_1-"), false},
2725
}
2826

2927
tests.test(t)

internal/splunkconfig/config/collection.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ type Collection struct {
2626

2727
// validate returns an error if Collection is invalid. It is invalid if it
2828
// has invalid:
29-
// * Name
30-
// * Fields
29+
// - Name
30+
// - Fields
3131
func (collection Collection) validate() error {
3232
if len(collection.Name) == 0 {
3333
return fmt.Errorf("Collection name can not be empty")

internal/splunkconfig/config/collectionfields.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type CollectionFields map[string]CollectionFieldType
1919

2020
// validate returns an error if CollectionFields is invalid. It is invalid if
2121
// any member has invalid:
22-
// * CollectionFieldType
22+
// - CollectionFieldType
2323
func (collectionFields CollectionFields) validate() error {
2424
for _, fieldType := range collectionFields {
2525
if err := fieldType.validate(); err != nil {

0 commit comments

Comments
 (0)