magellanic

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2023 License: GPL-3.0 Imports: 17 Imported by: 0

README

Magellanic SDK for Go

The purpose of the Magellanic SDK for Go is to provide a quick and easy way to integrate any Go project with the Magellanic platform. Currently, it supports only Express.js, but there are plans to integrate with other popular frameworks, such as Fastify.

Magellanic Documentation

Learn more here.

Documentation

Index

Constants

View Source
const (
	IdHeaderName   = "magellanic-workload-id"
	AuthHeaderName = "magellanic-authorization"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Claims

type Claims struct {
	WorkloadId string                     `json:"workloadId"`
	Role       string                     `json:"role,omitempty"`
	Resources  map[string]map[string]bool `json:"resources,omitempty"`
	jwt.RegisteredClaims
}

type Client

type Client struct {

	// ID is a unique ID of this workload
	ID string
	// contains filtered or unexported fields
}

Client is used to integrate your application into Magellanic.

Use NewClient or NewClientWithOptions to create an instance

func NewClient

func NewClient() (client *Client, err error)

NewClient creates a new Client instance without options. Use it if you are providing all Magellanic configuration options via environment variables

func NewClientWithOptions

func NewClientWithOptions(options *ClientOptions) (client *Client, err error)

NewClientWithOptions creates a new Client instance with options. Use it if you want to provide all Magellanic configuration options directly

func (*Client) Close

func (c *Client) Close()

Close will terminate the go routines being executed to perform token rotation

func (*Client) DilithiumGenerateKeys

func (c *Client) DilithiumGenerateKeys(mode int) (publicKey string, privateKey string, err error)

DilithiumGenerateKeys generates Dilithium public key/private key pair. Mode must be 2 or 3

func (*Client) DilithiumSign

func (c *Client) DilithiumSign(mode int, privateKey, message string) (signature string, err error)

DilithiumSign creates a signature of provided message using Dilithium

func (*Client) DilithiumVerify

func (c *Client) DilithiumVerify(mode int, publicKey, message, signature string) (verifyResult bool, err error)

DilithiumVerify verifies the signature of the message using Dilithium

func (*Client) GenerateHeaders

func (c *Client) GenerateHeaders() (headers [2][2]string)

GenerateHeaders returns headers to be appended to an outgoing request addressed to another workload.

It returns the array of 2 arrays of 2 strings, where the first string of the nested array is the header name and the second is the value

func (*Client) GetConfig

func (c *Client) GetConfig(configId string, result interface{}) (err error)

GetConfig pulls the specified configuration from Magellanic and unmarshalls it into provided result

func (*Client) GetErrorChannel

func (c *Client) GetErrorChannel() (ch <-chan Error)

GetErrorChannel returns the receive-only channel that will be notified of any occurring errors.

It should always be consumed and handled in a separate goroutine

func (*Client) GetMyToken

func (c *Client) GetMyToken() (token string)

GetMyToken returns the most recent token of this workload

func (*Client) GetTokenClaims

func (c *Client) GetTokenClaims(workloadId, token string) (*Claims, error)

GetTokenClaims validates the token and returns its Claims if the token is valid

func (*Client) KyberDecrypt

func (c *Client) KyberDecrypt(privateKey string, ciphertext string) (secret string, err error)

KyberDecrypt decrypts a secret using ciphertext and private key

func (*Client) KyberEncrypt

func (c *Client) KyberEncrypt(publicKey string) (ciphertext, secret string, err error)

KyberEncrypt generates Kyber secret and ciphertext using provided public key

func (*Client) KyberGenerateKeys

func (c *Client) KyberGenerateKeys() (publicKey, privateKey string, err error)

KyberGenerateKeys generates Kyber public key/private key pair

func (*Client) ValidateGinRequest

func (c *Client) ValidateGinRequest(context *gin.Context) (verifyResult bool)

ValidateGinRequest validates request's token using provided gin context

Returns true if the token is valid or false if not

func (*Client) ValidateGinRequestWithAccess

func (c *Client) ValidateGinRequestWithAccess(context *gin.Context, resource, action string) (verifyResult bool)

ValidateGinRequestWithAccess validates request's token and access to the specified resource using provided gin context

Returns true if the token is valid and the workload has proper permissions or false if token is not valid or workload has no sufficient permissions

func (*Client) ValidateToken

func (c *Client) ValidateToken(workloadId, token string) (verifyResult bool)

ValidateToken validates the token of the specified workload.

Returns true if the token is valid or false if not

func (*Client) ValidateTokenWithAccess

func (c *Client) ValidateTokenWithAccess(workloadId, token, resource, action string) (verifyResult bool)

ValidateTokenWithAccess validates the token and access to the resource of the specified workload.

Returns true if the token is valid and the workload has proper permissions or false if token is not valid or workload has no sufficient permissions

type ClientOptions

type ClientOptions struct {
	ProjectKey string
	Provider   string
	Name       string
	ApiKey     string
	RoleKey    string
}

type Error

type Error struct {
	Message string
}

Error type is used to inform about errors. When an error occurs, it is sent to Client.errorCh

Jump to

Keyboard shortcuts

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