vlazic / opalstack-go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Go API client for OpalStack

The Opalstack JSON REST API

Authorization

This API uses an Authorization header of the form: \"Authorization: Token 1111111111111111111111111111111111111111\", where 1111111111111111111111111111111111111111 represents an API token created at https://my.opalstack.com/tokens/.

The typical format of an API request looks like the following:

GET request:
    curl -s -H \"Authorization: Token 1111111111111111111111111111111111111111\" \"https://my.opalstack.com/api/v1/site/list/\" | jq .

POST request:
    curl -s -H \"Content-Type: application/json\" -H \"Authorization: Token 1111111111111111111111111111111111111111\" \\
            -X POST -d '[{\"id\": \"(site UUID)\", \"redirect\": true, ...}]' \"https://my.opalstack.com/api/v1/site/update/\" | jq .

(Further examples will omit headers and jq for the sake of clarity)

You can also authorize requests on our API Documentation page (https://my.opalstack.com/api/v1/doc/) in order to facilitate development. To do so, click the "Authorize" button on the right side of the page and enter "Token 1111111111111111111111111111111111111111" in the Value field within. Afterword, you will be able to perform requests directly from the documentation page. Be sure to logout when finished.

Embedding

The Opalstack API supports embedding. This allows you to nest child API objects in a single GET request. For example, consider the following GET request performed with curl:

Request:
    curl \"https://my.opalstack.com/api/v1/osuser/list/\"

Response:
    [
      {
        \"id\": \"01010101-0202-0303-0404-050505050505\",
        \"state\": \"READY\",
        \"ready\": true,
        \"name\": \"the_osuser_name\",
        \"server\": \"11111111-1212-1313-1414-151515151515\"
      }
    ]

Suppose then that we would like additional information about the server. We could proceed to query the server UUID (11111111-1212-1313-1414-151515151515) at the /server/read/{uuid} endpoint, like this:

Request:
    curl \"https://my.opalstack.com/api/v1/server/read/11111111-1212-1313-1414-151515151515\"

Response:
    {
      \"id\": \"11111111-1212-1313-1414-151515151515\",
      \"hostname\": \"vpsNNN.opalstack.com\"
    }

However, we could have instead choosen to specify ?embed=server as a query parameter to the original GET request. This will cause objects to be embedded in the response directly:

Request:
    curl \"https://my.opalstack.com/api/v1/osuser/list/?embed=server\"

Response:
    [
      {
        \"id\": \"01010101-0202-0303-0404-050505050505\",
        \"state\": \"READY\",
        \"ready\": true,
        \"name\": \"the_osuser_name\",
        \"server\": {
          \"id\": \"11111111-1212-1313-1414-151515151515\",
          \"hostname\": \"vpsNNN.opalstack.com\"
        }
      }
    ]

Here, the server field has been be populated with the full object instead of just a UUID.

The embed query parameter accepts multiple (comma-separated) fields to embed. For example:

curl \"https://my.opalstack.com/api/v1/account/info/?embed=web_servers,imap_servers,smtp_servers\"

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.0
  • Package version: 0.0.1
  • Build package: org.openapitools.codegen.languages.GoClientCodegen

Installation

Install the following dependencies:

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

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

import OpalStack "github.com/vlazic/opalstack-go"

To use a proxy, set the environment variable HTTP_PROXY:

os.Setenv("HTTP_PROXY", "http://proxy_name:proxy_port")

Configuration of Server URL

Default configuration comes with Servers field that contains server objects as defined in the OpenAPI specification.

Select Server Configuration

For using other server than the one defined on index 0 set context value sw.ContextServerIndex of type int.

ctx := context.WithValue(context.Background(), OpalStack.ContextServerIndex, 1)

Templated Server URL

Templated server URL is formatted using default variables from configuration or from context value sw.ContextServerVariables of type map[string]string.

ctx := context.WithValue(context.Background(), OpalStack.ContextServerVariables, map[string]string{
	"basePath": "v2",
})

Note, enum values are always validated and all unused variables are silently ignored.

URLs Configuration per Operation

Each operation can use different server URL defined using OperationServers map in the Configuration. An operation is uniquely identified by "{classname}Service.{nickname}" string. Similar rules for overriding default operation server index and variables applies by using sw.ContextOperationServerIndices and sw.ContextOperationServerVariables context maps.

