maz

package module
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2023 License: MIT Imports: 12 Imported by: 0

README

maz

Microsoft Azure module for calling Azure resource and MS Graph API. It provides simple MSAL authentication and common object calls.

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 to something like filepath.Join(os.Getenv("HOME"), "." + prgname)
    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 DumpCredentials

func DumpCredentials(z Bundle)

func DumpVariables

func DumpVariables(z Bundle)

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 SetupAutomatedLogin

func SetupAutomatedLogin(z Bundle)

func SetupInterativeLogin

func SetupInterativeLogin(z Bundle)

func StrVal

func StrVal(x interface{}) string

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 // MS Graph API ...
	MgHeaders    map[string]string
	AzToken      string // 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