Documentation ¶
Index ¶
- func AssignRole(ctx context.Context, principalID, roleDefID string) (role authorization.RoleAssignment, err error)
- func AssignRoleWithSubscriptionScope(ctx context.Context, principalID, roleDefID string) (role authorization.RoleAssignment, err error)
- func DeleteRoleAssignment(ctx context.Context, id string) (authorization.RoleAssignment, error)
- func ListRoles(ctx context.Context, filter string) (list authorization.RoleDefinitionListResultPage, err error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssignRole ¶
func AssignRole(ctx context.Context, principalID, roleDefID string) (role authorization.RoleAssignment, err error)
AssignRole assigns a role, with a resource group scope
Example ¶
helpers.SetResourceGroupName("AssignRole") ctx := context.Background() defer resources.Cleanup(ctx) _, err := resources.CreateGroup(ctx, helpers.ResourceGroupName()) if err != nil { helpers.PrintAndLog(err.Error()) } list, err := ListRoles(ctx, "roleName eq 'Contributor'") if err != nil { helpers.PrintAndLog(err.Error()) } helpers.PrintAndLog("got role definitions list") rgRole, err := AssignRole(ctx, helpers.ServicePrincipalObjectID(), *list.Values()[0].ID) if err != nil { helpers.PrintAndLog(err.Error()) } helpers.PrintAndLog("role assigned with resource group scope") subRole, err := AssignRoleWithSubscriptionScope(ctx, helpers.ServicePrincipalObjectID(), *list.Values()[0].ID) if err != nil { helpers.PrintAndLog(err.Error()) } helpers.PrintAndLog("role assigned with subscription scope") if !helpers.KeepResources() { DeleteRoleAssignment(ctx, *rgRole.ID) if err != nil { helpers.PrintAndLog(err.Error()) } DeleteRoleAssignment(ctx, *subRole.ID) if err != nil { helpers.PrintAndLog(err.Error()) } }
Output: got role definitions list role assigned with resource group scope role assigned with subscription scope
func AssignRoleWithSubscriptionScope ¶
func AssignRoleWithSubscriptionScope(ctx context.Context, principalID, roleDefID string) (role authorization.RoleAssignment, err error)
AssignRoleWithSubscriptionScope assigns a role, with a subscription scope
func DeleteRoleAssignment ¶
func DeleteRoleAssignment(ctx context.Context, id string) (authorization.RoleAssignment, error)
DeleteRoleAssignment deletes a roleassignment
func ListRoles ¶
func ListRoles(ctx context.Context, filter string) (list authorization.RoleDefinitionListResultPage, err error)
ListRoles gets the role definitions in the used resource group
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.