drycc

package module
v0.0.0-...-e5fbff1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2024 License: Apache-2.0 Imports: 10 Imported by: 5

README

Controller Go SDK

Build Status codecov Go Report Card codebeat badge GoDoc

This is the Go SDK for interacting with the Drycc Controller.

Usage
import drycc "github.com/drycc/controller-sdk-go"
import "github.com/drycc/controller-sdk-go/apps"

Construct a drycc client to interact with the controller API. Then, get the first 100 apps the user has access to.

//                    Verify SSL, Controller URL, API Token
client, err := drycc.New(true, "drycc.test.io", "abc123")
if err != nil {
    log.Fatal(err)
}
apps, _, err := apps.List(client, 100)
if err != nil {
    log.Fatal(err)
}
Authentication
import drycc "github.com/drycc/controller-sdk-go"
import "github.com/drycc/controller-sdk-go/auth"

If you don't already have a token for a user, you can retrieve one with a username and password.

// Create a client with a blank token to pass to login.
client, err := drycc.New(true, "drycc.test.io", "")
if err != nil {
    log.Fatal(err)
}
token, err := auth.Login(client, "user", "password")
if err != nil {
    log.Fatal(err)
}
// Set the client to use the retrieved token
client.Token = token

For a complete usage guide to the SDK, see full package documentation.

Documentation

Overview

Package drycc offers a SDK for interacting with the Drycc controller API.

This package works by creating a client, which contains session information, such as the controller url and user token. The client is then passed to api methods, which use it to make requests.

Basic Example

This example creates a client and then lists the apps that the user has access to:

import (
    drycc "github.com/drycc/controller-sdk-go"
    "github.com/drycc/controller-sdk-go/apps"
)

//                      Verify SSL, Controller URL, API Token
client, err := drycc.New(true, "drycc.test.io", "abc123")
if err != nil {
    log.Fatal(err)
}
apps, _, err := apps.List(client, 100)
if err != nil {
    log.Fatal(err)
}

Authentication

If you don't already have a token for a user, you can retrieve one with a username and password.

import (
    drycc "github.com/drycc/controller-sdk-go"
    "github.com/drycc/controller-sdk-go/apps"
)

// Create a client with a blank token to pass to login.
client, err := drycc.New(true, "drycc.test.io", "")
if err != nil {
    log.Fatal(err)
}
token, err := auth.Login(client, "user", "password")
if err != nil {
    log.Fatal(err)
}
// Set the client to use the retrieved token
client.Token = token

Learning More

See the godoc for the SDK's subpackages to learn more about specific SDK actions.

Index

Constants

View Source
const APIVersion = "2.3"

APIVersion is the api version compatible with the SDK.

In general, using an SDK that is a minor version out of date with the target controller is probably safe, as the drycc controller api follows semantic versioning and is backward compatible. However, using a SDK that is newer or a major version different than the controller is unsafe.

If the SDK detects an API version mismatch, it will return ErrAPIMismatch.

Variables

