openapi

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2020 License: MIT Imports: 23 Imported by: 0

README

Go API client for openapi

Handles authentication, creation/management of applications, databases, users and also provides a superuser API.

Only a superuser can avail the superuser API. A superuser can grant/revoke superuser privileges to other users. A default superuser is created every time a Gasper instance is launched whose credentials are defined in the admin section of config.toml, the main configuration file. A sample configuration file is available here.

Note:- Normally the applications and databases can only be managed by their owners but the superuser can bypass that check.

PS:- If you want to programmatically generate a client for this API, you can find the corresponding OpenAPI specifications here. We recommend using OpenAPI-Generator for generating clients.

Overview

This API client was generated by the OpenAPI Generator project. By using the OpenAPI-spec from a remote server, you can easily generate an API client.

  • API version: 1.0
  • Package version: 1.0.0
  • Build package: org.openapitools.codegen.languages.GoClientCodegen For more information, please visit https://chat.sdslabs.co

Installation

Install the following dependencies:

go get github.com/stretchr/testify/assert
go get golang.org/x/oauth2
go get golang.org/x/net/context
go get github.com/antihax/optional

Put the package under your project folder and add the following in import:

import "./openapi"

Documentation for API Endpoints

All URIs are relative to http://localhost:3000

Class Method HTTP request Description
AppsAPI CreateApp Post /apps/{language} Create an application
AppsAPI DeleteAppByUser Delete /apps/{app} Delete an application owned by a user
AppsAPI FetchAppByUser Get /apps/{app} Fetch a single application owned by a user
AppsAPI FetchAppsByUser Get /apps Fetch all applications owned by a user
AppsAPI FetchLogsByUser Get /apps/{app}/logs Fetch logs of an application
AppsAPI FetchMetricsByUser Get /apps/{app}/metrics Fetch metrics of an application
AppsAPI RebuildAppByUser Patch /apps/{app}/rebuild Rebuild an application
AppsAPI UpdateAppByUser Put /apps/{app} Update an application owned by a user
AuthAPI Refresh Get /auth/refresh Refresh JWT token using existing token
DbsAPI CreateDB Post /dbs/{databaseType} Create a database
DbsAPI DeleteDbByUser Delete /dbs/{db} Delete a single database owned by a user
DbsAPI FetchDbByUser Get /dbs/{db} Fetch a single database owned by a user
DbsAPI FetchDbsByUser Get /dbs Fetch all databases owned by a user
InstancesAPI FetchIntancesByUser Get /instances Fetch all instances owned by a user

Documentation For Models

Documentation For Authorization

bearerAuth

  • Type: HTTP basic authentication

Example

auth := context.WithValue(context.Background(), sw.ContextBasicAuth, sw.BasicAuth{
    UserName: "username",
    Password: "password",
})
r, err := client.Service.Operation(auth, args)

Author

contact@sdslabs.co.in

Documentation

Index

Constants

View Source
const LOGINPATH = "/gctllogin"

Variables

View Source
var (
	// ContextOAuth2 takes an oauth2.TokenSource as authentication for the request.
	ContextOAuth2 = contextKey("token")

	// ContextBasicAuth takes BasicAuth as authentication for the request.
	ContextBasicAuth = contextKey("basic")

	// ContextAccessToken takes a string oauth2 access token as authentication for the request.
	ContextAccessToken = contextKey("accesstoken")

	// ContextAPIKey takes an APIKey as authentication for the request
	ContextAPIKey = contextKey("apikey")
)

Functions

func CacheExpires

func CacheExpires(r *http.Response) time.Time

CacheExpires helper function to determine remaining time before repeating a request.

Types

type APIClient

type APIClient struct {
	AppsAPI *AppsAPIService

	AuthAPI *AuthAPIService

	DbsAPI *DbsAPIService

	InstancesAPI *InstancesAPIService
	// contains filtered or unexported fields
}

