maz

package module
v0.8.8 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2023 License: MIT Imports: 19 Imported by: 0

README

maz

Microsoft Azure module for simple MSAL authentication, and calling MS Graph and Azure resource APIs. Other APIs could be added in the future.

WARNING: Currently under constant changes.

Getting Started

  1. Any program or utility wanting to use this module can simply import it, then instantiate a variable of type maz.Bundle to manage the interaction. For example:
import (
    "github.com/git719/maz"
)
z := maz.Bundle{
    ConfDir:      "",                   // You set later, see example below
    CredsFile:    "credentials.yaml",
    TokenFile:    "accessTokens.json",
    TenantId:     "",
    ClientId:     "",
    ClientSecret: "",
    Interactive:  false,
    Username:     "",
    AuthorityUrl: "",                   // You set later to maz.ConstAuthUrl + z.TenantId
    MgToken:      "",                   // you set below 4 with function maz.SetupApiTokens()
    MgHeaders:    map[string]string{},
    AzToken:      "",
    AzHeaders:    map[string]string{},  
}
// Then update the variables within the Bundle, to set up configuration directory
z.ConfDir = filepath.Join(os.Getenv("HOME"), "." + prgname)
if utl.FileNotExist(z.ConfDir) {
    if err := os.Mkdir(z.ConfDir, 0700); err != nil {
        panic(err.Error())
    }
}
  1. Then call maz.SetupInterativeLogin(z) or maz.SetupAutomatedLogin(z) to setup the credentials file accordingly.
  2. Then call z := maz.SetupApiTokens(*z) to acquire the respective API tokens, web headers, and other variables.
  3. Now pass and use the z variables, with its z.mgHeaders and/or z.azHeaders attributes, to call your own REST API functions to do whatever you want.

Functions

A breakdown of available functions.

maz.SetupInterativeLogin

This functions allows you to set up interactive Azure login. ...

Documentation

Index

Constants

View Source
const (
	ConstAuthUrl              = "https://login.microsoftonline.com/"
	ConstMgUrl                = "https://graph.microsoft.com"
	ConstAzUrl                = "https://management.azure.com"
	ConstAzPowerShellClientId = "1950a258-227b-4e31-a9cf-717495945fc2"
)

Variables

This section is empty.

Functions

func AdRolesCountAzure added in v0.8.0

func AdRolesCountAzure(z Bundle) int64

func AdRolesCountLocal added in v0.8.0

func AdRolesCountLocal(z Bundle) int64

func ApiCall added in v0.8.0

func ApiCall(method, url string, payload map[string]interface{}, headers, params map[string]string, verbose bool) (result map[string]interface{})

func ApiDelete added in v0.8.8

func ApiDelete(url string, headers, params map[string]string) (result map[string]interface{})

func ApiDeleteDebug added in v0.8.8

func ApiDeleteDebug(url string, headers, params map[string]string) (result map[string]interface{})

func ApiErrorCheck added in v0.8.0

func ApiErrorCheck(r map[string]interface{}, caller string)

func ApiGet added in v0.8.0

func ApiGet(url string, headers, params map[string]string) (result map[string]interface{})

func ApiGetDebug added in v0.8.0

func ApiGetDebug(url string, headers, params map[string]string) (result map[string]interface{})

func ApiPut added in v0.8.8

func ApiPut(url string, payload map[string]interface{}, headers, params map[string]string) (result map[string]interface{})

func ApiPutDebug added in v0.8.8

func ApiPutDebug(url string, payload map[string]interface{}, headers, params map[string]string) (result map[string]interface{})

func AppsCountAzure added in v0.8.0

func AppsCountAzure(z Bundle) int64

func AppsCountLocal added in v0.8.0

func AppsCountLocal(z Bundle) int64

func CheckLocalCache added in v0.8.0

func CheckLocalCache(cacheFile string, cachePeriod int64) (usable bool, cachedList []interface{})