View Source
var (
	// ErrAPIMismatch occurs when the sdk is using a different api version than the drycc.
	ErrAPIMismatch = errors.New("API Version Mismatch between server and drycc")

	// DefaultUserAgent is used as the default user agent when making requests.
	DefaultUserAgent = fmt.Sprintf("Drycc Go SDK V%s", APIVersion)
)
View Source
var (
	// ErrServerError is returned when the server returns a 500.
	ErrServerError = errors.New("Internal Server Error")
	// ErrMethodNotAllowed is thrown when using a unsupposrted method.
	// This should not come up unless there in an bug in the SDK.
	ErrMethodNotAllowed = errors.New("Method Not Allowed")
	// ErrInvalidUsername is returned when the user specifies an invalid or missing username.
	ErrInvalidUsername = errors.New(invalidUserMsg)
	// ErrDuplicateUsername is returned when trying to register a user that already exists.
	ErrDuplicateUsername = errors.New(duplicateUserMsg)
	// ErrMissingPassword is returned when a password is not sent with the request.
	ErrMissingPassword = errors.New("A Password is required")
	// ErrLogin is returned when the api cannot login fails with provided username and password
	ErrLogin = errors.New(failedLoginMsg)
	// ErrUnauthorized is given when the API returns a 401.
	ErrUnauthorized = errors.New("Unauthorized: Missing or Invalid Token")
	// ErrInvalidAppName is returned when the user specifies an invalid app name.
	ErrInvalidAppName = errors.New(invalidAppNameMsg)
	// ErrConflict is returned when the API returns a 409.
	ErrConflict = errors.New("this action could not be completed due to a conflict")
	// ErrForbidden is returned when the API returns a 403.
	ErrForbidden = errors.New("you do not have permission to perform this action")
	// ErrMissingKey is returned when a key is not sent with the request.
	ErrMissingKey = errors.New("a key is required")
	// ErrDuplicateKey is returned when adding a key that already exists.
	ErrDuplicateKey = errors.New(duplicateKeyMsg)
	// ErrInvalidName is returned when a name is invalid or missing.
	ErrInvalidName = fmt.Errorf("name %s", strings.ToLower(invalidNameMsg))
	// ErrInvalidCertificate is returned when a certififate is missing or invalid
	ErrInvalidCertificate = errors.New(invalidCertMsg)
	// ErrPodNotFound is returned when a pod type is not Found
	ErrPodNotFound = errors.New("Pod not found in application")
	// ErrInvalidDomain is returned when a domain is missing or invalid
	ErrInvalidDomain = errors.New(invalidDomainMsg)
	// ErrDuplicateDomain is returned adding domain that is already in use
	ErrDuplicateDomain = errors.New(duplicateDomainMsg)
	// ErrInvalidImage is returned when a image is missing or invalid
	ErrInvalidImage = errors.New("The given image is invalid")
	// ErrInvalidVersion is returned when a version is invalid
	ErrInvalidVersion = errors.New("The given version is invalid")
	// ErrMissingID is returned when a ID is missing
	ErrMissingID = errors.New("An id is required")
	// ErrInvalidEmail is returned when a user gives an invalid email.
	ErrInvalidEmail = errors.New(invalidEmailMsg)
	// ErrTagNotFound is returned when no node can be found that matches the tag
	ErrTagNotFound = errors.New(invalidTagMsg)
	// ErrDuplicateApp is returned when create an app with an ID that already exists
	ErrDuplicateApp = errors.New(duplicateIDMsg)
	// ErrCancellationFailed is returned when cancelling a user fails.
	ErrCancellationFailed = errors.New("failed to delete user because the user still has applications assigned. Delete or transfer ownership")
)

Functions

func IsErrAPIMismatch

func IsErrAPIMismatch(err error) bool

IsErrAPIMismatch returns true if err is an ErrAPIMismatch, false otherwise

Types

type Client

type Client struct {
	// HTTPClient is the transport that is used to communicate with the API.
	HTTPClient *http.Client

	// VerifySSL determines whether or not to verify SSL connections.
	// This should be true unless you know the controller is using untrusted SSL keys.
	VerifySSL bool

	// ControllerURL is the URL used to communicate with the controller.
	ControllerURL *url.URL

	// UserAgent is the user agent used when making requests.
	UserAgent string

	// API Version used by the controller, set after a http request.
	ControllerAPIVersion string

	// Version of the drycc controller in use, set after a http request.
	ControllerVersion string

	// Token is used to authenticate the request against the API.
	Token string

	// HooksToken is the controller token used with the hooks resource.
	// The hooks resource isn't intended to be used by users, so it requires
	// a service token rather than a user token.
	HooksToken string
}

Client oversees the interaction between the drycc and controller

func New

func New(verifySSL bool, controllerURL string, token string) (*Client, error)

