cloudcraft

package module
v0.0.0-...-0a3d80e Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2023 License: MIT Imports: 12 Imported by: 0

README

cloudcraft-go

Go client library for accessing the https://cloudcraft.co API

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool

func Bool(v bool) *bool

Bool is a helper routine that allocates a new bool value to store v and returns a pointer to it.

func CheckResponse

func CheckResponse(r *http.Response) error

CheckResponse checks the API response for errors, and returns them if present. A response is considered an error if it has a status code outside the 200 range. API error responses are expected to have either no response body, or a JSON response body that maps to ErrorResponse. Any other response body will be silently ignored.

func DoRequest

func DoRequest(ctx context.Context, req *http.Request) (*http.Response, error)

DoRequest submits an HTTP request.

func DoRequestWithClient

func DoRequestWithClient(
	ctx context.Context,
	client *http.Client,
	req *http.Request) (*http.Response, error)

DoRequestWithClient submits an HTTP request using the specified client.

func Int

func Int(v int) *int

Int is a helper routine that allocates a new int32 value to store v and returns a pointer to it, but unlike Int32 its argument value is an int.

func StreamToString

func StreamToString(stream io.Reader) string

StreamToString converts a reader to a string

func String

func String(v string) *string

String is a helper routine that allocates a new string value to store v and returns a pointer to it.

func Stringify

func Stringify(message interface{}) string

Stringify attempts to create a string representation of Cloudcraft types

Types

type ArgError

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

ArgError is an error that represents an error with an input to cloudcraft-go. It identifies the argument and the cause (if possible).

func NewArgError

func NewArgError(arg, reason string) *ArgError

NewArgError creates an InputError.

func (*ArgError) Error

func (e *ArgError) Error() string

type AwsAccount

type AwsAccount struct {
	CreatedAt  time.Time `json:"createdAt,omitempty"`
	CreatorId  string    `json:"CreatorId,omitempty"`
	ExternalId string    `json:"externalId"`
	Id         string    `json:"id,omitempty"`
	Name       string    `json:"name,omitempty"`
	RoleArn    string    `json:"roleArn,omitempty"`
	UpdatedAt  time.Time `json:"createdAt,omitempty"`
}

AwsAccount represents a Cloudcraft AwsAccount

func (AwsAccount) String

func (d AwsAccount) String() string

Convert AwsAccount to a string

type AwsAccountCreateOrUpdateRequest

type AwsAccountCreateOrUpdateRequest struct {
	Name    string `json:"name"`
	RoleArn string `json:"roleArn"`
}

func (AwsAccountCreateOrUpdateRequest) String

type AwsAccountData

type AwsAccountData struct {
	Grid           string                   `json:"grid,omitempty"`
	LinkKey        string                   `json:"linkKey,omitempty"`
	Name           string                   `json:"name,omitempty"`
	Text           []map[string]interface{} `json:"text,omitempty"`
	Edges          []map[string]interface{} `json:"edges,omitempty"`
	Icons          []map[string]interface{} `json:"icons,omitempty"`
	Nodes          []map[string]interface{} `json:"nodes,omitempty"`
	Groups         []map[string]interface{} `json:"groups,omitempty"`
	Images         []map[string]interface{} `json:"images,omitempty"`
	Surfaces       []map[string]interface{} `json:"surfaces,omitempty"`
	Connectors     []map[string]interface{} `json:"connectors,omitempty"`
	DisabledLayers []map[string]interface{} `json:"disabledLayers,omitempty"`
}

type AwsAccountDataEdge

type AwsAccountDataEdge struct {
	Id     string `json:"id,omitempty"`
	To     string `json:"to,omitempty"`
	From   string `json:"from,omitempty"`
	Type   string `json:"type,omitempty"`
	Color  string `json:"color,omitempty"`
	Width  int    `json:"width,omitempty"`
	Dashed bool   `json:"dashed,omitempty"`
}

type AwsAccountDataText

