Documentation ¶
Index ¶
- Constants
- Variables
- func BearerTokenHeaderValue(token string) string
- func ClientBundleDecodeBase64Value(val io.Reader) (string, error)
- func ClientBundleRetrieveValue(val io.Reader) (string, error)
- func GeneratePass() string
- func NewLoginResponse(token string) loginResponse
- type AccountFilter
- type AccountPublicKey
- type Auth
- type Certificate
- type Client
- func (c *Client) ApiAuthorizedGeneric(ctx context.Context, req *http.Request) (*Response, error)
- func (c *Client) ApiClientBundleCreate(ctx context.Context, label string) (ClientBundle, error)
- func (c *Client) ApiClientBundleDelete(ctx context.Context, cb ClientBundle) error
- func (c *Client) ApiClientBundleGetPublicKey(ctx context.Context, cb ClientBundle) (AccountPublicKey, error)
- func (c *Client) ApiCreateAccount(ctx context.Context, acc CreateAccount) (ResponseAccount, error)
- func (c *Client) ApiDeleteAccount(ctx context.Context, id string) error
- func (c *Client) ApiGeneric(ctx context.Context, req *http.Request) (*Response, error)
- func (c *Client) ApiLogin(ctx context.Context) error
- func (c *Client) ApiPing(ctx context.Context) error
- func (c *Client) ApiPublicKeyDelete(ctx context.Context, account, keyid string) error
- func (c *Client) ApiPublicKeyList(ctx context.Context, account string) ([]AccountPublicKey, error)
- func (c *Client) ApiPublicKeyRetrieve(ctx context.Context, account, keyid string) (AccountPublicKey, error)
- func (c *Client) ApiReadAccount(ctx context.Context, id string) (ResponseAccount, error)
- func (c *Client) ApiReadAccounts(ctx context.Context, accFilter AccountFilter) ([]ResponseAccount, error)
- func (c *Client) ApiUpdateAccount(ctx context.Context, id string, acc UpdateAccount) (ResponseAccount, error)
- func (c *Client) RequestFromTargetAndBytesBody(ctx context.Context, method, target string, body []byte) (*http.Request, error)
- func (c *Client) RequestFromTargetAndJSONBody(ctx context.Context, method, target string, body interface{}) (*http.Request, error)
- func (c *Client) Username() string
- type ClientBundle
- type ClientBundleKube
- type ClientBundleMeta
- type CreateAccount
- type GetKeysResponse
- type Response
- type ResponseAccount
- type ResponseAccounts
- type UpdateAccount
Constants ¶
const ( URLTargetForClientBundle = "api/clientbundle" URLTargetForClientBundleQueryLabel = "label" )
const ( // /accounts/{accountNameOrID}/publicKeys url. URLTargetPatternForPublicKeys = "accounts/%s/publicKeys" // /accounts/{accountNameOrID}/publicKeys/{keyID} url. URLTargetPatternForPublicKey = "accounts/%s/publicKeys/%s" )
const ( ClientBundleMetaEndpointDocker = "docker" ClientBundleMetaEndpointKubernetes = "kubernetes" )
const (
EndpointDefaultScheme = "https"
)
const (
HeaderKeyAuthorization = "Authorization"
)
const (
URLTargetForAuth = "auth/login"
)
const (
URLTargetForPing = "_ping"
)
Variables ¶
var ( ErrFailedToRetrieveClientBundle = errors.New("failed to retrieve the client bundle from MKE") ErrFailedToFindClientBundleMKEPublicKey = errors.New("no MKE Public key was found that matches the client bundle") )
var ( ErrEmptyUsernamePass = errors.New("no username or password provided in MKE client") ErrEmptyEndpoint = errors.New("no endpoint provided in MKE client") ErrRequestCreation = errors.New("error creating request in MKE client") ErrMarshaling = errors.New("error occurred while marshalling struct in MKE client") ErrUnmarshaling = errors.New("error occurred while unmarshalling struct in MKE client") ErrEmptyResError = errors.New("request returned empty ResponseError struct in MKE client") ErrResponseError = errors.New("request returned ResponseError in MKE client") ErrUnknownTarget = errors.New("unknown API target") ErrServerError = errors.New("server error occurred") ErrEmptyStruct = errors.New("empty struct passed in MKE client") ErrInvalidFilter = errors.New("passing invalid account retrieval filter in MKE client") )
var (
ErrCouldNotCreateClient = errors.New("could not create a client")
)
Functions ¶
func BearerTokenHeaderValue ¶
BearerTokenHeaderValue convert an auth token into the auth header value.
func ClientBundleDecodeBase64Value ¶
ClientBundleDecodeBase64Value read a value and base64 decode it.
func ClientBundleRetrieveValue ¶
ClientBundleRetrieveValue read a value.
func GeneratePass ¶ added in v0.2.1
func GeneratePass() string
GeneratePass creates a random password.
func NewLoginResponse ¶
func NewLoginResponse(token string) loginResponse
NewLoginResponse create a login response.
Types ¶
type AccountFilter ¶ added in v0.2.1
type AccountFilter string
Account filters enum.
const ( AccountFilterUsers AccountFilter = "user" AccountFilterOrgs AccountFilter = "orgs" AccountFilterAdmins AccountFilter = "admins" AccountFilterNonAdmins AccountFilter = "non-admins" AccountFilterActiveUsers AccountFilter = "active-users" AccountFilterInactiveUsers AccountFilter = "inactive-users" URLTargetForAccounts = "accounts" )
func (AccountFilter) APIFormOfFilter ¶ added in v0.2.1
func (accF AccountFilter) APIFormOfFilter() string
APIFormOfFilter is a string readable form of the AccountFilters enum.
type AccountPublicKey ¶
type AccountPublicKey struct { ID string `json:"id" description:"the hash of the public key's DER bytes"` AccountID string `json:"accountID" description:"the ID of the account"` PublicKey string `json:"publicKey" description:"the encoded PEM of the public key"` Label string `json:"label" description:"the label or description for the key"` Certificates []Certificate `json:"certificates,omitempty" description:"certificates for the public key"` }
AccountPublicKey api interpretation of a public key @see https://github.com/Mirantis/orca/blob/c999ce63c591beba851926500c3d66f9af3cb244/enzi/api/responses/responses.go#L1058
type Auth ¶
type Auth struct { Code string `json:"code"` Password string `json:"password"` Token string `json:"token"` UseTLS bool `json:"useTLS"` Username string `json:"username"` }
Auth container for data related to authentication. @see MKE Auth struct for auth/login.
type Certificate ¶
type Certificate struct { Label string `json:"label" description:"Label for the certificate"` Cert string `json:"cert" description:"Encoded PEM for the cert"` }
Certificate is a sub-form for the account certificate. @see https://github.com/Mirantis/orca/blob/master/enzi/api/responses/responses.go#L1103
type Client ¶
Client MKE client.
func NewClientSimple ¶
NewClient from a string URL and u/p.
func NewUnsafeSSLClient ¶
NewUnsafeSSLClient that allows self-signed SSL from a string URL and u/p.
func (*Client) ApiAuthorizedGeneric ¶
ApiAuthorizedGeneric send a authenticated generic http request to the MKE API.
func (*Client) ApiClientBundleCreate ¶
ApiClientBundle retrieve a client bundle.
func (*Client) ApiClientBundleDelete ¶
func (c *Client) ApiClientBundleDelete(ctx context.Context, cb ClientBundle) error
ApiClientBundleDelete delete a client bundle by finding and deleting the matching public key. There isn't really a great way of doing this.
func (*Client) ApiClientBundleGetPublicKey ¶
func (c *Client) ApiClientBundleGetPublicKey(ctx context.Context, cb ClientBundle) (AccountPublicKey, error)
ApiClientBundleGetPublicKey retrieve a client bundle by finding the matching public key. There isn't really a great way of doing this.
func (*Client) ApiCreateAccount ¶ added in v0.2.1
func (c *Client) ApiCreateAccount(ctx context.Context, acc CreateAccount) (ResponseAccount, error)
CreateAccount method - checking the MKE health endpoint.
func (*Client) ApiDeleteAccount ¶ added in v0.2.1
DeleteAccount deletes a user from in Enzi.
func (*Client) ApiGeneric ¶
ApiGeneric send a generic http request to the MKE API.
func (*Client) ApiPing ¶
ApiPing Ping the endpoint @note MKE allows node specific pings, and a loadbalancer ping will
just connect to any node. This makes this precarious for cluster health.
func (*Client) ApiPublicKeyDelete ¶
ApiPublicKeyDelete delete a specific account key.
func (*Client) ApiPublicKeyList ¶
ApiPublicKeyList list all of the public keys.
func (*Client) ApiPublicKeyRetrieve ¶
func (c *Client) ApiPublicKeyRetrieve(ctx context.Context, account, keyid string) (AccountPublicKey, error)
ApiPublicKeyRetrieve retrieve a specific account key.
func (*Client) ApiReadAccount ¶ added in v0.2.1
ReadAccount method retrieves a user from the enzi endpoint.
func (*Client) ApiReadAccounts ¶ added in v0.2.1
func (c *Client) ApiReadAccounts(ctx context.Context, accFilter AccountFilter) ([]ResponseAccount, error)
ReadAccounts method retrieves all accounts depending on the filter passed from the enzi endpoint.
func (*Client) ApiUpdateAccount ¶ added in v0.2.1
func (c *Client) ApiUpdateAccount(ctx context.Context, id string, acc UpdateAccount) (ResponseAccount, error)
UpdateAccount updates a user in the enzi endpoint.
func (*Client) RequestFromTargetAndBytesBody ¶
func (c *Client) RequestFromTargetAndBytesBody(ctx context.Context, method, target string, body []byte) (*http.Request, error)
RequestFromTarget build simple http.Request from relative API target and bytes array for a body.
type ClientBundle ¶
type ClientBundle struct { ID string `json:"id"` PrivateKey string `json:"private_key"` PublicKey string `json:"public_key"` Cert string `json:"cert"` CACert string `json:"ca_cert"` Kube *ClientBundleKube `json:"kube"` // There is not always a kube config Meta ClientBundleMeta `json:"meta"` }
ClientBundle interpretation of the ClientBundle data in memory.
func (ClientBundle) ToJSON ¶
func (cb ClientBundle) ToJSON() []byte
ToJSON stringify client bundle as json for debugging.
type ClientBundleKube ¶
type ClientBundleKube struct { Config string `json:"config"` Host string `json:"host"` ClientKey string `json:"client_key"` ClientCertificate string `json:"client_certificate"` CACertificate string `json:"cluster_ca_certificate"` Insecure string `json:"insecure"` }
ClientBundleKube Kubernetes parts of the client bundle. primarily we are focused on satisfying requirements for a kubernetes provider. such as https://github.com/hashicorp/terraform-provider-kubernetes/blob/main/kubernetes/provider.go
func NewClientBundleKubeFromKubeYml ¶
func NewClientBundleKubeFromKubeYml(val io.Reader) (ClientBundleKube, error)
NewClientBundleKubeFromKubeYml ClientBundleKube constructor from byte list of a kubeconfig file.
type ClientBundleMeta ¶
type ClientBundleMeta struct { Name string `json:"Name"` Description string `json:"Description"` StackOrchestrator string `json:"StackOrchestrator"` DockerHost string `json:"DockerHost"` DockerSkipVerifyTLS bool `json:"DockerSkipVerifyTLS"` KubernetesHost string `json:"KubernetesHost"` KubernetesSkipVerifyTLS bool `json:"KubernetesSkipVerifyTLS"` }
ClientBundleMeta in the client bundle is a flattenned meta.json file. It is buried kind of deep.
func NewClientBundleMetaFromReader ¶
func NewClientBundleMetaFromReader(val io.Reader) (ClientBundleMeta, error)
NewClientBundleMetaFromReader interpret the meta.json file reader as a Meta struct
type CreateAccount ¶ added in v0.2.1
type CreateAccount struct { Name string `json:"name"` ID string `json:"id"` Password string `json:"password"` FullName string `json:"fullName,omitempty"` IsActive bool `json:"isActive,omitempty"` IsAdmin bool `json:"isAdmin,omitempty"` IsOrg bool `json:"isOrg,omitempty"` SearchLDAP bool `json:"searchLDAP,omitempty"` }
CreateAccount struct.
type GetKeysResponse ¶
type GetKeysResponse struct { AccountPubKeys []AccountPublicKey `json:"accountPublicKeys"` NextPageStart string `json:"nextPageStart"` }
type Response ¶
Response http.Response wrapper that can interpret the body more.
func (*Response) JSONMarshallBody ¶
JSONMarshallBody unmarshall http.Response body as json to passed target.
type ResponseAccount ¶ added in v0.2.1
type ResponseAccount struct { Name string `json:"name"` ID string `json:"id"` FullName string `json:"fullName,omitempty"` IsActive bool `json:"isActive"` IsAdmin bool `json:"isAdmin"` IsOrg bool `json:"isOrg"` IsImported bool `json:"isImported"` OnDemand bool `json:"onDemand"` OtpEnabled bool `json:"otpEnabled"` MembersCount int `json:"membersCount"` TeamsCount int `json:"teamsCount"` }
ResponseAccount struct.
type ResponseAccounts ¶ added in v0.2.1
type ResponseAccounts struct { UsersCount int `json:"usersCount"` OrgsCount int `json:"orgsCount"` ResourceCount int `json:"resourceCount"` NextPageStart string `json:"nextPageStart"` Accounts []ResponseAccount `json:"accounts"` }
ResponseAccounts struct.
type UpdateAccount ¶ added in v0.2.1
type UpdateAccount struct { FullName string `json:"fullName,omitempty"` IsActive bool `json:"isActive,omitempty"` IsAdmin bool `json:"isAdmin,omitempty"` }
UpdateAccount struct.