graphrbac

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: 8 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddClientSecret

func AddClientSecret(ctx context.Context, objID string) (autorest.Response, error)

AddClientSecret adds a client secret (aka password credential) to the specified AAD app

func CreateADApplication

func CreateADApplication(ctx context.Context) (graphrbac.Application, error)

CreateADApplication creates an Azure Active Directory (AAD) application

func CreateServicePrincipal

func CreateServicePrincipal(ctx context.Context, appID string) (graphrbac.ServicePrincipal, error)

CreateServicePrincipal creates a service principal on the specified Azure Active Directory application.

Example
ctx := context.Background()

app, err := CreateADApplication(ctx)
if err != nil {
	helpers.PrintAndLog(err.Error())
}
helpers.PrintAndLog("ad app created")

sp, err := CreateServicePrincipal(ctx, *app.AppID)
if err != nil {
	helpers.PrintAndLog(err.Error())
}
helpers.PrintAndLog("service principal created")

_, err = AddClientSecret(ctx, *app.ObjectID)
if err != nil {
	helpers.PrintAndLog(err.Error())
}
helpers.PrintAndLog("added client secret")

helpers.SetResourceGroupName("CreateServicePrincipal")
_, err = resources.CreateGroup(ctx, helpers.ResourceGroupName())
if err != nil {
	helpers.PrintAndLog(err.Error())
}
helpers.PrintAndLog("created resource group")

list, err := authorization.ListRoles(ctx, "roleName eq 'Contributor'")
if err != nil {
	helpers.PrintAndLog(err.Error())
}
helpers.PrintAndLog("list contributor role definition, with resource group scope")

_, err = authorization.AssignRole(ctx, *sp.ObjectID, *list.Values()[0].ID)
if err != nil {
	helpers.PrintAndLog(err.Error())
}
helpers.PrintAndLog("create role definition")

if !helpers.KeepResources() {
	_, err = resources.DeleteGroup(ctx, helpers.ResourceGroupName())
	if err != nil {
		helpers.PrintAndLog(err.Error())
	}

	_, err = DeleteADApplication(ctx, *app.ObjectID)
	if err != nil {
		helpers.PrintAndLog(err.Error())
	}
}
Output:

ad app created
service principal created
added client secret
created resource group
list contributor role definition, with resource group scope
create role definition

func DeleteADApplication

func DeleteADApplication(ctx context.Context, appObjID string) (autorest.Response, error)

DeleteADApplication deletes the specified AAD application

func GetCurrentUser

func GetCurrentUser(ctx context.Context) (graphrbac.AADObject, error)

GetCurrentUser gets the Azure Active Directory object of the current user

Types

This section is empty.

Jump to

Keyboard shortcuts

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