type AwsAccountDataText struct {
	Id        string                   `json:"id,omitempty"`
	Text      string                   `json:"text,omitempty"`
	Type      string                   `json:"type,omitempty"`
	Color     string                   `json:"color,omitempty"`
	TextSize  int                      `json:"textSize,omitempty"`
	Direction string                   `json:"direction,omitempty"`
	Isometric bool                     `json:"isometric,omitempty"`
	MapPos    AwsAccountDataTextMapPos `json:"mapPos,omitempty"`
}

type AwsAccountDataTextMapPos

type AwsAccountDataTextMapPos struct {
	RelTo string `json:"relTo,omitempty"`
	// contains filtered or unexported fields
}

type AwsAccountIamParameters

type AwsAccountIamParameters struct {
	AccountId     string `json:"accountId"`
	ExternalId    string `json:"externalId"`
	AwsConsoleUrl string `json:"awsConsoleUrl"`
}

func (AwsAccountIamParameters) String

func (d AwsAccountIamParameters) String() string

type AwsAccountSnapshot

type AwsAccountSnapshot struct {
	ContentType        string
	Content            *bytes.Buffer
	SnapshotParameters *AwsAccountSnapshotParameters
}

type AwsAccountSnapshotParameters

type AwsAccountSnapshotParameters struct {
	Autoconnect bool     `url:"autoconnect,omitempty"`
	Exclude     []string `url:"exclude,omitempty,comma"`
	Filter      string   `url:"filter,omitempty"`
	Grid        bool     `url:"grid,omitempty"`
	Height      int      `url:"height,omitempty"`
	Label       bool     `url:"label,omitempty"`
	Landscape   bool     `url:"landscape,omitempty"`
	PaperSize   string   `url:"paperSize,omitempty"`
	Projection  string   `url:"projection,omitempty"`
	Scale       float32  `url:"scale,omitempty"`
	Transparent bool     `url:"transparent,omitempty"`
	Width       int      `url:"width,omitempty"`
}

type AwsAccountSnapshotRequest

type AwsAccountSnapshotRequest struct {
	Format             string
	Region             string
	SnapshotParameters *AwsAccountSnapshotParameters
}

func (AwsAccountSnapshotRequest) String

func (d AwsAccountSnapshotRequest) String() string

type AwsAccountsRoot

type AwsAccountsRoot struct {
	AwsAccounts []AwsAccount `json:"accounts"`
}

type AwsAccountsServiceOp

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

AwsAccountsServiceOp handles communication with the AwsAccount related methods of the Cloudcraft API.

func (*AwsAccountsServiceOp) Create

Create AwsAccount

func (*AwsAccountsServiceOp) Delete

func (s *AwsAccountsServiceOp) Delete(ctx context.Context, awsAccountID string) (*Response, error)

Delete AwsAccount.

func (*AwsAccountsServiceOp) Get

func (s *AwsAccountsServiceOp) Get(ctx context.Context, awsAccountID string) (*AwsAccount, *Response, error)

Get individual AwsAccount.

func (*AwsAccountsServiceOp) IamParameters

Get AwsAccount IAM Parameters.

func (*AwsAccountsServiceOp) List

List all AwsAccounts.

func (*AwsAccountsServiceOp) Snapshot

func (s *AwsAccountsServiceOp) Snapshot(ctx context.Context, awsAccountID string, snapshotRequest *AwsAccountSnapshotRequest) (*AwsAccountSnapshot, *Response, error)

Snapshot AwsAccount.

func (*AwsAccountsServiceOp) Update

func (s *AwsAccountsServiceOp) Update(ctx context.Context, awsAccountID string, updateRequest *AwsAccountCreateOrUpdateRequest) (*AwsAccount, *Response, error)

Update AwsAccount

type Blueprint

type Blueprint struct {
	Id         string         `json:"id,omitempty"`
	Name       string         `json:"name,omitempty"`
	CreatedAt  time.Time      `json:"createdAt,omitempty"`
	UpdatedAt  time.Time      `json:"createdAt,omitempty"`
	CreatorId  string         `json:"CreatorId,omitempty"`
	LastUserId string         `json:"LastUserId,omitempty"`
	Data       *BlueprintData `json:data,omitempty`
}

Blueprint represents a Cloudcraft Blueprint

func (Blueprint) String

func (d Blueprint) String() string

Convert Blueprint to a string

type BlueprintCreateRequest