func CompareSpecfileToAzure added in v0.8.0

func CompareSpecfileToAzure(filePath string, z Bundle)

func CreateAzRoleAssignment added in v0.8.8

func CreateAzRoleAssignment(x map[string]interface{}, z Bundle)

func CreateSkeletonFile added in v0.8.7

func CreateSkeletonFile(t string)

func DeleteAzObject added in v0.8.8

func DeleteAzObject(specifier string, z Bundle)

func DeleteAzObjectPrompt added in v0.8.8

func DeleteAzObjectPrompt(t string, fqid string, z Bundle)

func DeleteAzRoleAssignmentByFqid added in v0.8.8

func DeleteAzRoleAssignmentByFqid(fqid string, z Bundle) map[string]interface{}

func DeleteAzRoleDefinitionByFqid added in v0.8.8

func DeleteAzRoleDefinitionByFqid(fqid string, z Bundle) map[string]interface{}

func DumpCredentials

func DumpCredentials(z Bundle)

func DumpVariables

func DumpVariables(z Bundle)

func FindAzObjectsByUuid added in v0.8.8

func FindAzObjectsByUuid(uuid string, z Bundle) (list []interface{})

func GetAdRoles added in v0.8.0

func GetAdRoles(filter string, force bool, z Bundle) (list []interface{})

func GetApps added in v0.8.0

func GetApps(filter string, force bool, z Bundle) (list []interface{})

func GetAzAdRoleByUuid added in v0.8.8

func GetAzAdRoleByUuid(uuid string, headers map[string]string) map[string]interface{}

func GetAzAdRoles added in v0.8.0

func GetAzAdRoles(cacheFile string, headers map[string]string, verbose bool) (list []interface{})

func GetAzAppByUuid added in v0.8.8

func GetAzAppByUuid(uuid string, headers map[string]string) map[string]interface{}

func GetAzApps added in v0.8.0

func GetAzApps(cacheFile string, headers map[string]string, verbose bool) (list []interface{})

func GetAzGroupByUuid added in v0.8.8

func GetAzGroupByUuid(uuid string, headers map[string]string) map[string]interface{}

func GetAzGroups added in v0.8.0

func GetAzGroups(cacheFile string, headers map[string]string, verbose bool) (list []interface{})

func GetAzMgGroups added in v0.8.0

func GetAzMgGroups(z Bundle) (list []interface{})

func GetAzObjectByUuid added in v0.8.8

func GetAzObjectByUuid(t, uuid string, z Bundle) (x map[string]interface{})

func GetAzObjects added in v0.8.0

func GetAzObjects(url string, headers map[string]string, verbose bool) (deltaSet []interface{}, deltaLinkMap map[string]string)

func GetAzRbacScopes added in v0.8.0

func GetAzRbacScopes(z Bundle) (scopes []string)

func GetAzRoleAssignmentByObject added in v0.8.8

func GetAzRoleAssignmentByObject(x map[string]interface{}, z Bundle) (y map[string]interface{})

func GetAzRoleAssignmentByUuid added in v0.8.8

func GetAzRoleAssignmentByUuid(uuid string, z Bundle) (x map[string]interface{})

func GetAzRoleAssignments added in v0.8.0

func GetAzRoleAssignments(verbose bool, z Bundle) (list []interface{})

func GetAzRoleDefinitionByName added in v0.8.8

func GetAzRoleDefinitionByName(specifier string, z Bundle) (y map[string]interface{})

func GetAzRoleDefinitionByObject added in v0.8.8

func GetAzRoleDefinitionByObject(x map[string]interface{}, z Bundle) (y map[string]interface{})

func GetAzRoleDefinitionByUuid added in v0.8.8

func GetAzRoleDefinitionByUuid(uuid string, z Bundle) (x map[string]interface{})

func GetAzRoleDefinitions added in v0.8.0

func GetAzRoleDefinitions(verbose bool, z Bundle) (list []interface{})