APIClient manages communication with the Gasper Master API API v1.0 In most cases there should be only one, shared, APIClient.

func NewAPIClient

func NewAPIClient(cfg *Configuration) *APIClient

NewAPIClient creates a new API client. Requires a userAgent string describing your application. optionally a custom http.Client to allow for advanced features such as caching.

func (*APIClient) CallAPI

func (c *APIClient) CallAPI(request *http.Request) (*http.Response, error)

CallAPI do the request.

func (*APIClient) ChangeBasePath

func (c *APIClient) ChangeBasePath(path string)

ChangeBasePath changes base path to allow switching to mocks

func (*APIClient) GetConfig

func (c *APIClient) GetConfig() *Configuration

GetConfig allow modification of underlying config for alternate implementations and testing Caution: modifying the configuration while live can cause data races and potentially unwanted behavior

type APIKey

type APIKey struct {
	Key    string
	Prefix string
}

APIKey provides API key based authentication to a request passed via context using ContextAPIKey

type APIResponse

type APIResponse struct {
	*http.Response `json:"-"`
	Message        string `json:"message,omitempty"`
	// Operation is the name of the OpenAPI operation.
	Operation string `json:"operation,omitempty"`
	// RequestURL is the request URL. This value is always available, even if the
	// embedded *http.Response is nil.
	RequestURL string `json:"url,omitempty"`
	// Method is the HTTP method used for the request.  This value is always
	// available, even if the embedded *http.Response is nil.
	Method string `json:"method,omitempty"`
	// Payload holds the contents of the response body (which may be nil or empty).
	// This is provided here as the raw response.Body() reader will have already
	// been drained.
	Payload []byte `json:"-"`
}

APIResponse stores the API response returned by the server.

func NewAPIResponse

func NewAPIResponse(r *http.Response) *APIResponse

NewAPIResponse returns a new APIResonse object.

func NewAPIResponseWithError

func NewAPIResponseWithError(errorMessage string) *APIResponse

NewAPIResponseWithError returns a new APIResponse object with the provided error message.

type Application

type Application struct {
	// Name of the application
	Name string `json:"name"`
	// Password required for SSH access to the application's docker container
	Password string  `json:"password"`
	Git      Git     `json:"git"`
	Context  Context `json:"context"`
	// Environment variables required by the application
	Env       map[string]string    `json:"env,omitempty"`
	Resources ApplicationResources `json:"resources,omitempty"`
}

Application struct for Application

type ApplicationResources

type ApplicationResources struct {
	// Number of virtual CPUs
	CPU float32 `json:"cpu,omitempty"`
	// Memory in GigaBytes (GB)
	Memory float32 `json:"memory,omitempty"`
}

ApplicationResources Resources required by the application

type AppsAPI

type AppsAPI interface {
	CreateApp(ctx _context.Context, language string, application Application) (InlineResponse2002, *_nethttp.Response, error)
	DeleteAppByUser(ctx _context.Context, app string) (InlineResponse2002, *_nethttp.Response, error)
	FetchAppByUser(ctx _context.Context, app string) (InlineResponse2003, *_nethttp.Response, error)
	FetchAppsByUser(ctx _context.Context) (InlineResponse2003, *_nethttp.Response, error)
}

AppsAPI is interface for functions of type AppsAPIService

type AppsAPIService

type AppsAPIService service

AppsAPIService AppsAPI service

func (*AppsAPIService) CreateApp

func (a *AppsAPIService) CreateApp(ctx _context.Context, language string, application Application) (InlineResponse2002, *_nethttp.Response, error)

CreateApp Create an application

  • @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param language The programming language in which the application is written
  • @param application

@return InlineResponse2002

func (*AppsAPIService) DeleteAppByUser

func (a *AppsAPIService) DeleteAppByUser(ctx _context.Context, app string) (InlineResponse2002, *_nethttp.Response, error)