type BlueprintCreateRequest struct {
	Data *BlueprintData `json:"data"`
}

BlueprintCreateRequest represents a request to create a Blueprint.

func (BlueprintCreateRequest) String

func (d BlueprintCreateRequest) String() string

type BlueprintData

type BlueprintData struct {
	Grid           string                   `json:"grid,omitempty"`
	LinkKey        string                   `json:"linkKey,omitempty"`
	Name           string                   `json:"name,omitempty"`
	Text           []map[string]interface{} `json:"text,omitempty"`
	Edges          []map[string]interface{} `json:"edges,omitempty"`
	Icons          []map[string]interface{} `json:"icons,omitempty"`
	Nodes          []map[string]interface{} `json:"nodes,omitempty"`
	Groups         []map[string]interface{} `json:"groups,omitempty"`
	Images         []map[string]interface{} `json:"images,omitempty"`
	Surfaces       []map[string]interface{} `json:"surfaces,omitempty"`
	Connectors     []map[string]interface{} `json:"connectors,omitempty"`
	DisabledLayers []map[string]interface{} `json:"disabledLayers,omitempty"`
}

type BlueprintExportParameters

type BlueprintExportParameters struct {
	Grid        bool    `url:"grid"`
	Height      int     `url:"height"`
	Landscape   bool    `url:"landscape"`
	PaperSize   string  `url:"paperSize"`
	Scale       float32 `url:"scale"`
	Transparent bool    `url:"transparent"`
	Width       int     `url:"width"`
}

type BlueprintExportRequest

type BlueprintExportRequest struct {
	Format           string
	ExportParameters *BlueprintExportParameters
}

func (BlueprintExportRequest) String

func (d BlueprintExportRequest) String() string

type BlueprintImage

type BlueprintImage struct {
	ContentType      string
	Content          *bytes.Buffer
	ExportParameters *BlueprintExportParameters
}

type BlueprintUpdateRequest

type BlueprintUpdateRequest struct {
	Data *BlueprintData `json:"data"`
}

BlueprintCreateRequest represents a request to update a Blueprint.

func (BlueprintUpdateRequest) String

func (d BlueprintUpdateRequest) String() string

type BlueprintsRoot

type BlueprintsRoot struct {
	Blueprints []Blueprint `json:"blueprints"`
}

type BlueprintsService

BlueprintsService is an interface for interfacing with the Blueprints endpoints of the Cloudcraft API See: https://developers.cloudcraft.co/#dbc3d135-6447-47f2-b043-bae65b722246

type BlueprintsServiceOp

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

BlueprintsServiceOp handles communication with the Blueprint related methods of the Cloudcraft API.

func (*BlueprintsServiceOp) Create

func (s *BlueprintsServiceOp) Create(ctx context.Context, createRequest *BlueprintCreateRequest) (*Blueprint, *Response, error)

Create Blueprint

func (*BlueprintsServiceOp) Delete

func (s *BlueprintsServiceOp) Delete(ctx context.Context, blueprintId string) (*Response, error)

Delete Blueprint.

func (*BlueprintsServiceOp) Export

func (s *BlueprintsServiceOp) Export(ctx context.Context, blueprintId string, exportRequest *BlueprintExportRequest) (*BlueprintImage, *Response, error)

imageMediaType = "image/svg+xml, image/png, application/pdf, application/xml, application/json" Export Blueprint.

func (*BlueprintsServiceOp) Get

func (s *BlueprintsServiceOp) Get(ctx context.Context, blueprintId string) (*Blueprint, *Response, error)

Get individual Blueprint.

func (*BlueprintsServiceOp) List

List all Blueprints.

func (*BlueprintsServiceOp) Update

func (s *BlueprintsServiceOp) Update(ctx context.Context, blueprintId string, updateRequest *BlueprintUpdateRequest) (*Blueprint, *Response, error)

Update Blueprint

type Client

type Client struct {

	// Base URL for API requests.
	BaseURL *url.URL

	// User agent for client
	UserAgent string

	// Services used for communicating with the API
	AwsAccounts AwsAccountsService
	Blueprints  BlueprintsService
	Users       UsersService
	// contains filtered or unexported fields
}

