Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.

Commit 0f1a5c5

Browse files
committed
Add Application, Role, Group, RoleAssignment support
Signed-off-by: vaspahomov <vas2142553@gmail.com>
1 parent 3a2c932 commit 0f1a5c5

26 files changed

Lines changed: 3090 additions & 5 deletions

apis/azure.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
databasev1beta1 "github.com/crossplane/provider-azure/apis/database/v1beta1"
2727
keyvaultv1alpha1 "github.com/crossplane/provider-azure/apis/keyvault/v1alpha1"
2828
networkv1alpha3 "github.com/crossplane/provider-azure/apis/network/v1alpha3"
29+
rbacv1alpha1 "github.com/crossplane/provider-azure/apis/rbac/v1alpha1"
2930
storagev1alpha3 "github.com/crossplane/provider-azure/apis/storage/v1alpha3"
3031
azurev1alpha3 "github.com/crossplane/provider-azure/apis/v1alpha3"
3132
azurev1beta1 "github.com/crossplane/provider-azure/apis/v1beta1"
@@ -42,6 +43,7 @@ func init() {
4243
databasev1beta1.SchemeBuilder.AddToScheme,
4344
keyvaultv1alpha1.SchemeBuilder.AddToScheme,
4445
networkv1alpha3.SchemeBuilder.AddToScheme,
46+
rbacv1alpha1.SchemeBuilder.AddToScheme,
4547
storagev1alpha3.SchemeBuilder.AddToScheme,
4648
)
4749
}

apis/rbac/rbac.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
Copyright 2021 The Crossplane Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// Package rbac contains Azure rbac API versions
18+
package rbac

apis/rbac/v1alpha1/doc.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
Copyright 2021 The Crossplane Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// Package v1alpha1 contains managed resources for Azure rbac.
18+
// +kubebuilder:object:generate=true
19+
// +groupName=rbac.azure.crossplane.io
20+
// +versionName=v1alpha1
21+
package v1alpha1

apis/rbac/v1alpha1/referencers.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
Copyright 2021 The Crossplane Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha1
18+
19+
import (
20+
"context"
21+
22+
"github.com/pkg/errors"
23+
24+
"sigs.k8s.io/controller-runtime/pkg/client"
25+
26+
"github.com/crossplane/crossplane-runtime/pkg/reference"
27+
)
28+
29+
// ResolveReferences of this ServicePrincipal
30+
func (mg *ServicePrincipal) ResolveReferences(ctx context.Context, c client.Reader) error {
31+
r := reference.NewAPIResolver(c, mg)
32+
33+
// Resolve spec.applicationID
34+
rsp, err := r.Resolve(ctx, reference.ResolutionRequest{
35+
CurrentValue: mg.Spec.ForProvider.ApplicationID,
36+
Reference: mg.Spec.ForProvider.ApplicationIDRef,
37+
Selector: mg.Spec.ForProvider.ApplicationIDSelector,
38+
To: reference.To{Managed: &Application{}, List: &ApplicationList{}},
39+
Extract: reference.ExternalName(),
40+
})
41+
if err != nil {
42+
return errors.Wrap(err, "spec.applicationID")
43+
}
44+
mg.Spec.ForProvider.ApplicationID = rsp.ResolvedValue
45+
mg.Spec.ForProvider.ApplicationIDRef = rsp.ResolvedReference
46+
47+
return nil
48+
}
49+
50+
// ResolveReferences of this ServicePrincipal
51+
func (mg *RoleAssignment) ResolveReferences(ctx context.Context, c client.Reader) error {
52+
r := reference.NewAPIResolver(c, mg)
53+
54+
rsp, err := r.Resolve(ctx, reference.ResolutionRequest{
55+
CurrentValue: mg.Spec.ForProvider.PrincipalID,
56+
Reference: mg.Spec.ForProvider.PrincipalIDRef,
57+
Selector: mg.Spec.ForProvider.PrincipalIDSelector,
58+
To: reference.To{Managed: &ServicePrincipal{}, List: &ServicePrincipalList{}},
59+
Extract: reference.ExternalName(),
60+
})
61+
if err != nil {
62+
return errors.Wrap(err, "spec.principalID")
63+
}
64+
mg.Spec.ForProvider.PrincipalID = rsp.ResolvedValue
65+
mg.Spec.ForProvider.PrincipalIDRef = rsp.ResolvedReference
66+
67+
return nil
68+
}