DeleteAppByUser Delete an application owned by a user

  • @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param app The name of the application

@return InlineResponse2002

func (*AppsAPIService) FetchAppByUser

FetchAppByUser Fetch a single application owned by a user

  • @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param app The name of the application

@return InlineResponse2003

func (*AppsAPIService) FetchAppsByUser

FetchAppsByUser Fetch all applications owned by a user

  • @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().

@return InlineResponse2003

func (*AppsAPIService) FetchLogsByUser

func (a *AppsAPIService) FetchLogsByUser(ctx _context.Context, app string, localVarOptionals *FetchLogsByUserOpts) (InlineResponse2005, *_nethttp.Response, error)

FetchLogsByUser Fetch logs of an application

  • @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param app The name of the application
  • @param optional nil or *FetchLogsByUserOpts - Optional Parameters:
  • @param "Tail" (optional.Int32) - Fetch the last **n** logs (Fetches all logs if not specified)

@return InlineResponse2005

func (*AppsAPIService) FetchMetricsByUser

func (a *AppsAPIService) FetchMetricsByUser(ctx _context.Context, app string, localVarOptionals *FetchMetricsByUserOpts) (InlineResponse2006, *_nethttp.Response, error)

FetchMetricsByUser Fetch metrics of an application

  • @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param app The name of the application
  • @param optional nil or *FetchMetricsByUserOpts - Optional Parameters:
  • @param "Seconds" (optional.Int32) - Fetch metrics in the last **n** seconds
  • @param "Minutes" (optional.Int32) - Fetch metrics in the last **n** minutes
  • @param "Hours" (optional.Int32) - Fetch metrics in the last **n** hours
  • @param "Days" (optional.Int32) - Fetch metrics in the last **n** days
  • @param "Weeks" (optional.Int32) - Fetch metrics in the last **n** weeks
  • @param "Months" (optional.Int32) - Fetch metrics in the last **n** months
  • @param "Years" (optional.Int32) - Fetch metrics in the last **n** years
  • @param "Decades" (optional.Int32) - Fetch metrics in the last **n** decades

@return InlineResponse2006

func (*AppsAPIService) RebuildAppByUser

func (a *AppsAPIService) RebuildAppByUser(ctx _context.Context, app string) (InlineResponse2002, *_nethttp.Response, error)

RebuildAppByUser Rebuild an application

  • @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param app The name of the application

@return InlineResponse2002

func (*AppsAPIService) UpdateAppByUser

func (a *AppsAPIService) UpdateAppByUser(ctx _context.Context, app string, application Application) (InlineResponse2002, *_nethttp.Response, error)

UpdateAppByUser Update an application owned by a user

  • @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param app The name of the application
  • @param application

@return InlineResponse2002

type AuthAPI

type AuthAPI interface {
	Refresh(ctx _context.Context, authorization string) (LoginResponse, *_nethttp.Response, error)
}

AuthAPI is interface for functions of type AuthAPIService

type AuthAPIService

type AuthAPIService service

AuthAPIService AuthAPI service

func (*AuthAPIService) Login

Login Login in gctl

  • @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param email

@return InlineResponse2004

func (*AuthAPIService) Refresh

func (a *AuthAPIService) Refresh(ctx _context.Context, authorization string) (LoginResponse, *_nethttp.Response, error)

Refresh Refresh JWT token using existing token

  • @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param authorization Bearer Token Authentication

@return LoginResponse

type BasicAuth

type BasicAuth struct {
	UserName string `json:"userName,omitempty"`
	Password string `json:"password,omitempty"`
}

BasicAuth provides basic http authentication to a request passed via context using ContextBasicAuth

type Client

type Client interface {
	NewAPIClient(cfg *Configuration) *APIClient
	CallAPI(request *http.Request) (*http.Response, error)
	ChangeBasePath(path string)
	GetConfig() *Configuration
	// contains filtered or unexported methods
}

