sigs.k8s.io/cluster-api-provider-azure@v1.14.3/azure/services/roleassignments/spec.go (about) 1 /* 2 Copyright 2019 The Kubernetes 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 roleassignments 18 19 import ( 20 "context" 21 22 "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/authorization/armauthorization/v2" 23 "github.com/pkg/errors" 24 "k8s.io/utils/ptr" 25 ) 26 27 // RoleAssignmentSpec defines the specification for a role assignment. 28 type RoleAssignmentSpec struct { 29 Name string 30 MachineName string 31 ResourceGroup string 32 ResourceType string 33 PrincipalID *string 34 PrincipalType armauthorization.PrincipalType 35 RoleDefinitionID string 36 Scope string 37 } 38 39 // ResourceName returns the name of the role assignment. 40 func (s *RoleAssignmentSpec) ResourceName() string { 41 return s.Name 42 } 43 44 // ResourceGroupName returns the name of the resource group. 45 func (s *RoleAssignmentSpec) ResourceGroupName() string { 46 return s.ResourceGroup 47 } 48 49 // OwnerResourceName returns the scope for role assignment. 50 // TODO: Consider renaming the function for better readability (@sonasingh46). 51 func (s *RoleAssignmentSpec) OwnerResourceName() string { 52 return s.Scope 53 } 54 55 // Parameters returns the parameters for the RoleAssignmentSpec. 56 func (s *RoleAssignmentSpec) Parameters(ctx context.Context, existing interface{}) (interface{}, error) { 57 if existing != nil { 58 if _, ok := existing.(armauthorization.RoleAssignment); !ok { 59 return nil, errors.Errorf("%T is not an armauthorization.RoleAssignment", existing) 60 } 61 // RoleAssignmentSpec already exists 62 return nil, nil 63 } 64 return armauthorization.RoleAssignmentCreateParameters{ 65 Properties: &armauthorization.RoleAssignmentProperties{ 66 PrincipalID: s.PrincipalID, 67 RoleDefinitionID: ptr.To(s.RoleDefinitionID), 68 PrincipalType: ptr.To(s.PrincipalType), 69 }, 70 }, nil 71 }