Skip to content

Commit a27da7a

Browse files
author
Shreyas Sreenivas
authored
Merge pull request #101 from vmware/vasundharas/schema-image-policy
Schema for Image Registry Policy
2 parents 9d9d2df + 8efd905 commit a27da7a

28 files changed

+1487
-179
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
Copyright © 2022 VMware, Inc. All Rights Reserved.
3+
SPDX-License-Identifier: MPL-2.0
4+
Code generated by go-swagger; DO NOT EDIT.
5+
*/
6+
7+
package policyrecipeimagemodel
8+
9+
import (
10+
"github.com/go-openapi/swag"
11+
12+
policyrecipeimagecommonmodel "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/policy/recipe/image/common"
13+
)
14+
15+
// VmwareTanzuManageV1alpha1CommonPolicySpecImageV1AllowedNameTag is model for allowed-name-tag recipe version v1
16+
//
17+
// The input schema for image policy allowed-name-tag recipe.
18+
//
19+
// swagger:model VmwareTanzuManageV1alpha1CommonPolicySpecImageV1AllowedNameTag
20+
type VmwareTanzuManageV1alpha1CommonPolicySpecImageV1AllowedNameTag struct {
21+
22+
// Audit (dry-run)
23+
// Creates this policy for dry-run. Violations will be logged but not denied. Defaults to false (deny).
24+
Audit *bool `json:"audit,omitempty"`
25+
26+
// This specifies a list of rules that defines allowed image patterns.
27+
// Required: true
28+
// Min Items: 1
29+
Rules []*VmwareTanzuManageV1alpha1CommonPolicySpecImageV1AllowedNameTagRules `json:"rules"`
30+
}
31+
32+
// MarshalBinary interface implementation
33+
func (m *VmwareTanzuManageV1alpha1CommonPolicySpecImageV1AllowedNameTag) MarshalBinary() ([]byte, error) {
34+
if m == nil {
35+
return nil, nil
36+
}
37+
38+
return swag.WriteJSON(m)
39+
}
40+
41+
// UnmarshalBinary interface implementation
42+
func (m *VmwareTanzuManageV1alpha1CommonPolicySpecImageV1AllowedNameTag) UnmarshalBinary(b []byte) error {
43+
var res VmwareTanzuManageV1alpha1CommonPolicySpecImageV1AllowedNameTag
44+
if err := swag.ReadJSON(b, &res); err != nil {
45+
return err
46+
}
47+
48+
*m = res
49+
50+
return nil
51+
}
52+
53+
// VmwareTanzuManageV1alpha1CommonPolicySpecImageV1AllowedNameTagRules Rules.
54+
//
55+
// swagger:model VmwareTanzuManageV1alpha1CommonPolicySpecImageV1AllowedNameTagRules
56+
type VmwareTanzuManageV1alpha1CommonPolicySpecImageV1AllowedNameTagRules struct {
57+
58+
// Allowed image names, wildcards are supported(for example: fooservice/*). Empty field is equivalent to *.
59+
ImageName string `json:"imageName,omitempty"`
60+
61+
// Tag
62+
Tag *policyrecipeimagecommonmodel.VmwareTanzuManageV1alpha1CommonPolicySpecImageV1RulesTag `json:"tag,omitempty"`
63+
}
64+
65+
// MarshalBinary interface implementation
66+
func (m *VmwareTanzuManageV1alpha1CommonPolicySpecImageV1AllowedNameTagRules) MarshalBinary() ([]byte, error) {
67+
if m == nil {
68+
return nil, nil
69+
}
70+
71+
return swag.WriteJSON(m)
72+
}
73+
74+
// UnmarshalBinary interface implementation
75+
func (m *VmwareTanzuManageV1alpha1CommonPolicySpecImageV1AllowedNameTagRules) UnmarshalBinary(b []byte) error {
76+
var res VmwareTanzuManageV1alpha1CommonPolicySpecImageV1AllowedNameTagRules
77+
if err := swag.ReadJSON(b, &res); err != nil {
78+
return err
79+
}
80+
81+
*m = res
82+
83+
return nil
84+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
Copyright © 2022 VMware, Inc. All Rights Reserved.
3+
SPDX-License-Identifier: MPL-2.0
4+
Code generated by go-swagger; DO NOT EDIT.
5+
*/
6+
7+
package policyrecipeimagemodel
8+
9+
import "github.com/go-openapi/swag"
10+
11+
// VmwareTanzuManageV1alpha1CommonPolicySpecImageV1CommonRecipe is model for block-latest-tag and require-digest recipes version v1
12+
//
13+
// The input schema for image policy block-latest-tag and require-digest recipes.
14+
//
15+
// swagger:model VmwareTanzuManageV1alpha1CommonPolicySpecImageV1CommonRecipe
16+
type VmwareTanzuManageV1alpha1CommonPolicySpecImageV1CommonRecipe struct {
17+
18+
// Audit (dry-run)
19+
// Creates this policy for dry-run. Violations will be logged but not denied. Defaults to false (deny).
20+
Audit *bool `json:"audit,omitempty"`
21+
}
22+
23+
// MarshalBinary interface implementation
24+
func (m *VmwareTanzuManageV1alpha1CommonPolicySpecImageV1CommonRecipe) MarshalBinary() ([]byte, error) {
25+
if m == nil {
26+
return nil, nil
27+
}
28+
29+
return swag.WriteJSON(m)
30+
}
31+
32+
// UnmarshalBinary interface implementation
33+
func (m *VmwareTanzuManageV1alpha1CommonPolicySpecImageV1CommonRecipe) UnmarshalBinary(b []byte) error {
34+
var res VmwareTanzuManageV1alpha1CommonPolicySpecImageV1CommonRecipe
35+
if err := swag.ReadJSON(b, &res); err != nil {
36+
return err
37+
}
38+
39+
*m = res
40+
41+
return nil
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
Copyright © 2022 VMware, Inc. All Rights Reserved.
3+
SPDX-License-Identifier: MPL-2.0
4+
Code generated by go-swagger; DO NOT EDIT.
5+
*/
6+
7+
package policyrecipeimagecommonmodel
8+
9+
import "github.com/go-openapi/swag"
10+
11+
// VmwareTanzuManageV1alpha1CommonPolicySpecImageV1RulesTag Tag
12+
//
13+
// Allowed image tag, wildcards are supported (for example: v1.*). No validation is performed on tag if the field is empty.
14+
//
15+
// swagger:model VmwareTanzuManageV1alpha1CommonPolicySpecImageV1RulesTag
16+
type VmwareTanzuManageV1alpha1CommonPolicySpecImageV1RulesTag struct {
17+
18+
// The negate flag used to exclude certain tag patterns.
19+
Negate *bool `json:"negate,omitempty"`
20+
21+
// The value (support wildcard) is used to validate against the tag of the image.
22+
Value string `json:"value,omitempty"`
23+
}
24+
25+
// MarshalBinary interface implementation
26+
func (m *VmwareTanzuManageV1alpha1CommonPolicySpecImageV1RulesTag) MarshalBinary() ([]byte, error) {
27+
if m == nil {
28+
return nil, nil
29+
}
30+
31+
return swag.WriteJSON(m)
32+
}
33+
34+
// UnmarshalBinary interface implementation
35+
func (m *VmwareTanzuManageV1alpha1CommonPolicySpecImageV1RulesTag) UnmarshalBinary(b []byte) error {
36+
var res VmwareTanzuManageV1alpha1CommonPolicySpecImageV1RulesTag
37+
if err := swag.ReadJSON(b, &res); err != nil {
38+
return err
39+
}
40+
41+
*m = res
42+
43+
return nil
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
Copyright © 2022 VMware, Inc. All Rights Reserved.
3+
SPDX-License-Identifier: MPL-2.0
4+
Code generated by go-swagger; DO NOT EDIT.
5+
*/
6+
7+
package policyrecipeimagemodel
8+
9+
import (
10+
"github.com/go-openapi/swag"
11+
12+
policyrecipeimagecommonmodel "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/policy/recipe/image/common"
13+
)
14+
15+
// VmwareTanzuManageV1alpha1CommonPolicySpecImageV1Custom is model for custom recipe version v1
16+
//
17+
// The input schema for image policy custom recipe.
18+
//
19+
// swagger:model VmwareTanzuManageV1alpha1CommonPolicySpecImageV1Custom
20+
type VmwareTanzuManageV1alpha1CommonPolicySpecImageV1Custom struct {
21+
22+
// Audit (dry-run)
23+
// Creates this policy for dry-run. Violations will be logged but not denied. Defaults to false (deny).
24+
Audit *bool `json:"audit,omitempty"`
25+
26+
// This specifies a list of rules that defines allowed image patterns.
27+
// Required: true
28+
// Min Items: 1
29+
Rules []*VmwareTanzuManageV1alpha1CommonPolicySpecImageV1CustomRules `json:"rules"`
30+
}
31+
32+
// MarshalBinary interface implementation
33+
func (m *VmwareTanzuManageV1alpha1CommonPolicySpecImageV1Custom) MarshalBinary() ([]byte, error) {
34+
if m == nil {
35+
return nil, nil
36+
}
37+
38+
return swag.WriteJSON(m)
39+
}
40+
41+
// UnmarshalBinary interface implementation
42+
func (m *VmwareTanzuManageV1alpha1CommonPolicySpecImageV1Custom) UnmarshalBinary(b []byte) error {
43+
var res VmwareTanzuManageV1alpha1CommonPolicySpecImageV1Custom
44+
if err := swag.ReadJSON(b, &res); err != nil {
45+
return err
46+
}
47+
48+
*m = res
49+
50+
return nil
51+
}
52+
53+
// VmwareTanzuManageV1alpha1CommonPolicySpecImageV1CustomRules Rules.
54+
//
55+
// swagger:model VmwareTanzuManageV1alpha1CommonPolicySpecImageV1CustomRules
56+
type VmwareTanzuManageV1alpha1CommonPolicySpecImageV1CustomRules struct {
57+
58+
// Allowed image hostnames, wildcards are supported(for example: *.mycompany.com). Empty field is equivalent to *.
59+
Hostname string `json:"hostname,omitempty"`
60+
61+
// Allowed image names, wildcards are supported(for example: fooservice/*). Empty field is equivalent to *.
62+
ImageName string `json:"imageName,omitempty"`
63+
64+
// Allowed port(if presented) of the image hostname, must associate with valid hostname. Wildcards are supported.
65+
Port string `json:"port,omitempty"`
66+
67+
// The flag used to enforce digest to appear in container images.
68+
RequireDigest *bool `json:"requireDigest,omitempty"`
69+
70+
// Tag
71+
Tag *policyrecipeimagecommonmodel.VmwareTanzuManageV1alpha1CommonPolicySpecImageV1RulesTag `json:"tag,omitempty"`
72+
}
73+
74+
// MarshalBinary interface implementation
75+
func (m *VmwareTanzuManageV1alpha1CommonPolicySpecImageV1CustomRules) MarshalBinary() ([]byte, error) {
76+
if m == nil {
77+
return nil, nil
78+
}
79+
80+
return swag.WriteJSON(m)
81+
}
82+
83+
// UnmarshalBinary interface implementation
84+
func (m *VmwareTanzuManageV1alpha1CommonPolicySpecImageV1CustomRules) UnmarshalBinary(b []byte) error {
85+
var res VmwareTanzuManageV1alpha1CommonPolicySpecImageV1CustomRules
86+
if err := swag.ReadJSON(b, &res); err != nil {
87+
return err
88+
}
89+
90+
*m = res
91+
92+
return nil
93+
}

internal/provider/provider.go

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import (
1818
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/namespace"
1919
custompolicy "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/policy/kind/custom"
2020
custompolicyresource "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/policy/kind/custom/resource"
21+
imagepolicy "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/policy/kind/image"
22+
imagepolicyresource "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/policy/kind/image/resource"
2123
securitypolicy "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/policy/kind/security"
2224
securitypolicyresource "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/policy/kind/security/resource"
2325
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/workspace"
@@ -36,6 +38,7 @@ func Provider() *schema.Provider {
3638
iampolicy.ResourceName: iampolicy.ResourceIAMPolicy(),
3739
custompolicy.ResourceName: custompolicyresource.ResourceCustomPolicy(),
3840
securitypolicy.ResourceName: securitypolicyresource.ResourceSecurityPolicy(),
41+
imagepolicy.ResourceName: imagepolicyresource.ResourceImageRegistryPolicy(),
3942
credential.ResourceName: credential.ResourceCredential(),
4043
integration.ResourceName: integration.ResourceIntegration(),
4144
},

internal/resources/policy/constants.go

-12
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,9 @@ const (
1111
KeyKey = "key"
1212
OperatorKey = "operator"
1313
ValuesKey = "values"
14-
ScopeKey = "scope"
15-
clusterKey = "cluster"
16-
clusterGroupKey = "cluster_group"
17-
organizationKey = "organization"
1814
SpecKey = "spec"
1915
NameKey = "name"
2016
InputKey = "input"
2117
RecipeVersionDefaultValue = "v1"
2218
UnknownRecipe = ""
2319
)
24-
25-
// Allowed scopes.
26-
const (
27-
UnknownScope Scope = iota
28-
ClusterScope
29-
ClusterGroupScope
30-
OrganizationScope
31-
)

internal/resources/policy/kind/custom/resource/resource_custom_policy.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/policy"
1414
policykindcustom "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/policy/kind/custom"
1515
policyoperations "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/policy/operations"
16+
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/policy/scope"
1617
)
1718

1819
func ResourceCustomPolicy() *schema.Resource {
@@ -23,7 +24,7 @@ func ResourceCustomPolicy() *schema.Resource {
2324
DeleteContext: schema.DeleteContextFunc(policyoperations.ResourceOperation(policyoperations.WithResourceName(policykindcustom.ResourceName), policyoperations.WithOperationType(policyoperations.Delete))),
2425
Schema: customPolicySchema,
2526
CustomizeDiff: customdiff.All(
26-
policy.ValidateScope,
27+
scope.ValidateScope,
2728
policykindcustom.ValidateInput,
2829
policy.ValidateSpecLabelSelectorRequirement,
2930
),
@@ -37,7 +38,7 @@ var customPolicySchema = map[string]*schema.Schema{
3738
Required: true,
3839
ForceNew: true,
3940
},
40-
policy.ScopeKey: policy.ScopeSchema,
41-
common.MetaKey: common.Meta,
42-
policy.SpecKey: policykindcustom.SpecSchema,
41+
scope.ScopeKey: scope.ScopeSchema,
42+
common.MetaKey: common.Meta,
43+
policy.SpecKey: policykindcustom.SpecSchema,
4344
}

0 commit comments

Comments
 (0)