authorization

package
v0.0.0-...-e747c7c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 5, 2018 License: MIT Imports: 9 Imported by: 0

Documentation

Index

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL