Documentation
¶
Index ¶
- Constants
- Variables
- func Ed25519PubKeyToDID(pubKey ed25519.PublicKey) (string, error)
- type Client
- func (c *Client) CreateServices(ctx context.Context, request CreateServiceRequest, nonce string) ([]Service, error)
- func (c *Client) DID() string
- func (c *Client) GetService(ctx context.Context, id uint, nonce string) (*Service, error)
- func (c *Client) ListServices(ctx context.Context, nonce string) ([]Service, error)
- func (c *Client) Plans(ctx context.Context) ([]Plan, error)
- func (c *Client) RawRequest(ctx context.Context, method, path string, body []byte, nonce string, ts int64) (*ProxyResponse, error)
- func (c *Client) ServiceAction(ctx context.Context, action ServiceAction, id uint, nonce string) error
- func (c *Client) SetGatewayAddr(addr string) error
- type CreateServiceRequest
- type Endpoint
- type Os
- type Plan
- type PlanType
- type ProxyRequest
- type ProxyResponse
- type Service
- type ServiceAction
Constants ¶
const ( // ServiceStart starts a service ServiceStart = "START" // ServiceShutdown stops a service ServiceShutdown = "SHUTDOWN" // ServiceRestart restarts a service ServiceRestart = "RESTART" // ServiceReinstall reinstalls the service to its initial state ServiceReinstall = "REINSTALL" // ServiceDelete destroys the service ServiceDelete = "DELETE" )
const ( Ubuntu24_04 = "Ubuntu 24.04 LTS" Ubuntu22_04 = "Ubuntu 22.04 LTS" Debian11 = "Debian 11" )
const ProtocolID = "/serverista-proxy/1.0.0"
ProtocolID to communicate with p2p-gateway.
Variables ¶
var ( // PlansEndpoint is a public endpoint PlansEndpoint = Endpoint{ Method: "GET", Uri: "/v1/plans", } // ListUserServicesEndpoint ListUserServicesEndpoint = Endpoint{ Method: "GET", Uri: "/v1/services", } // GetUserServiceEndpoint GetUserServiceEndpoint = Endpoint{ Method: "GET", Uri: "/v1/services/%d", } // CreateServicesEndpoint CreateServicesEndpoint = Endpoint{ Method: "POST", Uri: "/v1/services", } // ManageServiceEndpoint ManageServiceEndpoint = Endpoint{ Method: "POST", Uri: "/v1/services/%d/management", } )
var (
ErrNoPermissions = errors.New("no permission")
)
Functions ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client hold the structures to sign messages and communicate with the p2p-gateway.
func New ¶
New creates a new client given a libp2p host which will be used to connect and send a message to the remote protocol. in the params you can use any ed25519 private key to sign the messages. This should be the private key that the DID was derived from and entered in serverista IAM DID Key.
func (*Client) CreateServices ¶
func (c *Client) CreateServices(ctx context.Context, request CreateServiceRequest, nonce string) ([]Service, error)
CreateServices creates a new service given an optional custom name plan id, os type, number of instances and a public key.
func (*Client) GetService ¶
Get a specific service.
func (*Client) ListServices ¶
ListServices returns a list of available services.
func (*Client) RawRequest ¶
func (c *Client) RawRequest(ctx context.Context, method, path string, body []byte, nonce string, ts int64) (*ProxyResponse, error)
RawRequest sends a raw request given the method, path, body and other args
func (*Client) ServiceAction ¶
func (c *Client) ServiceAction(ctx context.Context, action ServiceAction, id uint, nonce string) error
ServiceAction performs an action such as start, shutdown, restart, reinstall and delete on a service.
func (*Client) SetGatewayAddr ¶
SetGatewayAddr sets the gateway address.
type CreateServiceRequest ¶
type CreateServiceRequest struct {
PlanID uint `json:"plan_id"`
OS Os `json:"os"`
Amount int `json:"amount"`
SSHPublicKey string `json:"ssh_public_key"`
Name string `json:"name"`
}
CreateServiceRequest is the service creation payload.
type ProxyRequest ¶
type ProxyRequest struct {
Method string `json:"method"`
Path string `json:"path"`
Headers map[string]string `json:"headers,omitempty"`
Body []byte `json:"body,omitempty"`
}
ProxyRequest represents the payload to send to the p2p-gateway.
type ProxyResponse ¶
type ProxyResponse struct {
Status int `json:"status"`
Headers map[string]string `json:"headers,omitempty"`
Body []byte `json:"body,omitempty"`
Error string `json:"error,omitempty"`
}
ProxyResponse is the response from p2p-gateway.
type Service ¶
type Service struct {
ID uint `json:"id"`
AccountID uint `json:"account_id"`
UserID uint `json:"user_id"`
PlanID uint `json:"plan_id"`
Data json.RawMessage `json:"data"`
Status string `json:"status"`
UserDefinedName string `json:"user_defined_name"`
FirewallEnabled bool `json:"firewall_enabled"`
UniqueID uint `json:"unique_id"`
IP string `json:"ip"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type ServiceAction ¶
type ServiceAction string
ServiceAction represents the management action on a service