ctx := context.WithValue(context.Background(), OpalStack.ContextOperationServerIndices, map[string]int{
	"{classname}Service.{nickname}": 2,
})
ctx = context.WithValue(context.Background(), OpalStack.ContextOperationServerVariables, map[string]map[string]string{
	"{classname}Service.{nickname}": {
		"port": "8443",
	},
})

Documentation for API Endpoints

All URIs are relative to http://localhost

Class Method HTTP request Description
AccountAPI AccountList Get /api/v1/account/list/
AccountAPI AccountRead Get /api/v1/account/read/{uuid}
AccountAPI AccountReadCurrent Get /api/v1/account/info/
AccountAPI AccountReadCurrent2 Get /api/v1/account/read/current/
AccountAPI AccountUpdate Post /api/v1/account/update/
AccountAPI AccountUpdateCurrent Post /api/v1/account/update/current/
AddressAPI AddressCreate Post /api/v1/address/create/
AddressAPI AddressDelete Post /api/v1/address/delete/
AddressAPI AddressList Get /api/v1/address/list/
AddressAPI AddressRead Get /api/v1/address/read/{uuid}
AddressAPI AddressUpdate Post /api/v1/address/update/
AppAPI AppCreate Post /api/v1/app/create/
AppAPI AppDelete Post /api/v1/app/delete/
AppAPI AppFailed Post /api/v1/app/failed/
AppAPI AppInstalled Post /api/v1/app/installed/
AppAPI AppList Get /api/v1/app/list/
AppAPI AppRead Get /api/v1/app/read/{uuid}
AppAPI AppUpdate Post /api/v1/app/update/
CertAPI CertCreate Post /api/v1/cert/create/
CertAPI CertDelete Post /api/v1/cert/delete/
CertAPI CertList Get /api/v1/cert/list/
CertAPI CertRead Get /api/v1/cert/read/{uuid}
CertAPI CertShared Get /api/v1/cert/shared/
CertAPI CertUpdate Post /api/v1/cert/update/
DnscheckAPI DnscheckLeChallengeCheck Post /api/v1/dnscheck/le_challenge_check/
DnsrecordAPI DnsrecordCreate Post /api/v1/dnsrecord/create/
DnsrecordAPI DnsrecordDelete Post /api/v1/dnsrecord/delete/
DnsrecordAPI DnsrecordList Get /api/v1/dnsrecord/list/
DnsrecordAPI DnsrecordRead Get /api/v1/dnsrecord/read/{uuid}
DnsrecordAPI DnsrecordUpdate Post /api/v1/dnsrecord/update/
DomainAPI DomainCreate Post /api/v1/domain/create/
DomainAPI DomainDelete Post /api/v1/domain/delete/
DomainAPI DomainList Get /api/v1/domain/list/
DomainAPI DomainRead Get /api/v1/domain/read/{uuid}
IpAPI IpList Get /api/v1/ip/list/
IpAPI IpRead Get /api/v1/ip/read/{uuid}
LoginAPI Login Post /api/v1/login/
MailuserAPI MailuserCreate Post /api/v1/mailuser/create/
MailuserAPI MailuserDelete Post /api/v1/mailuser/delete/
MailuserAPI MailuserList Get /api/v1/mailuser/list/
MailuserAPI MailuserRead Get /api/v1/mailuser/read/{uuid}
MailuserAPI MailuserUpdate Post /api/v1/mailuser/update/
MailuserAPI MailuserUpdatePublic Post /api/v1/mailuser/update_public/
MariadbAPI MariadbCreate Post /api/v1/mariadb/create/
MariadbAPI MariadbDelete Post /api/v1/mariadb/delete/
MariadbAPI MariadbList Get /api/v1/mariadb/list/
MariadbAPI MariadbRead Get /api/v1/mariadb/read/{uuid}
MariadbAPI MariadbUpdate Post /api/v1/mariadb/update/
MariauserAPI MariauserCreate Post /api/v1/mariauser/create/
MariauserAPI MariauserDelete Post /api/v1/mariauser/delete/
MariauserAPI MariauserList Get /api/v1/mariauser/list/
MariauserAPI MariauserRead Get /api/v1/mariauser/read/{uuid}
MariauserAPI MariauserUpdate Post /api/v1/mariauser/update/
NoticeAPI NoticeCreate Post /api/v1/notice/create/
NoticeAPI NoticeDelete Post /api/v1/notice/delete/
NoticeAPI NoticeList Get /api/v1/notice/list/
NoticeAPI NoticeRead Get /api/v1/notice/read/{uuid}
NoticeAPI NoticeUpdate Post /api/v1/notice/update/
OsuserAPI OsuserCreate Post /api/v1/osuser/create/
OsuserAPI OsuserDelete Post /api/v1/osuser/delete/
OsuserAPI OsuserList Get /api/v1/osuser/list/
OsuserAPI OsuserRead Get /api/v1/osuser/read/{uuid}
OsuserAPI OsuserUpdate Post /api/v1/osuser/update/
OsvarAPI OsvarCreate Post /api/v1/osvar/create/
OsvarAPI OsvarDelete Post /api/v1/osvar/delete/
OsvarAPI OsvarList Get /api/v1/osvar/list/
OsvarAPI OsvarRead Get /api/v1/osvar/read/{uuid}
OsvarAPI OsvarUpdate Post /api/v1/osvar/update/
PsqldbAPI PsqldbCreate Post /api/v1/psqldb/create/
PsqldbAPI PsqldbDelete Post /api/v1/psqldb/delete/
PsqldbAPI PsqldbList Get /api/v1/psqldb/list/
PsqldbAPI PsqldbRead Get /api/v1/psqldb/read/{uuid}
PsqldbAPI PsqldbUpdate Post /api/v1/psqldb/update/
PsqluserAPI PsqluserCreate Post /api/v1/psqluser/create/
PsqluserAPI PsqluserDelete Post /api/v1/psqluser/delete/
PsqluserAPI PsqluserList Get /api/v1/psqluser/list/
PsqluserAPI PsqluserRead Get /api/v1/psqluser/read/{uuid}
PsqluserAPI PsqluserUpdate Post /api/v1/psqluser/update/
QuarantinedmailAPI QuarantinedmailDelete Post /api/v1/quarantinedmail/delete/
QuarantinedmailAPI QuarantinedmailList Get /api/v1/quarantinedmail/list/
QuarantinedmailAPI QuarantinedmailRead Get /api/v1/quarantinedmail/read/{uuid}
QuarantinedmailAPI QuarantinedmailSubmit Post /api/v1/quarantinedmail/submit/
SchemaAPI SchemaRetrieve Get /api/v1/schema/
ServerAPI ServerList Get /api/v1/server/list/
ServerAPI ServerRead Get /api/v1/server/read/{uuid}
SiteAPI SiteCreate Post /api/v1/site/create/
SiteAPI SiteDelete Post /api/v1/site/delete/
SiteAPI SiteList Get /api/v1/site/list/
SiteAPI SiteRead Get /api/v1/site/read/{uuid}
SiteAPI SiteUpdate Post /api/v1/site/update/
TokenAPI TokenCreate Post /api/v1/token/create/
TokenAPI TokenDelete Post /api/v1/token/delete/
TokenAPI TokenList Get /api/v1/token/list/
TokenAPI TokenRead Get /api/v1/token/read/{key}
TokenAPI TokenUpdate Post /api/v1/token/update/
UsageAPI MailusageLatest Get /api/v1/usage/mail/latest/
UsageAPI WebusageLatest Get /api/v1/usage/web/latest/

Documentation For Models

Documentation For Authorization

Authentication schemes defined for the API:

tokenAuth

  • Type: API key
  • API key parameter name: Authorization
  • Location: HTTP header

Note, each API key must be added to a map of map[string]APIKey where the key is: Authorization and passed in as the auth context for each request.

Example

auth := context.WithValue(
		context.Background(),
		sw.ContextAPIKeys,
		map[string]sw.APIKey{
			"Authorization": {Key: "API_KEY_STRING"},
		},
	)
r, err := client.Service.Operation(auth, args)

Documentation for Utility Methods

Due to the fact that model structure members are all pointers, this package contains a number of utility functions to easily obtain pointers to values of basic types. Each of these functions takes a value of the given basic type and returns a pointer to it:

  • PtrBool
  • PtrInt
  • PtrInt32
  • PtrInt64
  • PtrFloat
  • PtrFloat32
  • PtrFloat64
  • PtrString
  • PtrTime

Author

About


Languages

Language:Shell 100.0%