authorization

package
v0.0.0-...-042701a Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2020 License: MIT Imports: 8 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 to the named principal at the scope of the current group.

Example
var groupName = config.GenerateGroupName("Authorization")
config.SetGroupName(groupName)

ctx := context.Background()
defer resources.Cleanup(ctx)

_, err := resources.CreateGroup(ctx, groupName)
if err != nil {
	util.LogAndPanic(err)
}

list, err := ListRoleDefinitions(ctx, "roleName eq 'Contributor'")
if err != nil {
	util.LogAndPanic(err)
}
util.PrintAndLog("got role definitions list")

var userID string
user, err := graphrbac.GetCurrentUser(ctx)
if err != nil {
	log.Printf("could not get object for current user: %v\n", err)
	log.Printf("using service principal ID instead")
	userID = config.ClientID()
} else {
	userID = *user.ObjectID
}

groupRole, err := AssignRole(ctx, userID, *list.Values()[0].ID)
if err != nil {
	util.LogAndPanic(err)
}
util.PrintAndLog("role assigned with resource group scope")

subscriptionRole, err := AssignRoleWithSubscriptionScope(
	ctx, userID, *list.Values()[0].ID)
if err != nil {
	util.LogAndPanic(err)
}
util.PrintAndLog("role assigned with subscription scope")

if !config.KeepResources() {
	if _, err := DeleteRoleAssignment(ctx, *groupRole.ID); err != nil {
		util.LogAndPanic(err)
	}

	if _, err := DeleteRoleAssignment(ctx, *subscriptionRole.ID); err != nil {
		util.LogAndPanic(err)
	}
}
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 to the named principal at the subscription scope.

func DeleteRoleAssignment

func DeleteRoleAssignment(ctx context.Context, id string) (authorization.RoleAssignment, error)

DeleteRoleAssignment deletes a roleassignment

func ListRoleDefinitions

func ListRoleDefinitions(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