Client is interface for functions of type APIClient

type Configuration

type Configuration struct {
	BasePath      string                `json:"basePath,omitempty"`
	Host          string                `json:"host,omitempty"`
	Scheme        string                `json:"scheme,omitempty"`
	DefaultHeader map[string]string     `json:"defaultHeader,omitempty"`
	UserAgent     string                `json:"userAgent,omitempty"`
	Debug         bool                  `json:"debug,omitempty"`
	Servers       []ServerConfiguration `json:"server,omitempty"`
	HTTPClient    *http.Client
}

Configuration stores the configuration of the API client

func NewConfiguration

func NewConfiguration() *Configuration

NewConfiguration returns a new Configuration object

func (*Configuration) AddDefaultHeader

func (c *Configuration) AddDefaultHeader(key string, value string)

AddDefaultHeader adds a new HTTP header to the default header in the request

func (*Configuration) ServerURL

func (c *Configuration) ServerURL(index int, variables map[string]string) (string, error)

ServerURL returns URL based on server settings

type Context

type Context struct {
	// Entrypoint for an application
	Index string `json:"index"`
	// Port on which the application runs
	Port int64 `json:"port,omitempty"`
	// Is a Run Commands file present in the application's git repository's root directory?
	RcFile bool `json:"rc_file,omitempty"`
	// Commands for installing application dependencies
	Build []string `json:"build,omitempty"`
	// Commands for running the application
	Run []string `json:"run,omitempty"`
}

Context struct for Context

type CreateDBOpts

type CreateDBOpts struct {
	Database optional.Interface
}

CreateDBOpts Optional parameters for the method 'CreateDB'

type CreatedApplication

type CreatedApplication struct {
	// ID of the application's docker container
	ContainerId string `json:"container_id,omitempty"`
	// Port assigned by the node to the application's docker container
	ContainerPort int64 `json:"container_port,omitempty"`
	// Docker image used in building the application's container
	DockerImage string `json:"docker_image,omitempty"`
	// The domain name of the application (DNS entry is managed by GenDNS 💡)
	AppUrl string `json:"app_url,omitempty"`
	// IPv4 address of the node
	HostIp string `json:"host_ip,omitempty"`
	// The DNS NameServers used by the application's docker container
	NameServers []string `json:"name_servers,omitempty"`
	// The kind of instance this application belongs to
	InstanceType string `json:"instance_type,omitempty"`
	// The programming language in which the application is written
	Language string `json:"language,omitempty"`
	// Owner of the application
	Owner string `json:"owner,omitempty"`
	// Command to SSH into the application's docker container
	SshCmd string `json:"ssh_cmd,omitempty"`
	// Application's identifier assigned by MongoDB
	Id string `json:"_id,omitempty"`
}

CreatedApplication struct for CreatedApplication

type CreatedDatabase

type CreatedDatabase struct {
	// Username of the database
	User string `json:"user,omitempty"`
	// Owner of the database
	Owner string `json:"owner,omitempty"`
	// The domain name of the database (DNS entry is managed by GenDNS 💡)
	DbUrl string `json:"db_url,omitempty"`
	// IPv4 address of the node where the database is deployed
	HostIp string `json:"host_ip,omitempty"`
	// Port on which the database server is running
	Port string `json:"port,omitempty"`
	// The kind of instance the database belongs to
	InstanceType string `json:"instance_type,omitempty"`
	// The type of database
	Language string `json:"language,omitempty"`
}

CreatedDatabase struct for CreatedDatabase

type Database

type Database struct {
	// Name of the database
	Name string `json:"name"`
	// Password of the database
	Password string `json:"password"`
}

Database struct for Database

type DbsAPI

