maz

package module
v0.8.4 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2023 License: MIT Imports: 17 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, jsonObj map[string]interface{}, headers, params map[string]string, verbose bool) (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 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 DumpCredentials

func DumpCredentials(z Bundle)

func DumpVariables

func DumpVariables(z Bundle)

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 GetAzAdRoleById added in v0.8.0

func GetAzAdRoleById(id 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 GetAzAppById added in v0.8.0

func GetAzAppById(id 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 GetAzGroupById added in v0.8.0

func GetAzGroupById(id 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 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 GetAzRoleAssignment added in v0.8.0

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

func GetAzRoleAssignmentById added in v0.8.0

func GetAzRoleAssignmentById(id string, z Bundle) map[string]interface{}

func GetAzRoleAssignments added in v0.8.0

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

func GetAzRoleDefinition added in v0.8.0

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

func GetAzRoleDefinitionById added in v0.8.0

func GetAzRoleDefinitionById(id string, z Bundle) map[string]interface{}

func GetAzRoleDefinitions added in v0.8.0

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

func GetAzSpById added in v0.8.0

func GetAzSpById(id 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 GetAzSubscriptionById added in v0.8.0

func GetAzSubscriptionById(id 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 GetAzUserById added in v0.8.0

func GetAzUserById(id 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 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 GetObjectById added in v0.8.0

func GetObjectById(t, id string, z Bundle) (x map[string]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 GetObjectsWithThisUuid added in v0.8.4

func GetObjectsWithThisUuid(id string, 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 PrintObjectById added in v0.8.4

func PrintObjectById(id 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 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