-
Notifications
You must be signed in to change notification settings - Fork 431
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(role_assignment): make roleassignment reconcile async
Signed-off-by: Ashutosh Kumar <[email protected]>
- Loading branch information
1 parent
8be8e43
commit 35426b5
Showing
4 changed files
with
148 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package roleassignments | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/Azure/azure-sdk-for-go/profiles/2019-03-01/authorization/mgmt/authorization" | ||
"github.com/Azure/go-autorest/autorest/to" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
// RoleAssignmentSpec defines the specification for a Role Assignment. | ||
type RoleAssignmentSpec struct { | ||
RoleAssignmentName string | ||
ResourceGroup string | ||
MachineName string | ||
Name string | ||
ResourceType string | ||
SubscriptionID string | ||
PrincipalID *string | ||
} | ||
|
||
// ResourceName returns the name of the role assignment. | ||
func (s *RoleAssignmentSpec) ResourceName() string { | ||
return s.RoleAssignmentName | ||
} | ||
|
||
// ResourceGroupName returns the name of the resource group. | ||
func (s *RoleAssignmentSpec) ResourceGroupName() string { | ||
return s.ResourceGroup | ||
} | ||
|
||
// OwnerResourceName is a no-op for role assignment. | ||
func (s *RoleAssignmentSpec) OwnerResourceName() string { | ||
return "" | ||
} | ||
|
||
// Parameters returns the parameters for the RoleAssignmentSpec. | ||
func (s *RoleAssignmentSpec) Parameters(existing interface{}) (interface{}, error) { | ||
if existing != nil { | ||
if _, ok := existing.(authorization.RoleAssignment); !ok { | ||
return nil, errors.Errorf("%T is not a authorization.RoleAssignment", existing) | ||
} | ||
// RoleAssignmentSpec already exists | ||
return nil, nil | ||
} | ||
scope := fmt.Sprintf("/subscriptions/%s/", s.SubscriptionID) | ||
// Azure built-in roles https://docs.microsoft.com/en-us/azure/role-based-access-control/built-in-roles | ||
contributorRoleDefinitionID := fmt.Sprintf("/subscriptions/%s/providers/Microsoft.Authorization/roleDefinitions/%s", s.SubscriptionID, azureBuiltInContributorID) | ||
properties := &authorization.RoleAssignmentPropertiesWithScope{ | ||
Scope: to.StringPtr(scope), | ||
RoleDefinitionID: to.StringPtr(contributorRoleDefinitionID), | ||
PrincipalID: s.PrincipalID, | ||
} | ||
return authorization.RoleAssignment{ | ||
Name: to.StringPtr(s.RoleAssignmentName), | ||
Properties: properties, | ||
}, nil | ||
} |