type DbsAPI interface {
	CreateDB(ctx _context.Context, databaseType string, localVarOptionals *CreateDBOpts) (InlineResponse2002, *_nethttp.Response, error)
	DeleteDbByUser(ctx _context.Context, db string) (InlineResponse2002, *_nethttp.Response, error)
	FetchDbByUser(ctx _context.Context, db string) (InlineResponse2007, *_nethttp.Response, error)
	FetchDbsByUser(ctx _context.Context) (InlineResponse2007, *_nethttp.Response, error)
}

DbsAPI is interface for functions of type DbsAPIService

type DbsAPIService

type DbsAPIService service

DbsAPIService DbsAPI service

func (*DbsAPIService) CreateDb

func (a *DbsAPIService) CreateDb(ctx _context.Context, databaseType string, localVarOptionals *CreateDBOpts) (InlineResponse2002, *_nethttp.Response, error)

CreateDB Create a database

  • @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param databaseType The type of database
  • @param optional nil or *CreateDBOpts - Optional Parameters:
  • @param "Database" (optional.Interface of Database) -

@return InlineResponse2002

func (*DbsAPIService) DeleteDbByUser

DeleteDbByUser Delete a single database owned by a user

  • @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param db Name of the database

@return InlineResponse2002

func (*DbsAPIService) FetchDbByUser

FetchDbByUser Fetch a single database owned by a user

  • @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param db Name of the database

@return InlineResponse2007

func (*DbsAPIService) FetchDbsByUser

FetchDbsByUser Fetch all databases owned by a user

  • @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().

@return InlineResponse2007

type Email

type Email struct {
	// Email id of the user
	Email string `json:"email"`
}

Email struct for Email

type FetchLogsByUserOpts

type FetchLogsByUserOpts struct {
	Tail optional.Int32
}

FetchLogsByUserOpts Optional parameters for the method 'FetchLogsByUser'

type FetchMetricsByUserOpts

type FetchMetricsByUserOpts struct {
	Seconds optional.Int32
	Minutes optional.Int32
	Hours   optional.Int32
	Days    optional.Int32
	Weeks   optional.Int32
	Months  optional.Int32
	Years   optional.Int32
	Decades optional.Int32
}

FetchMetricsByUserOpts Optional parameters for the method 'FetchMetricsByUser'

type GenericOpenAPIError

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

GenericOpenAPIError Provides access to the body, error and model on returned errors.

func (GenericOpenAPIError) Body

func (e GenericOpenAPIError) Body() []byte

Body returns the raw bytes of the response

func (GenericOpenAPIError) Error

func (e GenericOpenAPIError) Error() string

Error returns non-empty string if there was an error.

func (GenericOpenAPIError) Model

func (e GenericOpenAPIError) Model() interface{}

Model returns the unpacked model of the error

type Git

type Git struct {
	// Git Repository URL of the application
	RepoUrl string `json:"repo_url"`
	// Access token for cloning the application's git repository
	AccessToken string `json:"access_token,omitempty"`
	// Specific branch to clone
	Branch string `json:"branch,omitempty"`
}

Git struct for Git

type InlineResponse2001

type InlineResponse2001 struct {
	Success bool        `json:"success,omitempty"`
	Data    []Instances `json:"data,omitempty"`
}

InlineResponse2001 struct for InlineResponse2001

type InlineResponse2002

type InlineResponse2002 struct {
	Success bool `json:"success,omitempty"`
}

InlineResponse2002 struct for InlineResponse2002

type InlineResponse2003

type InlineResponse2003 struct {
	Success bool                 `json:"success,omitempty"`
	Data    []CreatedApplication `json:"data,omitempty"`
}

InlineResponse2003 struct for InlineResponse2003

type InlineResponse2004

type InlineResponse2004 struct {
	Success bool      `json:"success,omitempty"`
	Expire  time.Time `json:"expire,omitempty"`
}

InlineResponse2004 struct for InlineResponse2004

type InlineResponse2005

type InlineResponse2005 struct {
	Success bool     `json:"success,omitempty"`
	Data    []string `json:"data,omitempty"`
}

