-
Notifications
You must be signed in to change notification settings - Fork 100
/
resource_artifactory_webhook_build.go
68 lines (58 loc) · 2.04 KB
/
resource_artifactory_webhook_build.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package artifactory
import (
"fmt"
"log"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
type BuildWebhookCriteria struct {
BaseWebhookCriteria
AnyBuild bool `json:"anyBuild"`
SelectedBuilds []string `json:"selectedBuilds"`
}
var buildWebhookSchema = func(webhookType string) map[string]*schema.Schema {
return mergeSchema(baseWebhookBaseSchema(webhookType), map[string]*schema.Schema{
"criteria": {
Type: schema.TypeSet,
Required: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: mergeSchema(baseCriteriaSchema, map[string]*schema.Schema{
"any_build": {
Type: schema.TypeBool,
Required: true,
Description: "Trigger on any builds",
},
"selected_builds": {
Type: schema.TypeSet,
Required: true,
Elem: &schema.Schema{Type: schema.TypeString},
Description: "Trigger on this list of build IDs",
},
}),
},
Description: "Specifies where the webhook will be applied on which builds.",
},
})
}
var packBuildCriteria = func(artifactoryCriteria map[string]interface{}) map[string]interface{} {
return map[string]interface{}{
"any_build": artifactoryCriteria["anyBuild"].(bool),
"selected_builds": schema.NewSet(schema.HashString, artifactoryCriteria["selectedBuilds"].([]interface{})),
}
}
var unpackBuildCriteria = func(terraformCriteria map[string]interface{}, baseCriteria BaseWebhookCriteria) interface{} {
return BuildWebhookCriteria{
AnyBuild: terraformCriteria["any_build"].(bool),
SelectedBuilds: castToStringArr(terraformCriteria["selected_builds"].(*schema.Set).List()),
BaseWebhookCriteria: baseCriteria,
}
}
var buildCriteriaValidation = func(criteria map[string]interface{}) error {
log.Print("[DEBUG] buildCriteriaValidation")
anyBuild := criteria["any_build"].(bool)
selectedBuilds := criteria["selected_builds"].(*schema.Set).List()
if anyBuild == false && len(selectedBuilds) == 0 {
return fmt.Errorf("selected_builds cannot be empty when any_build is false")
}
return nil
}