apis/rbac/v1alpha1/register.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
Copyright 2019 The Crossplane Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha1
18+
19+
import (
20+
"reflect"
21+
22+
"k8s.io/apimachinery/pkg/runtime/schema"
23+
"sigs.k8s.io/controller-runtime/pkg/scheme"
24+
)
25+
26+
// Package type metadata.
27+
const (
28+
Group = "rbac.azure.crossplane.io"
29+
Version = "v1alpha1"
30+
)
31+
32+
var (
33+
// SchemeGroupVersion is group version used to register these objects
34+
SchemeGroupVersion = schema.GroupVersion{Group: Group, Version: Version}
35+
36+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
37+
SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion}
38+
)
39+
40+
// Application type metadata.
41+
var (
42+
ApplicationKind = reflect.TypeOf(Application{}).Name()
43+
ApplicationGroupKind = schema.GroupKind{Group: Group, Kind: ApplicationKind}.String()
44+
ApplicationKindAPIVersion = ApplicationKind + "." + SchemeGroupVersion.String()
45+
ApplicationGroupVersionKind = SchemeGroupVersion.WithKind(ApplicationKind)
46+
47+
ServicePrincipalKind = reflect.TypeOf(ServicePrincipal{}).Name()
48+
ServicePrincipalGroupKind = schema.GroupKind{Group: Group, Kind: ServicePrincipalKind}.String()
49+
ServicePrincipalKindAPIVersion = ServicePrincipalKind + "." + SchemeGroupVersion.String()
50+
ServicePrincipalGroupVersionKind = SchemeGroupVersion.WithKind(ServicePrincipalKind)
51+
52+
RoleAssignmentKind = reflect.TypeOf(RoleAssignment{}).Name()
53+
RoleAssignmentGroupKind = schema.GroupKind{Group: Group, Kind: RoleAssignmentKind}.String()
54+
RoleAssignmentKindAPIVersion = RoleAssignmentKind + "." + SchemeGroupVersion.String()
55+
RoleAssignmentGroupVersionKind = SchemeGroupVersion.WithKind(RoleAssignmentKind)
56+
)
57+
58+
func init() {
59+
SchemeBuilder.Register(&Application{}, &ApplicationList{})
60+
SchemeBuilder.Register(&ServicePrincipal{}, &ServicePrincipalList{})
61+
SchemeBuilder.Register(&RoleAssignment{}, &RoleAssignmentList{})
62+
}