func New

func New(httpClient *http.Client, opts ...ClientOpt) (*Client, error)

New returns a new Cloudcraft API client instance.

func NewClient

func NewClient(httpClient *http.Client) *Client

NewClient returns a new Cloudcraft API client, using the given http.Client to perform all requests.

Users who wish to pass their own http.Client should use this method. If you're in need of further customization, the godo.New method allows more options, such as setting a custom URL or a custom user agent string.

func NewFromToken

func NewFromToken(token string) *Client

NewFromToken returns a new Cloudcraft API client with the given API token.

func (*Client) Do

func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*Response, error)

Do sends an API request and returns the API response. The API response is JSON decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred. If v implements the io.Writer interface, the raw response will be written to v, without attempting to decode it.

func (*Client) NewRequest

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

NewRequest creates an API request. A relative URL can be provided in urlStr, which will be resolved to the BaseURL of the Client. Relative URLS should always be specified without a preceding slash. If specified, the value pointed to by body is JSON encoded and included in as the request body.

func (*Client) OnRequestCompleted

func (c *Client) OnRequestCompleted(rc RequestCompletionCallback)

OnRequestCompleted sets the DO API request completion callback

type ClientOpt

type ClientOpt func(*Client) error

ClientOpt are options for New.

func SetBaseURL

func SetBaseURL(bu string) ClientOpt

SetBaseURL is a client option for setting the base URL.

func SetRequestHeaders

func SetRequestHeaders(headers map[string]string) ClientOpt

SetRequestHeaders sets optional HTTP headers on the client that are sent on each HTTP request.

func SetUserAgent

func SetUserAgent(ua string) ClientOpt

SetUserAgent is a client option for setting the user agent.

type ErrorResponse

type ErrorResponse struct {
	// HTTP response that caused this error
	Response *http.Response

	// Error message
	Message string `json:"error"`

	// Error code
	Code int `json:"code"`
}

An ErrorResponse reports the error caused by an API request

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

type RequestCompletionCallback

type RequestCompletionCallback func(*http.Request, *http.Response)

type ResourceWithURN

type ResourceWithURN interface {
	URN() string
}

ResourceWithURN is an interface for interfacing with the types that implement the URN method.

type Response

type Response struct {
	*http.Response
}

Response is a Cloudcraft response. This wraps the standard http.Response returned from Cloudcraft.

type Timestamp

type Timestamp struct {
	time.Time
}

Timestamp represents a time that can be unmarshalled from a JSON string formatted as either an RFC3339 or Unix timestamp. All exported methods of time.Time can be called on Timestamp.

func (Timestamp) Equal

func (t Timestamp) Equal(u Timestamp) bool

Equal reports whether t and u are equal based on time.Equal

func (Timestamp) String

func (t Timestamp) String() string

func (*Timestamp) UnmarshalJSON

func (t *Timestamp) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface. Time is expected in RFC3339 or Unix format.

type User

type User struct {
	ID         string    `json:"id,omitempty"`
	Name       string    `json:"name,omitempty"`
	CreatedAt  time.Time `json:"createdAt,omitempty"`
	UpdatedAt  time.Time `json:"createdAt,omitempty"`
	CreatorId  string    `json:"CreatorId,omitempty"`
	LastUserId string    `json:"LastUserId,omitempty"`
}

User represents a Cloudcraft User

func (User) String

func (d User) String() string

Convert User to a string

type UsersService

type UsersService interface {
	Me(context.Context) (*User, *Response, error)
}

UsersService is an interface for interfacing with the Users endpoints of the Cloudcraft API See: https://developers.cloudcraft.co/#398fa0e6-3139-41e6-a5c2-3b9a31e15d6d

type UsersServiceOp

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

UsersServiceOp handles communication with the User related methods of the Cloudcraft API.

func (*UsersServiceOp) Get

func (s *UsersServiceOp) Get(ctx context.Context, userID string) (*User, *Response, error)

Get an individual user. Currently only "me" supported.

func (*UsersServiceOp) Me

func (s *UsersServiceOp) Me(ctx context.Context) (*User, *Response, error)

Jump to

Keyboard shortcuts

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