func GetAzSpByUuid added in v0.8.8

func GetAzSpByUuid(uuid string, headers map[string]string) map[string]interface{}

func GetAzSps added in v0.8.0

func GetAzSps(cacheFile string, headers map[string]string, verbose bool) (list []interface{})

func GetAzSubscriptionByUuid added in v0.8.8

func GetAzSubscriptionByUuid(uuid string, headers map[string]string) map[string]interface{}

func GetAzSubscriptions added in v0.8.0

func GetAzSubscriptions(z Bundle) (list []interface{})

func GetAzSubscriptionsIds added in v0.8.0

func GetAzSubscriptionsIds(z Bundle) (scopes []string)

func GetAzUserByUuid added in v0.8.8

func GetAzUserByUuid(uuid string, headers map[string]string) map[string]interface{}

func GetAzUsers added in v0.8.0

func GetAzUsers(cacheFile string, headers map[string]string, verbose bool) (list []interface{})

func GetGroups added in v0.8.0

func GetGroups(filter string, force bool, z Bundle) (list []interface{})

func GetIdMapApps added in v0.8.0

func GetIdMapApps(z Bundle) (nameMap map[string]string)

func GetIdMapGroups added in v0.8.0

func GetIdMapGroups(z Bundle) (nameMap map[string]string)

func GetIdMapMgGroups added in v0.8.8

func GetIdMapMgGroups(z Bundle) (nameMap map[string]string)

func GetIdMapRoleDefs added in v0.8.0

func GetIdMapRoleDefs(z Bundle) (nameMap map[string]string)

func GetIdMapSps added in v0.8.0

func GetIdMapSps(z Bundle) (nameMap map[string]string)

func GetIdMapSubs added in v0.8.0

func GetIdMapSubs(z Bundle) (nameMap map[string]string)

func GetIdMapUsers added in v0.8.0

func GetIdMapUsers(z Bundle) (nameMap map[string]string)

func GetMgGroups added in v0.8.0

func GetMgGroups(filter string, force bool, z Bundle) (list []interface{})

func GetObjectFromFile added in v0.8.0

func GetObjectFromFile(filePath string) (formatType, t string, obj map[string]interface{})

func GetObjects added in v0.8.0

func GetObjects(t, filter string, force bool, z Bundle) (list []interface{})

func GetRoleAssignments added in v0.8.0

func GetRoleAssignments(filter string, force bool, z Bundle) (list []interface{})

func GetRoleDefinitions added in v0.8.0

func GetRoleDefinitions(filter string, force bool, z Bundle) (list []interface{})

func GetSps added in v0.8.0

func GetSps(filter string, force bool, z Bundle) (list []interface{})

func GetSubscriptions added in v0.8.0

func GetSubscriptions(filter string, force bool, z Bundle) (list []interface{})

func GetTokenByCredentials

func GetTokenByCredentials(scopes []string, confDir, tokenFile, authorityUrl, clientId, clientSecret string) (token string, err error)

func GetTokenInteractively

func GetTokenInteractively(scopes []string, confDir, tokenFile, authorityUrl, username string) (token string, err error)

func GetUsers added in v0.8.0

func GetUsers(filter string, force bool, z Bundle) (list []interface{})

func GroupsCountAzure added in v0.8.0

func GroupsCountAzure(z Bundle) int64

func GroupsCountLocal added in v0.8.0

func GroupsCountLocal(z Bundle) int64

func MgGroupCountAzure added in v0.8.0

func MgGroupCountAzure(z Bundle) int64

func MgGroupCountLocal added in v0.8.0

func MgGroupCountLocal(z Bundle) int64

func MgType added in v0.8.0

func MgType(typeIn string) string

func NormalizeCache added in v0.8.0

func NormalizeCache(baseSet, deltaSet []interface{}) (list []interface{})

func PrintAdRole added in v0.8.0

func PrintAdRole(x map[string]interface{}, z Bundle)

func PrintApp added in v0.8.0

