-
Notifications
You must be signed in to change notification settings - Fork 42
/
validations.go
31 lines (25 loc) · 916 Bytes
/
validations.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package jenkins
import (
"fmt"
"strings"
"github.com/hashicorp/go-cty/cty"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
)
func validateJobName(val interface{}, path cty.Path) diag.Diagnostics {
if strings.Contains(val.(string), "/") {
return diag.FromErr(fmt.Errorf("provided name includes path characters. Please use the 'folder' property if specifying a job within a subfolder"))
}
return diag.Diagnostics{}
}
func validateFolderName(val interface{}, path cty.Path) diag.Diagnostics {
return diag.Diagnostics{}
}
func validateCredentialScope(val interface{}, path cty.Path) diag.Diagnostics {
var supportedCredentialScopes = []string{"SYSTEM", "GLOBAL"}
for _, supported := range supportedCredentialScopes {
if val == supported {
return diag.Diagnostics{}
}
}
return diag.Errorf("Invalid scope: %s. Supported scopes are: %s", val, strings.Join(supportedCredentialScopes, ", "))
}