apimsas

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 30, 2022 License: MIT Imports: 6 Imported by: 0

README

Go.Dev reference go report card Test

This module exposes a Provider struct which can be used to generate SAS tokens for authenticating with Azure's APIM Management API.

Setup

If you haven't already, enable APIM's Management API by navigating to your APIM resource in the Azure Portal and using the pane's navigation bar on the left to find and select "Management API". From there, toggle "Enable Management REST API" to Yes.

Microsoft's documentation for the above steps can be found here.

Once activated, on the same page, locate the "Credentials" section and take note of your Identifier and either your Primary key, or Secondary key. These will be used when instantiating the Provider struct as id and key respectively.

Usage

package main

import (
	"github.com/iambenzo/apimsas"
	"fmt"
)

func main() {

    // Instantiate token provider
	sas := apimsas.NewApimSasProvider("identifier", "primary/secondary key")

    // Generate token
	token, err := sas.GetSasToken()

	if err != nil {
		fmt.Printf("%v\n", err)
	}

    // Show off our generated token
	fmt.Printf("%s\n", token)

    // Make API requests from here...
}

Microsoft's documentation on the API Management REST API can be found here.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Provider

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

Provider is a struct which gives access to SAS generation methods. Will cache last token generated until it expires. Use NewApimSasToken or NewApimSasTokenDuration to correctly instantiate this structure

func NewApimSasProvider

func NewApimSasProvider(id, key string) *Provider

NewApimSasProvider returns a new ApimSasToken with a default lifetime of 2 hours

func NewApimSasProviderDuration

func NewApimSasProviderDuration(id, key string, duration time.Duration) *Provider

NewApimSasProviderDuration returns a new ApimSasToken with a defined lifetime

func (*Provider) GetSasToken

func (p *Provider) GetSasToken() (string, error)

GetSasToken generates a new Sas Token. If a token has been previously generated and it's still valid, then the previous token will be returned

func (*Provider) String

func (p *Provider) String() string

Implements the Stringer interface so that you can:

``` sas := NewApimSasProvider("id", "key") fmt.Printf("%v", sas) ```

Jump to

Keyboard shortcuts

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