nb

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2019 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package nb makes client API calls to noobaa servers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindPortByName

func FindPortByName(srv *corev1.Service, portName string) *corev1.ServicePort

FindPortByName returns the port in the service that matches the given name.

func GetAPIPortName

func GetAPIPortName(api string) string

GetAPIPortName maps every noobaa api name to the service port name that serves it.

Types

type APIRouter

type APIRouter interface {
	GetAddress(api string) string
}

APIRouter should be able to map noobaa api names to actual addresses See implementations below: APIRouterNodePort, APIRouterPodPort, APIRouterServicePort

type APIRouterNodePort

type APIRouterNodePort struct {
	ServiceMgmt *corev1.Service
	NodeIP      string
}

APIRouterNodePort uses the service node port to route to NodeIP:NodePorts

func (*APIRouterNodePort) GetAddress

func (r *APIRouterNodePort) GetAddress(api string) string

GetAddress implements the router

type APIRouterPodPort

type APIRouterPodPort struct {
	ServiceMgmt *corev1.Service
	PodIP       string
}

APIRouterPodPort uses the service target port to route to PodIP:TargetPort

func (*APIRouterPodPort) GetAddress

func (r *APIRouterPodPort) GetAddress(api string) string

GetAddress implements the router

type APIRouterServicePort

type APIRouterServicePort struct {
	ServiceMgmt *corev1.Service
}

APIRouterServicePort uses the service port to route to Srv.Namespace:Port

func (*APIRouterServicePort) GetAddress

func (r *APIRouterServicePort) GetAddress(api string) string

GetAddress implements the router

type Client

type Client interface {
	SetAuthToken(token string)
	GetAuthToken() string

	ReadAuthAPI() (ReadAuthReply, error)

	ListAccountsAPI() (ListAccountsReply, error)
	ListBucketsAPI() (ListBucketsReply, error)

	CreateAuthAPI(CreateAuthParams) (CreateAuthReply, error)
	CreateSystemAPI(CreateSystemParams) (CreateSystemReply, error)
	CreateBucketAPI(CreateBucketParams) (CreateBucketReply, error)

	DeleteBucketAPI(DeleteBucketParams) (DeleteBucketReply, error)
}

Client is the interface providing typed noobaa API calls

func NewClient

func NewClient(router APIRouter) Client

NewClient initializes an RPCClient with defaults

type CreateAuthParams added in v1.0.0

type CreateAuthParams struct {
	System   string `json:"system"`
	Role     string `json:"role"`
	Email    string `json:"email"`
	Password string `json:"password"`
}

CreateAuthParams is the params of auth_api.create_auth()

type CreateAuthReply added in v1.0.0

type CreateAuthReply struct {
	Token string `json:"token"`
}

CreateAuthReply is the reply of auth_api.create_auth()

type CreateBucketParams added in v1.0.0

type CreateBucketParams struct {
	Name string `json:"name"`
}

CreateBucketParams is the params of bucket_api.create_bucket()

type CreateBucketReply added in v1.0.0

type CreateBucketReply struct {
}

CreateBucketReply is the reply of bucket_api.create_bucket()

type CreateSystemParams

type CreateSystemParams struct {
	Name     string `json:"name"`
	Email    string `json:"email"`
	Password string `json:"password"`
}

CreateSystemParams is the params of system_api.create_system()

type CreateSystemReply

type CreateSystemReply struct {
	Token         string `json:"token"`
	OperatorToken string `json:"operator_token"`
}

CreateSystemReply is the reply of system_api.create_system()

type DeleteBucketParams added in v1.0.0

type DeleteBucketParams struct {
	Name string `json:"name"`
}

DeleteBucketParams is the params of bucket_api.delete_bucket()

type DeleteBucketReply added in v1.0.0

type DeleteBucketReply struct {
}

DeleteBucketReply is the reply of bucket_api.delete_bucket()

type ListAccountsReply

type ListAccountsReply struct {
	Accounts []struct {
		Name       string `json:"name"`
		Email      string `json:"email"`
		AccessKeys []struct {
			AccessKey string `json:"access_key"`
			SecretKey string `json:"secret_key"`
		} `json:"access_keys"`
	} `json:"accounts"`
}

ListAccountsReply is the reply to account_api.list_accounts()

type ListBucketsReply added in v1.0.0