InlineResponse2005 struct for InlineResponse2005

type InlineResponse2006

type InlineResponse2006 struct {
	Success bool      `json:"success,omitempty"`
	Data    []Metrics `json:"data,omitempty"`
}

InlineResponse2006 struct for InlineResponse2006

type InlineResponse2007

type InlineResponse2007 struct {
	Success bool              `json:"success,omitempty"`
	Data    []CreatedDatabase `json:"data,omitempty"`
}

InlineResponse2007 struct for InlineResponse2007

type InlineResponse400

type InlineResponse400 struct {
	Success bool   `json:"success,omitempty"`
	Error   string `json:"error,omitempty"`
}

InlineResponse400 struct for InlineResponse400

type InlineResponse401

type InlineResponse401 struct {
	Success bool   `json:"success,omitempty"`
	Error   string `json:"error,omitempty"`
}

InlineResponse401 struct for InlineResponse401

type InlineResponse500

type InlineResponse500 struct {
	Success bool   `json:"success,omitempty"`
	Error   string `json:"error,omitempty"`
}

InlineResponse500 struct for InlineResponse500

type Instances

type Instances struct {
	// Document's identifier assigned by MongoDB
	Id string `json:"_id,omitempty"`
	// Name of the application or database
	Name string `json:"name,omitempty"`
	// The kind of instance this application belongs to
	InstanceType string `json:"instance_type,omitempty"`
	// The programming language in which the application is written
	Language string `json:"language,omitempty"`
}

Instances struct for Instances

type InstancesAPI

type InstancesAPI interface {
	FetchIntancesByUser(ctx _context.Context) (InlineResponse2001, *_nethttp.Response, error)
}

InstancesAPI is interface for functions of type InstancesAPIService

type InstancesAPIService

type InstancesAPIService service

InstancesAPIService InstancesAPI service

func (*InstancesAPIService) FetchIntancesByUser

FetchIntancesByUser Fetch all instances owned by a user

  • @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().

@return InlineResponse2001

type LoginResponse

type LoginResponse struct {
	Code   int32     `json:"code,omitempty"`
	Expire time.Time `json:"expire,omitempty"`
	// The token required for authentication via bearer scheme
	Token string `json:"token,omitempty"`
}

LoginResponse struct for LoginResponse

type Metrics

type Metrics struct {
	// Document's identifier assigned by MongoDB
	Id string `json:"_id,omitempty"`
	// Name of the application
	Name string `json:"name,omitempty"`
	// IPv4 address of the node where the application is deployed
	HostIp string `json:"host_ip,omitempty"`
	// Is the application up and running?
	Alive bool `json:"alive,omitempty"`
	// The number of available CPUs in the node
	OnlineCpus int32 `json:"online_cpus,omitempty"`
	// Fraction of total CPUs utilized by the application
	CpuUsage float64 `json:"cpu_usage,omitempty"`
	// Fraction of memory utilized by the application
	MemoryUsage float64 `json:"memory_usage,omitempty"`
	// Highest fraction of memory utilized by the application in its lifetime
	MaxMemoryUsage float64 `json:"max_memory_usage,omitempty"`
	// Memory (in GigaBytes) alloted to the application
	MemoryLimit float32 `json:"memory_limit,omitempty"`
	// Unix timestamp of the metrics document
	Timestamp int64 `json:"timestamp,omitempty"`
}

Metrics struct for Metrics

type ServerConfiguration

type ServerConfiguration struct {
	URL         string `json:"url,omitempty"`
	Description string `json:"description"`
	Variables   map[string]ServerVariable
}

ServerConfiguration stores the information about a server

type ServerVariable

type ServerVariable struct {
	Description  string
	DefaultValue string
	EnumValues   []string
}

ServerVariable stores the information about a server variable

Directories

Path Synopsis
Package testmocks is a generated GoMock package.
Package testmocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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