Documentation ¶
Overview ¶
Package maz is a library of functions for interacting with essential Azure APIs via REST calls. Currently it supports two APIs, the Azure Resource Management (ARM) API and the MS Graph API, but can be extended to support additional APIs. This package obviously also includes code to get an Azure JWT token using the MSAL library, to then use against either the 2 currently supported Azure APIs.
Index ¶
- Constants
- func AdRolesCountAzure(z *Config) int64
- func AdRolesCountLocal(z *Config) int64
- func AddAppSecret(id, displayName, expiry string, z *Config)
- func AddSpSecret(id, displayName, expiry string, z *Config)
- func ApiCall(method, apiUrl string, z *Config, payload jsonT, params strMapT, verbose bool) (result jsonT, rsc int, err error)
- func ApiDelete(apiUrl string, z *Config, params strMapT) (result jsonT, rsc int, err error)
- func ApiDeleteDebug(apiUrl string, z *Config, params strMapT) (result jsonT, rsc int, err error)
- func ApiErrorCheck(method, apiUrl, caller string, r jsonT)
- func ApiGet(apiUrl string, z *Config, params strMapT) (result jsonT, rsc int, err error)
- func ApiGetDebug(apiUrl string, z *Config, params strMapT) (result jsonT, rsc int, err error)
- func ApiPatch(apiUrl string, z *Config, payload jsonT, params strMapT) (result jsonT, rsc int, err error)
- func ApiPatchDebug(apiUrl string, z *Config, payload jsonT, params strMapT) (result jsonT, rsc int, err error)
- func ApiPost(apiUrl string, z *Config, payload jsonT, params strMapT) (result jsonT, rsc int, err error)
- func ApiPostDebug(apiUrl string, z *Config, payload jsonT, params strMapT) (result jsonT, rsc int, err error)
- func ApiPut(apiUrl string, z *Config, payload jsonT, params strMapT) (result jsonT, rsc int, err error)
- func ApiPutDebug(apiUrl string, z *Config, payload jsonT, params strMapT) (result jsonT, rsc int, err error)
- func AppsCountAzure(z *Config) int64
- func AppsCountLocal(z *Config) int64
- func CompareSpecfileToAzure(filePath string, z *Config)
- func CreateAzRoleAssignment(x map[string]interface{}, z *Config)
- func CreateDirGroup(jsonObj map[string]interface{}, z *Config) (x map[string]interface{}, e error)
- func CreateSkeletonFile(t string)
- func DecodeJwtToken(tokenString string)
- func DeleteAzObject(force bool, specifier string, z *Config)
- func DeleteAzRoleAssignmentByFqid(fqid string, z *Config) map[string]interface{}
- func DeleteAzRoleDefinitionByFqid(fqid string, z *Config) map[string]interface{}
- func DeleteDirGroup(opts *Options, z *Config)
- func DeleteGroupFromCache(id string, z *Config) error
- func DiffLists(list1, list2 []interface{}) (added, removed []interface{}, same bool)
- func DiffRoleDefinitionSpecfileVsAzure(a, b map[string]interface{}, z *Config)
- func DumpLoginValues(z *Config)
- func FindAzObjectsById(id string, z *Config) (list []interface{})
- func GetAzAdRoleById(id string, z *Config) map[string]interface{}
- func GetAzAdRoles(z *Config, verbose bool) (list []interface{})
- func GetAzAllPages(apiUrl string, z *Config) (list []interface{})
- func GetAzAppById(id string, z *Config) map[string]interface{}
- func GetAzApps(z *Config, verbose bool) (list []interface{})
- func GetAzMgGroups(z *Config) (list []interface{})
- func GetAzObjectById(t, id string, z *Config) (x map[string]interface{})
- func GetAzObjects(apiUrl string, z *Config, verbose bool) (deltaSet []interface{}, deltaLinkMap map[string]interface{})
- func GetAzRbacScopes(z *Config) (scopes []string)
- func GetAzRoleAssignmentById(id string, z *Config) map[string]interface{}
- func GetAzRoleAssignmentByObject(x map[string]interface{}, z *Config) (y map[string]interface{})
- func GetAzRoleAssignments(z *Config, verbose bool) (list []interface{})
- func GetAzRoleDefinitionById(id string, z *Config) map[string]interface{}
- func GetAzRoleDefinitionByName(roleName string, z *Config) (y map[string]interface{})
- func GetAzRoleDefinitionByObject(x map[string]interface{}, z *Config) (y map[string]interface{})
- func GetAzRoleDefinitions(z *Config, verbose bool) (list []interface{})
- func GetAzSpById(id string, z *Config) map[string]interface{}
- func GetAzSps(z *Config, verbose bool) (list []interface{})
- func GetAzSubscriptionById(id string, z *Config) map[string]interface{}
- func GetAzSubscriptions(z *Config) (list []interface{})
- func GetAzSubscriptionsIds(z *Config) (scopes []string)
- func GetAzUserById(id string, z *Config) map[string]interface{}
- func GetAzUsers(z *Config, verbose bool) (list []interface{})
- func GetCachedObjects(cacheFile string) (cachedList []interface{})
- func GetDirGroupFromAzureById(id string, z *Config) map[string]interface{}
- func GetDirGroupFromAzureByName(displayName string, z *Config) []interface{}
- func GetIdMapApps(z *Config) (nameMap map[string]string)
- func GetIdMapGroups(z *Config) (nameMap map[string]string)
- func GetIdMapMgGroups(z *Config) (nameMap map[string]string)
- func GetIdMapRoleDefs(z *Config) (nameMap map[string]string)
- func GetIdMapSps(z *Config) (nameMap map[string]string)
- func GetIdMapSubs(z *Config) (nameMap map[string]string)
- func GetIdMapUsers(z *Config) (nameMap map[string]string)
- func GetMatchingAdRoles(filter string, force bool, z *Config) (list []interface{})
- func GetMatchingApps(filter string, force bool, z *Config) (list []interface{})
- func GetMatchingMgGroups(filter string, force bool, z *Config) (list []interface{})
- func GetMatchingRoleAssignments(filter string, force bool, z *Config) (list []interface{})
- func GetMatchingRoleDefinitions(filter string, force bool, z *Config) (list []interface{})
- func GetMatchingSps(filter string, force bool, z *Config) (list []interface{})
- func GetMatchingSubscriptions(filter string, force bool, z *Config) (list []interface{})
- func GetMatchingUsers(filter string, force bool, z *Config) (list []interface{})
- func GetObjectFromFile(filePath string) (formatType, t string, specfileObj map[string]interface{})
- func GetObjects(t, filter string, force bool, z *Config) (list []interface{})
- func GetTokenByCredentials(scopes []string, z *Config) (token string, err error)
- func GetTokenInteractively(scopes []string, z *Config) (token string, err error)
- func GroupsCountAzure(z *Config) int64
- func GroupsCountLocal(z *Config) int64
- func JsonObjectFromDirGroup(g *DirGroup) map[string]interface{}
- func MgGroupCountAzure(z *Config) int64
- func MgGroupCountLocal(z *Config) int64
- func MgType(typeIn string) string
- func NormalizeCache(baseSet, deltaSet []interface{}) (list []interface{})
- func PrintAdRole(x map[string]interface{}, z *Config)
- func PrintAllDirGroupsTersely(all DirGroupList)
- func PrintApiErrMsg(msg string)
- func PrintApp(x map[string]interface{}, z *Config)
- func PrintAppRoleAssignmentsOthers(appRoleAssignments []interface{}, z *Config)
- func PrintAppRoleAssignmentsSp(roleNameMap map[string]string, appRoleAssignments []interface{})
- func PrintCertificateList(certificates []interface{})
- func PrintCountStatus(z *Config)
- func PrintCountStatusDirGroups(z *Config)
- func PrintDirGroup(x map[string]interface{}, z *Config)
- func PrintDirGroupTersely(g DirGroup)
- func PrintHeaders(headers http.Header)
- func PrintMatching(printFormat, t, specifier string, z *Config)
- func PrintMemberOfs(t string, memberOf []interface{})
- func PrintMgChildren(indent int, children []interface{})
- func PrintMgGroup(x map[string]interface{})
- func PrintMgTree(z *Config)
- func PrintObject(t string, x map[string]interface{}, z *Config)
- func PrintObjectById(id string, z *Config)
- func PrintOwners(owners []interface{})
- func PrintPags(z *Config)
- func PrintParams(params url.Values)
- func PrintRoleAssignment(x map[string]interface{}, z *Config)
- func PrintRoleAssignmentReport(z *Config)
- func PrintRoleDefinition(x map[string]interface{}, z *Config)
- func PrintSecretList(secretsList []interface{})
- func PrintSp(x map[string]interface{}, z *Config)
- func PrintStringMapColor(strMap map[string]string)
- func PrintSubscription(x map[string]interface{})
- func PrintTersely(t string, object interface{})
- func PrintUser(x map[string]interface{}, z *Config)
- func RemoveAppSecret(id, keyId string, z *Config)
- func RemoveCacheFile(t string, z *Config)
- func RemoveDirGroupCacheFile(z *Config)
- func RemoveSpSecret(id, keyId string, z *Config)
- func RenameDirGroup(opts *Options, z *Config)
- func RoleAssignmentsCountAzure(z *Config) int64
- func RoleAssignmentsCountLocal(z *Config) int64
- func RoleDefinitionCountAzure(z *Config) (builtin, custom int64)
- func RoleDefinitionCountLocal(z *Config) (builtin, custom int64)
- func SaveDirGroupsToCache(filePath string, groupList DirGroupList) error
- func SelectObject(id string, objSet []interface{}) map[string]interface{}
- func SetupApiTokens(z *Config)
- func SetupAutomatedLogin(z *Config)
- func SetupCredentials(z *Config)
- func SetupInterativeLogin(z *Config)
- func SpsCountAzure(z *Config) (native, microsoft int64)
- func SpsCountLocal(z *Config) (native, microsoft int64)
- func SubsCountAzure(z *Config) int64
- func SubsCountLocal(z *Config) int64
- func TokenValid(tokenString string) bool
- func UpdateDirGroup(id string, jsonObj map[string]interface{}, z *Config) error
- func UpsertAzObject(force bool, filePath string, z *Config)
- func UpsertAzRoleDefinition(force bool, x map[string]interface{}, z *Config)
- func UpsertDirGroup(opts *Options, z *Config)
- func UpsertDirGroupFromArgs(opts *Options, z *Config)
- func UpsertDirGroupFromFile(opts *Options, z *Config)
- func UpsertGroupInCache(group DirGroup, z *Config) error
- func UsersCountAzure(z *Config) int64
- func UsersCountLocal(z *Config) int64
- type Bundle
- type Config
- func (m *Config) AddAzHeader(key, value string) *Config
- func (m *Config) AddMgHeader(key, value string) *Config
- func (m *Config) SetInteractiveMode(interactive bool) *Config
- func (m *Config) SetTenantCredentials(tenantID, clientID, clientSecret string) *Config
- func (m *Config) SetUsername(username string) *Config
- func (m *Config) Validate() error
- type DirGroup
- type DirGroupList
- func GetAzureDirGroups(z *Config, verbose bool) DirGroupList
- func GetDirGroupByName(displayName string, z *Config) (matchingGroups DirGroupList)
- func GetMatchingGroups(filter string, force bool, z *Config) DirGroupList
- func LoadDirGroupsFromCache(filePath string) (DirGroupList, error)
- func NewDirGroupList() DirGroupList
- func NormalizeDirGroupCache(currentCache DirGroupList, deltaSet []interface{}) DirGroupList
- type Options
- func (a *Options) Count() int
- func (a *Options) Get(key string) (interface{}, bool)
- func (a *Options) GetBool(key string) (bool, bool)
- func (a *Options) GetInt(key string) (int, bool)
- func (a *Options) GetString(key string) (string, bool)
- func (a *Options) Set(key string, value interface{}) *Options
- func (a *Options) Validate(requiredKeys []string) error
- type TokenCache
Constants ¶
const ( ConstAuthUrl = "https://login.microsoftonline.com/" ConstMgUrl = "https://graph.microsoft.com" ConstAzUrl = "https://management.azure.com" ConstAzPowerShellClientId = "1950a258-227b-4e31-a9cf-717495945fc2" // 'Microsoft Azure PowerShell' ClientId ConstCacheFileExtension = "gz" ConstMgCacheFileAgePeriod = 1800 // Half hour ConstAzCacheFileAgePeriod = 86400 // One day )
Variables ¶
This section is empty.
Functions ¶
func AdRolesCountAzure ¶
Returns count of Azure AD directory role entries in current tenant
func AdRolesCountLocal ¶
Returns count of Azure AD directory role entries in local cache file
func AddAppSecret ¶
Creates/adds a secret to the given application
func AddSpSecret ¶
Creates/adds a secret to the given SP
func ApiCall ¶
func ApiCall(method, apiUrl string, z *Config, payload jsonT, params strMapT, verbose bool) (result jsonT, rsc int, err error)
Makes API calls and returns JSON object, Response StatusCode, and error. For a more clear explanation of how to interpret the JSON responses see https://eager.io/blog/go-and-json/ This function is the cornerstone of the maz package, extensively handling all API interactions.
func ApiDeleteDebug ¶
ApiCall alias to do a DELETE with debugging on
func ApiErrorCheck ¶
func ApiErrorCheck(method, apiUrl, caller string, r jsonT)
Prints useful error information if they occur
func ApiGetDebug ¶
ApiCall alias to do a GET with debugging on
func ApiPatch ¶
func ApiPatch(apiUrl string, z *Config, payload jsonT, params strMapT) (result jsonT, rsc int, err error)
ApiCall alias to do a PATCH
func ApiPatchDebug ¶
func ApiPatchDebug(apiUrl string, z *Config, payload jsonT, params strMapT) (result jsonT, rsc int, err error)
ApiCall alias to do a PATCH with debugging on
func ApiPost ¶
func ApiPost(apiUrl string, z *Config, payload jsonT, params strMapT) (result jsonT, rsc int, err error)
ApiCall alias to do a POST
func ApiPostDebug ¶
func ApiPostDebug(apiUrl string, z *Config, payload jsonT, params strMapT) (result jsonT, rsc int, err error)
ApiCall alias to do a POST with debugging on
func ApiPut ¶
func ApiPut(apiUrl string, z *Config, payload jsonT, params strMapT) (result jsonT, rsc int, err error)
ApiCall alias to do a PUT
func ApiPutDebug ¶
func ApiPutDebug(apiUrl string, z *Config, payload jsonT, params strMapT) (result jsonT, rsc int, err error)
ApiCall alias to do a PUT with debugging on
func AppsCountAzure ¶
Retrieves count of all applications in Azure tenant
func AppsCountLocal ¶
Retrieves count of all applications in local cache file
func CompareSpecfileToAzure ¶
Compares object in specfile to what is in Azure
func CreateAzRoleAssignment ¶
Creates an RBAC role assignment as defined by give x object
func CreateDirGroup ¶
Creates Azure directory group.
func CreateSkeletonFile ¶
func CreateSkeletonFile(t string)
Creates specfile skeleton/scaffold files
func DecodeJwtToken ¶
func DecodeJwtToken(tokenString string)
Decode and dump token string, trusting without formal verification and validation
func DeleteAzObject ¶
Deletes object based on string specifier (currently only supports roleDefinitions or Assignments) String specifier can be either of 3: UUID, specfile, or displaName (only for roleDefinition) 1) Search Azure by given identifier; 2) Grab object's Fully Qualified Id string; 3) Print and prompt for confirmation; 4) Delete or abort
func DeleteAzRoleAssignmentByFqid ¶
Deletes an RBAC role assignment by its fully qualified object Id Example of a fully qualified Id string (note it's one long line):
/providers/Microsoft.Management/managementGroups/33550b0b-2929-4b4b-adad-cccc66664444 \ /providers/Microsoft.Authorization/roleAssignments/5d586a7b-3f4b-4b5c-844a-3fa8efe49ab3
func DeleteAzRoleDefinitionByFqid ¶
Deletes an RBAC role definition object by its fully qualified object Id Example of a fully qualified Id string:
"/providers/Microsoft.Authorization/roleDefinitions/50a6ff7c-3ac5-4acc-b4f4-9a43aee0c80f"
func DeleteGroupFromCache ¶
Deletes a group by UUID from the local cache.
func DiffLists ¶
func DiffLists(list1, list2 []interface{}) (added, removed []interface{}, same bool)
Compares two list of strings and returns added and removed items, and whether or not the lists are the same. Note they come in as []interface{} but we know they are strings. This is a special function for handling Azure RBAC role definition action differences.
func DiffRoleDefinitionSpecfileVsAzure ¶
Prints differences between role definition in Specfile (a) vs what is in Azure (b). The calling function must ensure that both a & b are valid role definition objects from a specfile and from Azure. A generic DiffJsonObject() function would probably be better for this.
func FindAzObjectsById ¶
Returns list of Azure objects with this UUID. We are saying a list because 1) the UUID could be an appId shared by an app and an SP, or 2) there could be UUID collisions with multiple objects potentially sharing the same UUID. Only checks for the maz package limited set of Azure object types.
func GetAzAdRoleById ¶
Gets Azure AD role definition by Object UUID, with all attributes
func GetAzAdRoles ¶
Gets all directory role definitions from Azure and sync to local cache. Shows progress if verbose = true
func GetAzAllPages ¶
Returns all Azure pages for given API URL call
func GetAzAppById ¶
Gets application by its Object UUID or by its appId, with all attributes
func GetAzApps ¶
Gets all applications from Azure and sync to local cache. Shows progress if verbose = true
func GetAzMgGroups ¶
func GetAzMgGroups(z *Config) (list []interface{})
Gets all management groups in current Azure tenant, and saves them to local cache file
func GetAzObjectById ¶
Retrieves Azure object by Object UUID
func GetAzObjects ¶
func GetAzObjects(apiUrl string, z *Config, verbose bool) (deltaSet []interface{}, deltaLinkMap map[string]interface{})
Generic Azure object deltaSet retriever function. Returns the set of new or updated items, and a deltaLink for running the next future Azure query. Implements the code logic pattern described at https://docs.microsoft.com/en-us/graph/delta-query-overview
func GetAzRbacScopes ¶
Gets all scopes in the Azure tenant RBAC hierarchy: Tenant Root Group and all management groups, plus all subscription scopes
func GetAzRoleAssignmentById ¶
Gets RBAC role assignment by its Object UUID. Unfortunately we have to iterate through the entire tenant scope hierarchy, which can take time.
func GetAzRoleAssignmentByObject ¶
Gets Azure resource RBAC role assignment object by matching given objects: roleId, principalId, and scope (the 3 parameters which make a role assignment unique)
func GetAzRoleAssignments ¶
Gets all role assignments objects in current Azure tenant and save them to local cache file. Option to be verbose (true) or quiet (false), since it can take a while. References:
https://learn.microsoft.com/en-us/azure/role-based-access-control/role-assignments-list-rest https://learn.microsoft.com/en-us/rest/api/authorization/role-assignments/list-for-subscription
func GetAzRoleDefinitionById ¶
Gets role definition by Object Id. Unfortunately we have to iterate through the entire tenant scope hierarchy, which can take time.
func GetAzRoleDefinitionByName ¶
Gets role definition by displayName See https://learn.microsoft.com/en-us/rest/api/authorization/role-definitions/list
func GetAzRoleDefinitionByObject ¶
Gets role definition object if it exists exactly as x object (as per essential attributes). Matches on: displayName and assignableScopes
func GetAzRoleDefinitions ¶
Gets all role definitions in current Azure tenant and save them to local cache file Option to be verbose (true) or quiet (false), since it can take a while. References:
https://learn.microsoft.com/en-us/azure/role-based-access-control/role-definitions-list https://learn.microsoft.com/en-us/rest/api/authorization/role-definitions/list
func GetAzSpById ¶
Gets service principal by its Object UUID or by its appId, with all attributes
func GetAzSps ¶
Gets all service principals from Azure and sync to local cache. Shows progress if verbose = true
func GetAzSubscriptionById ¶
Gets specific Azure subscription by Object UUID
func GetAzSubscriptions ¶
func GetAzSubscriptions(z *Config) (list []interface{})
Gets all subscription in current Azure tenant, and saves them to local cache file
func GetAzSubscriptionsIds ¶
Gets all subscription full IDs, i.e. "/subscriptions/UUID", which are commonly used as scopes for Azure resource RBAC role definitions and assignments
func GetAzUserById ¶
Gets Azure user object by Object UUID, with all attributes
func GetAzUsers ¶
Gets all users from Azure and sync to local cache. Show progress if verbose = true
func GetCachedObjects ¶
func GetCachedObjects(cacheFile string) (cachedList []interface{})
Retrieves locally cached list of objects in given cache file
func GetDirGroupFromAzureById ¶
Gets directory group JSON object from Azure by Id. Updates entry in local cache.
func GetDirGroupFromAzureByName ¶
Gets directory group JSON array from Azure by Name. We are only looking for a single group with this displayName, but MS Graph supports having groups with the very same displayName, so we return an array to allow for that possibility.
func GetIdMapApps ¶
Returns an id:name map of all applications
func GetIdMapGroups ¶
Returns id:name map of all groups
func GetIdMapMgGroups ¶
Returns id:name map of management groups
func GetIdMapRoleDefs ¶
Returns id:name map of all RBAC role definitions
func GetIdMapSps ¶
Returns an id:name map of all service principals
func GetIdMapSubs ¶
Returns id:name map of all subscriptions
func GetIdMapUsers ¶
Returns an id:name map of all users
func GetMatchingAdRoles ¶
Gets all AD roles matching on 'filter'. Returns entire list if filter is empty ""
func GetMatchingApps ¶
Gets all applications matching on 'filter'. Return entire list if filter is empty ""
func GetMatchingMgGroups ¶
Gets all Azure management groups matching on 'filter'. Returns entire list if filter is empty ""
func GetMatchingRoleAssignments ¶
Gets all RBAC role assignments matching on 'filter'. Return entire list if filter is empty ""
func GetMatchingRoleDefinitions ¶
Gets all role definitions matching on 'filter'. Returns entire list if filter is empty ""
func GetMatchingSps ¶
Gets all service principals matching on 'filter'. Return entire list if filter is empty ""
func GetMatchingSubscriptions ¶
Gets all Azure subscriptions matching on 'filter'. Returns entire list if filter is empty ""
func GetMatchingUsers ¶
Gets all users matching on 'filter'. Returns entire list if filter is empty ""
func GetObjectFromFile ¶
Processes given specfile and returns the specfile format type, the maz object letter string type, and the actual object.
func GetObjects ¶
Generic function to get objects of type t whose attributes match on filter. If filter is the "" empty string return ALL of the objects of this type.
func GetTokenByCredentials ¶
Initiates an Azure JWT token acquisition with provided parameters, using a Client ID plus a Client Secret. This is the 'Confidential' app auth flow and is documented at: https://github.com/AzureAD/microsoft-authentication-library-for-go/blob/dev/apps/confidential/confidential.go
func GetTokenInteractively ¶
Initiates an Azure JWT token acquisition with provided parameters, using a Username and a browser pop up window. This is the 'Public' app auth flow as documented at: https://github.com/AzureAD/microsoft-authentication-library-for-go/blob/dev/apps/public/public.go
func GroupsCountAzure ¶
Returns number of group object entries in Azure tenant
func GroupsCountLocal ¶
Returns number of group object entries in local cache file
func JsonObjectFromDirGroup ¶
Creates a JSON-like map of attributes from a DirGroup.
func MgGroupCountAzure ¶
Returns count of management groups in Azure
func MgGroupCountLocal ¶
Returns count of management group objects in local cache file
func NormalizeCache ¶
func NormalizeCache(baseSet, deltaSet []interface{}) (list []interface{})
Builds JSON mergeSet from deltaSet, and builds and returns the list of deleted IDs
func PrintAdRole ¶
Prints Azure AD role definition object in YAML-like format
func PrintAllDirGroupsTersely ¶
func PrintAllDirGroupsTersely(all DirGroupList)
Prints list of directory groups tersely.
func PrintApiErrMsg ¶
func PrintApiErrMsg(msg string)
Prints API error messages in 2 parts separated by a newline: A header, then a JSON byte slice
func PrintAppRoleAssignmentsOthers ¶
func PrintAppRoleAssignmentsOthers(appRoleAssignments []interface{}, z *Config)
Prints appRoleAssignments for other types of objects (Users and Groups)
func PrintAppRoleAssignmentsSp ¶
Prints appRoleAssignments for given service principal (SP)
func PrintCertificateList ¶
func PrintCertificateList(certificates []interface{})
Prints certificate list stanza for Apps and Sps
func PrintCountStatus ¶
func PrintCountStatus(z *Config)
Prints a status count of all AZ and MG objects that are in Azure, and the local files.
func PrintCountStatusDirGroups ¶
func PrintCountStatusDirGroups(z *Config)
func PrintDirGroup ¶
Print directory group object in YAML-like format
func PrintDirGroupTersely ¶
func PrintDirGroupTersely(g DirGroup)
Prints single directory group tersely, only the Id and DisplayName.
func PrintHeaders ¶
Prints HTTP headers specific to API calls. Simplifies ApiCall function.
func PrintMatching ¶
Prints all objects that match on given specifier
func PrintMemberOfs ¶
func PrintMemberOfs(t string, memberOf []interface{})
Prints all memberOf entries
func PrintMgChildren ¶
func PrintMgChildren(indent int, children []interface{})
Recursively print management groups and all its children MGs and subscriptions
func PrintMgGroup ¶
func PrintMgGroup(x map[string]interface{})
Prints management group object in YAML-like format
func PrintMgTree ¶
func PrintMgTree(z *Config)
Gets current tenant management group tree, and recursively calls function PrintMgChildren() to print the hierarchy
func PrintObject ¶
Generic print object function
func PrintParams ¶
Prints HTTP parameters specific to API calls. Simplifies ApiCall function.
func PrintRoleAssignment ¶
Prints RBAC role definition object in YAML-like format
func PrintRoleAssignmentReport ¶
func PrintRoleAssignmentReport(z *Config)
Prints a human-readable report of all RBAC role assignments
func PrintRoleDefinition ¶
Prints role definition object in a YAML-like format
func PrintSecretList ¶
func PrintSecretList(secretsList []interface{})
Prints secret list stanza for App and SP objects
func PrintStringMapColor ¶
Prints string map in YAML-like format, sorted, and in color
func PrintSubscription ¶
func PrintSubscription(x map[string]interface{})
Prints subscription object in YAML-like format
func PrintTersely ¶
func PrintTersely(t string, object interface{})
Prints this single object of type 't' tersely, with minimal attributes.
func RemoveAppSecret ¶
Removes a secret from the given application
func RemoveDirGroupCacheFile ¶
func RemoveDirGroupCacheFile(z *Config)
Removes directory group local cache files.
func RemoveSpSecret ¶
Removes a secret from the given SP
func RoleAssignmentsCountAzure ¶
Calculates count of all role assignment objects in Azure
func RoleAssignmentsCountLocal ¶
Retrieves count of all role assignment objects in local cache file
func RoleDefinitionCountAzure ¶
Counts all role definition in Azure. Returns 2 lists: one of native custom roles, the other of built-in role
func RoleDefinitionCountLocal ¶
Dedicated role definition local cache counter able to discern if role is custom to native tenant or it's an Azure BuilIn role
func SaveDirGroupsToCache ¶
func SaveDirGroupsToCache(filePath string, groupList DirGroupList) error
Saves a list of DirGroup objects to a binary cache file.
func SelectObject ¶
Selects JSON object with given ID from slice
func SetupApiTokens ¶
func SetupApiTokens(z *Config)
Initializes the necessary global variables, acquires all API tokens, and sets them up for use.
func SetupAutomatedLogin ¶
func SetupAutomatedLogin(z *Config)
Sets up credentials file for client_id + secret login
func SetupCredentials ¶
func SetupCredentials(z *Config)
Gets credentials from OS environment variables (which take precedence), or from the credentials file.
func SetupInterativeLogin ¶
func SetupInterativeLogin(z *Config)
Sets up credentials file for interactive login
func SpsCountAzure ¶
Retrieves counts of all SPs in this Azure tenant, 2 values: Native ones to this tenant, and all others
func SpsCountLocal ¶
Retrieves counts of all SPs in local cache, 2 values: Native ones to this tenant, and all others
func SubsCountAzure ¶
Returns count of all subscriptions in current Azure tenant
func SubsCountLocal ¶
Returns count of all subscriptions in local cache file
func TokenValid ¶
Does a very basic validation of the JWT token as defined in https://tools.ietf.org/html/rfc7519
func UpdateDirGroup ¶
Updates Azure directory group.
func UpsertAzObject ¶
Creates or updates an Azure object based on given specfile
func UpsertAzRoleDefinition ¶
Creates or updates an RBAC role definition as defined by give x object
func UpsertDirGroup ¶
Driver function to Create or Update a directory group. Expects the group object to be printed out before hand, to then optionally prompt for confirmation.
func UpsertDirGroupFromArgs ¶
Upsert (update or create) Azure directory from given command-line arguments.
func UpsertDirGroupFromFile ¶
Upsert (update or create) Azure directory group from given specfile.
func UpsertGroupInCache ¶
Updates or adds a group in the local cache.
func UsersCountAzure ¶
Returns the number of entries in Azure tenant
func UsersCountLocal ¶
Returns the number of entries in local cache file
Types ¶
type Bundle ¶
type Bundle struct { ConfDir string // Directory where utility will store all its file CredsFile string TokenFile string TenantId string ClientId string ClientSecret string Interactive bool Username string AuthorityUrl string MgToken string // This and below to support MS Graph API MgHeaders map[string]string AzToken string // This and below to support Azure Resource Management API AzHeaders map[string]string }
Old configuration Bundle type. To be deprecated.
type Config ¶
type Config struct { ConfDir string CredsFile string TokenFile string TenantId string ClientId string ClientSecret string Interactive bool Username string MgToken string MgHeaders map[string]string AzToken string AzHeaders map[string]string }
Config holds configuration and credentials for various APIs and the calling programs themselves.
func NewConfig ¶
func NewConfig() *Config
Constructs, initializes, and returns a pointer to a Config instance. The returned pointer can be used as a global configuration object to store credentials, tokens, and other API-related details for the application.
func (*Config) AddAzHeader ¶
Adds an Azure Resource Management API header.
func (*Config) AddMgHeader ¶
Adds a Microsoft Graph API header.
func (*Config) SetInteractiveMode ¶
Sets the interactive mode flag.
func (*Config) SetTenantCredentials ¶
Sets the credentials for the tenant.
func (*Config) SetUsername ¶
Sets the username.
type DirGroup ¶
type DirGroup struct { Id string `json:"id"` DisplayName string `json:"displayName"` Description string `json:"description"` IsAssignableToRole bool `json:"isAssignableToRole"` }
Directory group type definition.
func DirGroupFromJson ¶
Creates a DirGroup object from a JSON-like map of attributes.
func FetchExistingDirGroup ¶
Fetches existing directory group, as preprocessing to rename, delete, or update.
func GetGroupFromCache ¶
Retrieves a single group by UUID from the local cache.
func MergeDirGroups ¶
Overwrites or adds the keys from a to b. A simple merge of first-level attributes. Existing b attributes are overwritten.
type DirGroupList ¶
type DirGroupList []*DirGroup
Directory group list type definition.
func GetAzureDirGroups ¶
func GetAzureDirGroups(z *Config, verbose bool) DirGroupList
Gets all groups from Azure and sync to local cache. Shows progress if verbose = true
func GetDirGroupByName ¶
func GetDirGroupByName(displayName string, z *Config) (matchingGroups DirGroupList)
Gets Azure directory group by given displayName. Note that this can potentially return multiple objects, ergo the use of an array for matchingGroups.
func GetMatchingGroups ¶
func GetMatchingGroups(filter string, force bool, z *Config) DirGroupList
Gets all groups matching on 'filter'. Returns entire list if filter is empty ""
func LoadDirGroupsFromCache ¶
func LoadDirGroupsFromCache(filePath string) (DirGroupList, error)
Reads a list of DirGroup objects from a binary cache file.
func NormalizeDirGroupCache ¶
func NormalizeDirGroupCache(currentCache DirGroupList, deltaSet []interface{}) DirGroupList
Normalizes currentCache with the changes in deltaSet and returns it as newCache.
func (*DirGroupList) Add ¶
func (l *DirGroupList) Add(g *DirGroup)
Add Group object to DirGroupList.
func (*DirGroupList) Delete ¶
func (list *DirGroupList) Delete(target interface{}) bool
Deletes a DirGroup from the DirGroupList by matching *DirGroup, Id, or DisplayName.
func (*DirGroupList) Exists ¶
func (list *DirGroupList) Exists(target interface{}) bool
Check if a DirGroup exists in the DirGroupList by matching *DirGroup, Id, or DisplayName.
func (*DirGroupList) Find ¶
func (list *DirGroupList) Find(target interface{}) *DirGroup
Finds a DirGroup in the DirGroupList by matching *DirGroup, Id, or DisplayName.
type Options ¶
type Options struct {
// contains filtered or unexported fields
}
Options map type to facilitate calling functions with many variables.
type TokenCache ¶
type TokenCache struct {
// contains filtered or unexported fields
}
func (*TokenCache) Export ¶
func (t *TokenCache) Export(ctx context.Context, cache cache.Marshaler, hints cache.ExportHints) error
func (*TokenCache) Print ¶
func (t *TokenCache) Print() string
func (*TokenCache) Replace ¶
func (t *TokenCache) Replace(ctx context.Context, cache cache.Unmarshaler, hints cache.ReplaceHints) error