type ListBucketsReply struct {
	Buckets []struct {
		Name string `json:"name"`
	} `json:"buckets"`
}

type RPCClient

type RPCClient struct {
	Router     APIRouter
	HTTPClient http.Client
	AuthToken  string
}

RPCClient makes API calls to noobaa. Requests to noobaa are plain http requests with json request and json response.

func (*RPCClient) Call

func (c *RPCClient) Call(req RPCRequest, res RPCResponseIfc) error

Call an API method to noobaa. The response type should be defined to include RPCResponseIfc inline. This is needed in order for json.Unmarshal() to decode into the reply structure.

func (*RPCClient) CreateAuthAPI added in v1.0.0

func (c *RPCClient) CreateAuthAPI(params CreateAuthParams) (CreateAuthReply, error)

CreateAuthAPI calls auth_api.create_auth()

func (*RPCClient) CreateBucketAPI added in v1.0.0

func (c *RPCClient) CreateBucketAPI(params CreateBucketParams) (CreateBucketReply, error)

CreateBucketAPI calls bucket_api.create_bucket()

func (*RPCClient) CreateSystemAPI

func (c *RPCClient) CreateSystemAPI(params CreateSystemParams) (CreateSystemReply, error)

CreateSystemAPI calls system_api.create_system()

func (*RPCClient) DeleteBucketAPI added in v1.0.0

func (c *RPCClient) DeleteBucketAPI(params DeleteBucketParams) (DeleteBucketReply, error)

DeleteBucketAPI calls bucket_api.delete_bucket()

func (*RPCClient) GetAuthToken added in v1.0.0

func (c *RPCClient) GetAuthToken() string

GetAuthToken is getting the client token for next calls

func (*RPCClient) ListAccountsAPI

func (c *RPCClient) ListAccountsAPI() (ListAccountsReply, error)

ListAccountsAPI calls account_api.list_accounts()

func (*RPCClient) ListBucketsAPI added in v1.0.0

func (c *RPCClient) ListBucketsAPI() (ListBucketsReply, error)

ListBucketsAPI calls bucket_api.list_buckets()

func (*RPCClient) ReadAuthAPI added in v1.0.0

func (c *RPCClient) ReadAuthAPI() (ReadAuthReply, error)

CreateAuthAPI calls auth_api.read_auth()

func (*RPCClient) SetAuthToken

func (c *RPCClient) SetAuthToken(token string)

SetAuthToken is setting the client token for next calls

type RPCError

type RPCError struct {
	RPCCode string `json:"rpc_code,omitempty"`
	Message string `json:"message"`
}

RPCError is a struct sent by noobaa servers to denote an error response.

func (*RPCError) Error

func (e *RPCError) Error() string

Error is implementing the standard error type interface

type RPCRequest

type RPCRequest struct {
	API       string      `json:"api"`
	Method    string      `json:"method"`
	AuthToken string      `json:"auth_token,omitempty"`
	Params    interface{} `json:"params,omitempty"`
}

RPCRequest is the structure encoded in every request

type RPCResponse

type RPCResponse struct {
	Op        string    `json:"op"`
	RequestID string    `json:"reqid"`
	Took      float64   `json:"took"`
	Error     *RPCError `json:"error,omitempty"`
}

RPCResponse is the structure encoded in every response Specific API response structures should include this inline, and add the standard Reply field with the specific fields. Refer to examples.

func (*RPCResponse) Response

func (r *RPCResponse) Response() *RPCResponse

Response is implementing the RPCResponseIfc interface

type RPCResponseIfc

type RPCResponseIfc interface {
	Response() *RPCResponse
}

RPCResponseIfc is the interface for response structs. RPCResponse is the only real implementor of it.

type ReadAuthReply added in v1.0.0

type ReadAuthReply struct {
	Account struct {
		Name               string `json:"name"`
		Email              string `json:"email"`
		IsSupport          bool   `json:"is_support"`
		MustChangePassword bool   `json:"must_change_password"`
	} `json:"account"`
	System struct {
		Name string `json:"name"`
	} `json:"system"`
	AuthorizedBy string                 `json:"authorized_by"`
	Role         string                 `json:"role"`
	Extra        map[string]interface{} `json:"extra"`
}

ReadAuthReply is the reply of auth_api.read_auth()

Jump to

Keyboard shortcuts

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