apis/rbac/v1alpha1/types.go

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
/*
2+
Copyright 2019 The Crossplane Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha1
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
22+
xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1"
23+
)
24+
25+
// ApplicationParameters parameters for an application.
26+
type ApplicationParameters struct {
27+
// AvailableToOtherTenants - Whether the application is available to other tenants.
28+
// +optional
29+
// +immutable
30+
AvailableToOtherTenants *bool `json:"availableToOtherTenants,omitempty"`
31+
32+
// DisplayName - The display name of the application.
33+
// +optional
34+
// +immutable
35+
DisplayName *string `json:"displayName,omitempty"`
36+
37+
// Homepage - The home page of the application.
38+
// +optional
39+
// +immutable
40+
Homepage *string `json:"homepage,omitempty"`
41+
42+
// IdentifierUris - A collection of URIs for the application.
43+
// +optional
44+
// +immutable
45+
IdentifierURIs []string `json:"identifierUris,omitempty"`
46+
}
47+
48+
// An ApplicationSpec defines the desired state of an Application.
49+
type ApplicationSpec struct {
50+
xpv1.ResourceSpec `json:",inline"`
51+
ForProvider ApplicationParameters `json:"forProvider"`
52+
}
53+
54+
// An ApplicationStatus represents the observed state of an Application.
55+
type ApplicationStatus struct {
56+
xpv1.ResourceStatus `json:",inline"`
57+
58+
// ApplicationID - The application ID.
59+
ApplicationID string `json:"applicationID,omitempty"`
60+
}
61+
62+
// +kubebuilder:object:root=true
63+
64+
// A Application is a managed resource that represents an Application.
65+
// +kubebuilder:printcolumn:name="READY",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].status"
66+
// +kubebuilder:printcolumn:name="SYNCED",type="string",JSONPath=".status.conditions[?(@.type=='Synced')].status"
67+
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp"
68+
// +kubebuilder:subresource:status
69+
// +kubebuilder:resource:scope=Cluster,categories={crossplane,managed,azure}
70+
type Application struct {
71+
metav1.TypeMeta `json:",inline"`
72+
metav1.ObjectMeta `json:"metadata,omitempty"`
73+
74+
Spec ApplicationSpec `json:"spec"`
75+
Status ApplicationStatus `json:"status,omitempty"`
76+
}
77+
78+
// +kubebuilder:object:root=true
79+
80+
// ApplicationList contains a list of Application items
81+
type ApplicationList struct {
82+
metav1.TypeMeta `json:",inline"`
83+
metav1.ListMeta `json:"metadata,omitempty"`
84+
Items []Application `json:"items"`
85+
}
86+
87+
// An ServicePrincipalParameters defines the desired state of an ServicePrincipal.
88+
type ServicePrincipalParameters struct {
89+
// ApplicationID - The application ID.
90+
// +optional
91+
ApplicationID string `json:"applicationID,omitempty"`
92+
93+
// ApplicationIDRef - A reference to the Application id.
94+
// +optional
95+
// +immutable
96+
ApplicationIDRef *xpv1.Reference `json:"applicationIDRef,omitempty"`
97+
98+
// ApplicationIDSelector - Select a reference to the Application id.
99+
// +immutable
100+
ApplicationIDSelector *xpv1.Selector `json:"applicationIDSelector,omitempty"`
101+
102+
// AccountEnabled - whether or not the service principal account is enabled
103+
// +optional
104+
// +immutable
105+
AccountEnabled *bool `json:"accountEnabled,omitempty"`
106+
}
107+
108+
// An ServicePrincipalSpec defines the desired state of an ServicePrincipal.
109+
type ServicePrincipalSpec struct {
110+
xpv1.ResourceSpec `json:",inline"`
111+
ForProvider ServicePrincipalParameters `json:"forProvider"`
112+
}
113+
114+
// An ServicePrincipalStatus represents the observed state of an ServicePrincipal.
115+
type ServicePrincipalStatus struct {
116+
xpv1.ResourceStatus `json:",inline"`
117+
}
118+
119+
// +kubebuilder:object:root=true
120+
121+
// A ServicePrincipal is a managed resource that represents an ServicePrincipal.
122+
// +kubebuilder:printcolumn:name="READY",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].status"
123+
// +kubebuilder:printcolumn:name="SYNCED",type="string",JSONPath=".status.conditions[?(@.type=='Synced')].status"
124+
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp"
125+
// +kubebuilder:subresource:status
126+
// +kubebuilder:resource:scope=Cluster,categories={crossplane,managed,azure}
127+
type ServicePrincipal struct {
128+
metav1.TypeMeta `json:",inline"`
129+
metav1.ObjectMeta `json:"metadata,omitempty"`
130+
131+
Spec ServicePrincipalSpec `json:"spec"`
132+
Status ServicePrincipalStatus `json:"status,omitempty"`
133+
}
134+
135+
// An RoleAssignmentParameters defines the desired state of an RoleAssignment.
136+
type RoleAssignmentParameters struct {
137+
// PrincipalID - The principal ID assigned to the role.
138+
// This maps to the ID inside the Active Directory.
139+
// It can point to a user, service principal, or security group.
140+
// +optional
141+
PrincipalID string `json:"principalID,omitempty"`
142+
143+
// PrincipalIDRef - A reference to the Principal id.
144+
// +optional
145+
// +immutable
146+
PrincipalIDRef *xpv1.Reference `json:"principalIDRef,omitempty"`
147+
148+
// PrincipalIDRef - Select a reference to the Principal id.
149+
// +immutable
150+
PrincipalIDSelector *xpv1.Selector `json:"principalIDSelector,omitempty"`
151+
152+
// RoleID - The role definition ID.
153+
// +immutable
154+
// +kubebuilder:validation:Required
155+
RoleID string `json:"roleID"`
156+
157+
// Scope - The role assignment scope.
158+
// +immutable
159+
// +kubebuilder:validation:Required
160+
Scope string `json:"scope"`
161+
}
162+
163+
// +kubebuilder:object:root=true
164+
165+
// ServicePrincipalList contains a list of ServicePrincipal items
166+
type ServicePrincipalList struct {
167+
metav1.TypeMeta `json:",inline"`
168+
metav1.ListMeta `json:"metadata,omitempty"`
169+
Items []ServicePrincipal `json:"items"`
170+
}
171+
172+
// An RoleAssignmentSpec defines the desired state of an RoleAssignment.
173+
type RoleAssignmentSpec struct {
174+
xpv1.ResourceSpec `json:",inline"`
175+
ForProvider RoleAssignmentParameters `json:"forProvider"`
176+
}
177+
178+
// An RoleAssignmentStatus represents the observed state of an RoleAssignment.
179+
type RoleAssignmentStatus struct {
180+
xpv1.ResourceStatus `json:",inline"`
181+
}
182+
183+
// +kubebuilder:object:root=true
184+
185+
// A RoleAssignment is a managed resource that represents an RoleAssignment.
186+
// +kubebuilder:printcolumn:name="READY",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].status"
187+
// +kubebuilder:printcolumn:name="SYNCED",type="string",JSONPath=".status.conditions[?(@.type=='Synced')].status"
188+
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp"
189+
// +kubebuilder:subresource:status
190+
// +kubebuilder:resource:scope=Cluster,categories={crossplane,managed,azure}
191+
type RoleAssignment struct {
192+
metav1.TypeMeta `json:",inline"`
193+
metav1.ObjectMeta `json:"metadata,omitempty"`
194+
195+
Spec RoleAssignmentSpec `json:"spec"`
196+
Status RoleAssignmentStatus `json:"status,omitempty"`
197+
}
198+
199+
// +kubebuilder:object:root=true
200+
201+
// RoleAssignmentList contains a list of RoleAssignment items
202+
type RoleAssignmentList struct {
203+
metav1.TypeMeta `json:",inline"`
204+
metav1.ListMeta `json:"metadata,omitempty"`
205+
Items []RoleAssignment `json:"items"`
206+
}

0 commit comments

Comments
 (0)