/
data_package_deny_policy.go
73 lines (67 loc) · 2.16 KB
/
data_package_deny_policy.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
69
70
71
72
73
package cloudsmith
import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)
func dataSourcePackageDenyPolicyRead(d *schema.ResourceData, m interface{}) error {
pc := m.(*providerConfig)
slugPerm := requiredString(d, "slug_perm")
namespace := requiredString(d, "namespace")
req := pc.APIClient.OrgsApi.OrgsDenyPolicyRead(pc.Auth, namespace, slugPerm)
packageDenyPolicy, _, err := pc.APIClient.OrgsApi.OrgsDenyPolicyReadExecute(req)
if err != nil {
return err
}
d.Set("name", packageDenyPolicy.GetName())
d.Set("description", packageDenyPolicy.GetDescription())
d.Set("package_query", packageDenyPolicy.GetPackageQueryString())
d.Set("enabled", packageDenyPolicy.GetEnabled())
d.SetId(packageDenyPolicy.GetSlugPerm())
return nil
}
//nolint:funlen
func dataSourcePackageDenyPolicy() *schema.Resource {
return &schema.Resource{
Read: dataSourcePackageDenyPolicyRead,
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Description: "A descriptive name for the package deny policy.",
Optional: true,
ValidateFunc: validation.StringIsNotEmpty,
},
"description": {
Type: schema.TypeString,
Description: "Description of the package deny policy.",
Optional: true,
ValidateFunc: validation.StringIsNotEmpty,
},
"package_query": {
Type: schema.TypeString,
Description: "The query to match the packages to be blocked.",
Optional: true,
ValidateFunc: validation.StringIsNotEmpty,
},
"enabled": {
Type: schema.TypeBool,
Description: "Is the package deny policy enabled?.",
Optional: true,
Default: true,
},
"namespace": {
Type: schema.TypeString,
Description: "Namespace to which this package deny policy belongs.",
Required: true,
ForceNew: true,
ValidateFunc: validation.StringIsNotEmpty,
},
"slug_perm": {
Type: schema.TypeString,
Description: "Identifier of the package deny policy.",
Required: true,
ForceNew: true,
ValidateFunc: validation.StringIsNotEmpty,
},
},
}
}