client

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2023 License: MPL-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	URLTargetForClientBundle           = "api/clientbundle"
	URLTargetForClientBundleQueryLabel = "label"
)
View Source
const (
	// /accounts/{accountNameOrID}/publicKeys url.
	URLTargetPatternForPublicKeys = "accounts/%s/publicKeys"
	// /accounts/{accountNameOrID}/publicKeys/{keyID} url.
	URLTargetPatternForPublicKey = "accounts/%s/publicKeys/%s"
)
View Source
const (
	ClientBundleMetaEndpointDocker     = "docker"
	ClientBundleMetaEndpointKubernetes = "kubernetes"
)
View Source
const (
	EndpointDefaultScheme = "https"
)
View Source
const (
	HeaderKeyAuthorization = "Authorization"
)
View Source
const (
	URLTargetForAuth = "auth/login"
)
View Source
const (
	URLTargetForPing = "_ping"
)

Variables

View Source
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")
)
View Source
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")
	ErrUnauthorizedReq   = errors.New("unauthorized request 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")
)
View Source
var (
	ErrCouldNotCreateClient = errors.New("could not create a client")
)

Functions

func BearerTokenHeaderValue

func BearerTokenHeaderValue(token string) string

BearerTokenHeaderValue convert an auth token into the auth header value.

func ClientBundleDecodeBase64Value

func ClientBundleDecodeBase64Value(val io.Reader) (string, error)

ClientBundleDecodeBase64Value read a value and base64 decode it.

func ClientBundleRetrieveValue

func ClientBundleRetrieveValue(val io.Reader) (string, error)

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.

func NewAuthUP

func NewAuthUP(username, password string) Auth

NewAuthSimple constructor for Auth from username and password.

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

type Client struct {
	HTTPClient *http.Client
	// contains filtered or unexported fields
}

Client MKE client.

func NewClient

func NewClient(apiURL *url.URL, auth *Auth, HTTPClient *http.Client) (Client, error)

NewClient creates a new MKE API Client from raw components.

func NewClientSimple

func NewClientSimple(endpoint, username, password string) (Client, error)

NewClient from a string URL and u/p.

func NewUnsafeSSLClient

func NewUnsafeSSLClient(endpoint, username, password string) (Client, error)

NewUnsafeSSLClient that allows self-signed SSL from a string URL and u/p.

func (*Client) ApiAuthorizedGeneric

func (c *Client) ApiAuthorizedGeneric(ctx context.Context, req *http.Request) (*Response, error)

ApiAuthorizedGeneric send a authenticated generic http request to the MKE API.

func (*Client) ApiClientBundleCreate

func (c *Client) ApiClientBundleCreate(ctx context.Context, label string) (ClientBundle, error)

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

func (c *Client) ApiDeleteAccount(ctx context.Context, id string) error

DeleteAccount deletes a user from in Enzi.

func (*Client) ApiGeneric

func (c *Client) ApiGeneric(ctx context.Context, req *http.Request) (*Response, error)

ApiGeneric send a generic http request to the MKE API.

func (*Client) ApiLogin

func (c *Client) ApiLogin(ctx context.Context) error

apiLogin update client Auth with a new token from an API auth request.

func (*Client) ApiPing

func (c *Client) ApiPing(ctx context.Context) error

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

func (c *Client) ApiPublicKeyDelete(ctx context.Context, account, keyid string) error

ApiPublicKeyDelete delete a specific account key.

func (*Client) ApiPublicKeyList

func (c *Client) ApiPublicKeyList(ctx context.Context, account string) ([]AccountPublicKey, error)

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

func (c *Client) ApiReadAccount(ctx context.Context, id string) (ResponseAccount, error)

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.

func (*Client) RequestFromTargetAndJSONBody

func (c *Client) RequestFromTargetAndJSONBody(ctx context.Context, method, target string, body interface{}) (*http.Request, error)

RequestFromTarget build simple http.Request from relative API target and JSON serialized struct for a body.

func (*Client) Username

func (c *Client) Username() string

Username retrieve username string for auth, so that we don't expose the whole auth struct.

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

type Response struct {
	*http.Response
}

Response http.Response wrapper that can interpret the body more.

func (*Response) BodyBytes

func (r *Response) BodyBytes() ([]byte, error)

BodyBytes return http.Response body as a []byte.

func (*Response) JSONMarshallBody

func (r *Response) JSONMarshallBody(target interface{}) error

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.

Jump to

Keyboard shortcuts

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