misc

package
v0.90.4 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrKeyMustBePEMEncoded is returned when the key is not encoded in PEM format
	ErrKeyMustBePEMEncoded = errors.New("Invalid Key: Key must be PEM encoded private key")
	// ErrNotPrivateKey is returned when the private key is not valid
	ErrNotPrivateKey = errors.New("Key is not a valid private key")
	// ErrUnsupportedPrivateKey is returned when the chosen private key is not supported for JWT generation
	ErrUnsupportedPrivateKey = errors.New("Key is not supported for JWT generation")
)

Functions

func DeviceIDToUUID

func DeviceIDToUUID(deviceID string) (string, error)

DeviceIDToUUID converts a Device ID from the standard Astarte representation (Base 64 Url Encoded) to UUID string representation. This is useful to interact directly with Cassandra, that uses that representation to store Device IDs.

func GenerateAstarteDeviceID added in v0.90.4

func GenerateAstarteDeviceID(uuidNamespace string, payloadData []byte) (string, error)

GenerateAstarteDeviceID returns an Astarte Device ID generated from a namespaced arbitrary payload. It is guaranteed to be always the same for the same namespace and payload. This is the go-to function to generate Astarte device IDs.

func GenerateAstarteJWTFromKeyFile

func GenerateAstarteJWTFromKeyFile(privateKeyFile string, servicesAndClaims map[AstarteService][]string,
	ttlSeconds int64) (jwtString string, err error)

GenerateAstarteJWTFromKeyFile generates an Astarte Token for a specific API out of a Private Key File. servicesAndClaims specifies which services with which claims the token will be authorized to access. Leaving a claim empty will imply `.*::.*`, aka access to the entirety of the service's API tree

func GenerateAstarteJWTFromPEMKey

func GenerateAstarteJWTFromPEMKey(privateKeyPEM []byte, servicesAndClaims map[AstarteService][]string,
	ttlSeconds int64) (jwtString string, err error)

GenerateAstarteJWTFromPEMKey generates an Astarte Token for a specific API out of a Private Key PEM bytearray. servicesAndClaims specifies which services with which claims the token will be authorized to access. Leaving a claim empty will imply `.*::.*`, aka access to the entirety of the service's API tree

func GenerateRandomAstarteDeviceID

func GenerateRandomAstarteDeviceID() (string, error)

GenerateRandomAstarteDeviceID returns a new Astarte Device ID on a fully Random basis. Do not use in production environments.

func GetNamespacedAstarteDeviceID deprecated

func GetNamespacedAstarteDeviceID(uuidNamespace string, payloadData []byte) (string, error)

Deprecated: This function will be removed in next releases. Use `GenerateAstarteDeviceID`. GetNamespacedAstarteDeviceID returns an Astarte Device ID generated from a namespaced arbitrary payload. It is guaranteed to be always the same for the same namespace and payload

func IsJWTAstarteClaimValidForService added in v0.90.4

func IsJWTAstarteClaimValidForService(token string, service AstarteService) (bool, error)

IsJWTAstarteClaimValidForService verifies that an Astarte Token has access to a given Astarte service.

func IsValidAstarteDeviceID

func IsValidAstarteDeviceID(deviceID string) bool

IsValidAstarteDeviceID returns whether the provided Device ID is a valid Astarte Device ID or not.

func ParsePrivateKeyFromPEM

func ParsePrivateKeyFromPEM(key []byte) (interface{}, error)

ParsePrivateKeyFromPEM parses a PEM encoded private key

func UUIDToDeviceID

func UUIDToDeviceID(deviceUUIDString string) (string, error)

UUIDToDeviceID converts a UUID string to a Device ID in the standard Astarte representation (Base 64 Url Encoded)

Types

type AstarteClaims added in v0.90.4

type AstarteClaims struct {
	jwt.StandardClaims

	AppEngineAPI    []string `json:"a_aea,omitempty"`
	Channels        []string `json:"a_ch,omitempty"`
	Flow            []string `json:"a_f,omitempty"`
	Housekeeping    []string `json:"a_ha,omitempty"`
	RealmManagement []string `json:"a_rma,omitempty"`
	Pairing         []string `json:"a_pa,omitempty"`
}

func GetJWTAstarteClaims added in v0.90.4

func GetJWTAstarteClaims(rawToken string) (AstarteClaims, error)

GetJWTAstarteClaims returns the set of Astarte claims for an Astarte Token.

func (*AstarteClaims) MarshalBinary added in v0.90.4

func (u *AstarteClaims) MarshalBinary() ([]byte, error)

type AstarteService

type AstarteService int

AstarteService represents one of Astarte's Services

const (
	// Unknown Astarte Service
	Unknown AstarteService = 0
	// Housekeeping is Astarte's service for managing Realms
	Housekeeping AstarteService = 1
	// RealmManagement is Astarte's service for managing configuration of a Realm
	RealmManagement AstarteService = 2
	// Pairing is Astarte's service for managing device provisioning and access
	Pairing AstarteService = 3
	// AppEngine is Astarte's service for interacting with Devices, Groups and more
	AppEngine AstarteService = 4
	// Channels is Astarte's service for WebSockets
	Channels AstarteService = 5
	// Flow is Astarte Flow
	Flow AstarteService = 6
)

func AstarteServiceFromString

func AstarteServiceFromString(astarteServiceString string) (AstarteService, error)

AstarteServiceFromString returns a valid AstarteService out of a string

func (AstarteService) String

func (astarteService AstarteService) String() string

Jump to

Keyboard shortcuts

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