func PrintApp(x map[string]interface{}, z Bundle)

func PrintCountStatus added in v0.8.0

func PrintCountStatus(z Bundle)

func PrintGroup added in v0.8.0

func PrintGroup(x map[string]interface{}, z Bundle)

func PrintMemberOfs added in v0.8.0

func PrintMemberOfs(t string, memberOf []interface{})

func PrintMgChildren added in v0.8.0

func PrintMgChildren(indent int, children []interface{})

func PrintMgGroup added in v0.8.0

func PrintMgGroup(x map[string]interface{})

func PrintMgTree added in v0.8.0

func PrintMgTree(z Bundle)

func PrintObject added in v0.8.0

func PrintObject(t string, x map[string]interface{}, z Bundle)

func PrintObjectByUuid added in v0.8.8

func PrintObjectByUuid(uuid string, z Bundle)

func PrintPags added in v0.8.0

func PrintPags(z Bundle)

func PrintRoleAssignment added in v0.8.0

func PrintRoleAssignment(x map[string]interface{}, z Bundle)

func PrintRoleAssignmentReport added in v0.8.0

func PrintRoleAssignmentReport(z Bundle)

func PrintRoleDefinition added in v0.8.0

func PrintRoleDefinition(x map[string]interface{}, z Bundle)

func PrintSp added in v0.8.0

func PrintSp(x map[string]interface{}, z Bundle)

func PrintSubscription added in v0.8.0

func PrintSubscription(x map[string]interface{})

func PrintTersely added in v0.8.0

func PrintTersely(t string, object interface{})

func PrintUser added in v0.8.0

func PrintUser(x map[string]interface{}, z Bundle)

func RemoveCacheFile added in v0.8.0

func RemoveCacheFile(t string, z Bundle)

func RoleAssignmentsCountAzure added in v0.8.0

func RoleAssignmentsCountAzure(z Bundle) int64

func RoleAssignmentsCountLocal added in v0.8.0

func RoleAssignmentsCountLocal(z Bundle) int64

func RoleDefinitionCountAzure added in v0.8.0

func RoleDefinitionCountAzure(z Bundle) (builtin, custom int64)

func RoleDefinitionCountLocal added in v0.8.0

func RoleDefinitionCountLocal(z Bundle) (builtin, custom int64)

func SelectObject added in v0.8.0

func SelectObject(id string, objSet []interface{}) (x map[string]interface{})

func SetupAutomatedLogin

func SetupAutomatedLogin(z Bundle)

func SetupInterativeLogin

func SetupInterativeLogin(z Bundle)

func SpsCountAzure added in v0.8.0

func SpsCountAzure(z Bundle) (native, microsoft int64)

func SpsCountLocal added in v0.8.0

func SpsCountLocal(z Bundle) (native, microsoft int64)

func SubsCountAzure added in v0.8.0

func SubsCountAzure(z Bundle) int64

func SubsCountLocal added in v0.8.0

func SubsCountLocal(z Bundle) int64

func UpsertAzObject added in v0.8.8

func UpsertAzObject(filePath string, z Bundle)

func UpsertAzRoleDefinition added in v0.8.8

func UpsertAzRoleDefinition(x map[string]interface{}, z Bundle)

func UsersCountAzure added in v0.8.0

func UsersCountAzure(z Bundle) int64

func UsersCountLocal added in v0.8.0

func UsersCountLocal(z Bundle) int64

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
}

func SetupApiTokens

func SetupApiTokens(z *Bundle) Bundle

func SetupCredentials

func SetupCredentials(z *Bundle) Bundle

type TokenCache

type TokenCache struct {
	// contains filtered or unexported fields
}

func (*TokenCache) Export

func (t *TokenCache) Export(cache cache.Marshaler, key string)

func (*TokenCache) Replace

func (t *TokenCache) Replace(cache cache.Unmarshaler, key string)

Jump to

Keyboard shortcuts

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