New creates a new client to communicate with the api. The controllerURL is the url of the controller component, by default drycc.<cluster url>.com verifySSL determines whether or not to verify SSL connections. This should be true unless you know the controller is using untrusted SSL keys.

func (*Client) CheckConnection

func (c *Client) CheckConnection() error

CheckConnection checks that the user is connected to a network and the URL points to a valid controller.

func (*Client) Do

func (c *Client) Do(req *http.Request) (*http.Response, error)

Do sends an HTTP request and returns an HTTP response, following policy (such as redirects, cookies, auth) as configured on the client.

func (*Client) Healthcheck

func (c *Client) Healthcheck() error

Healthcheck can be called to see if the controller is healthy

func (*Client) LimitedRequest

func (c *Client) LimitedRequest(path string, results int) (string, int, error)

LimitedRequest allows limiting the number of responses in a request.

func (*Client) NewRequest

func (c *Client) NewRequest(method string, path string, body io.Reader) (*http.Request, error)

NewRequest wraps [NewRequestWithContext] using context.Background.

func (*Client) Request

func (c *Client) Request(method string, path string, body []byte) (*http.Response, error)

Request makes a HTTP request with the given method, relative URL, and body on the controller. It also sets the Authorization and Content-Type headers to properly authenticate and communicate API. This is primarily intended to use be used by the SDK itself, but could potentially be used elsewhere.

type ErrNotFound

type ErrNotFound struct {
	// contains filtered or unexported fields
}

ErrNotFound is returned when the controller throws a 404.

func (ErrNotFound) Error

func (e ErrNotFound) Error() string

type ErrUnprocessable

type ErrUnprocessable struct {
	// contains filtered or unexported fields
}

ErrUnprocessable is returned when the controller throws a 422.

func (ErrUnprocessable) Error

func (e ErrUnprocessable) Error() string

Directories

Path Synopsis
Package allowlist provides methods for managing an app's allowlisted IP's.
Package allowlist provides methods for managing an app's allowlisted IP's.
Package apps provides methods for managing drycc apps.
Package apps provides methods for managing drycc apps.
Package appsettings provides methods for managing application settings of apps.
Package appsettings provides methods for managing application settings of apps.
Package auth handles user management: creation, deletion, and authentication.
Package auth handles user management: creation, deletion, and authentication.
Package builds provides methods for managing app builds.
Package builds provides methods for managing app builds.
Package certs manages SSL keys and certificates on the drycc platform
Package certs manages SSL keys and certificates on the drycc platform
Package config provides methods for managing configuration of apps.
Package config provides methods for managing configuration of apps.
Package domains provides methods for managing an app's domains.
Package domains provides methods for managing an app's domains.
Package ps provides methods for managing app processes.
Package ps provides methods for managing app processes.
Package gateways provides methods for managing an app's gateways.
Package gateways provides methods for managing an app's gateways.
Package hooks implements the controller's builder hooks api.
Package hooks implements the controller's builder hooks api.
Package keys provides methods for managing a user's ssh keys.
Package keys provides methods for managing a user's ssh keys.
Package perms provides methods for managing user app and administrative permissions.
Package perms provides methods for managing user app and administrative permissions.
pkg
Package ps provides methods for managing app processes.
Package ps provides methods for managing app processes.
Package ps provides methods for managing app processes.
Package ps provides methods for managing app processes.
Package releases provides methods for managing app releases.
Package releases provides methods for managing app releases.
Package config provides methods for managing configuration of apps.
Package config provides methods for managing configuration of apps.
Package routes provides methods for managing an app's routes.
Package routes provides methods for managing an app's routes.
Package services provides methods for managing an app's services.
Package services provides methods for managing an app's services.
Package tls provides methods for managing tls configuration for apps.
Package tls provides methods for managing tls configuration for apps.
Package users provides methods for viewing users.
Package users provides methods for viewing users.
Package config provides methods for managing configuration of apps.
Package config provides methods for managing configuration of apps.

Jump to

Keyboard shortcuts

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