Documentation ¶
Index ¶
- Variables
- func DeviceIDToUUID(deviceID string) (string, error)
- func GenerateAstarteDeviceID(uuidNamespace string, payloadData []byte) (string, error)
- func GenerateAstarteJWTFromKeyFile(privateKeyFile string, servicesAndClaims map[AstarteService][]string, ...) (jwtString string, err error)
- func GenerateAstarteJWTFromPEMKey(privateKeyPEM []byte, servicesAndClaims map[AstarteService][]string, ...) (jwtString string, err error)
- func GenerateRandomAstarteDeviceID() (string, error)
- func GetNamespacedAstarteDeviceID(uuidNamespace string, payloadData []byte) (string, error)deprecated
- func IsJWTAstarteClaimValidForService(token string, service AstarteService) (bool, error)
- func IsValidAstarteDeviceID(deviceID string) bool
- func ParsePrivateKeyFromPEM(key []byte) (interface{}, error)
- func UUIDToDeviceID(deviceUUIDString string) (string, error)
- type AstarteClaims
- type AstarteService
Constants ¶
This section is empty.
Variables ¶
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 ¶
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
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 ¶
GenerateRandomAstarteDeviceID returns a new Astarte Device ID on a fully Random basis. Do not use in production environments.
func GetNamespacedAstarteDeviceID
deprecated
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 ¶
IsValidAstarteDeviceID returns whether the provided Device ID is a valid Astarte Device ID or not.
func ParsePrivateKeyFromPEM ¶
ParsePrivateKeyFromPEM parses a PEM encoded private key
func UUIDToDeviceID ¶
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