api

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2023 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAPIKeyIDRequired   = errors.New("apikey id is required for this endpoint")
	ErrMemberIDRequired   = errors.New("member id is required for this endpoint")
	ErrProjectIDRequired  = errors.New("project id is required for this endpoint")
	ErrTenantIDRequired   = errors.New("tenant id is required for this endpoint")
	ErrTopicIDRequired    = errors.New("topic id is required for this endpoint")
	ErrInvalidTenantField = errors.New("invalid tenant field")
)

Functions

func NotAllowed

func NotAllowed(c *gin.Context)

NotAllowed returns a JSON 405 response for the API.

func NotFound

func NotFound(c *gin.Context)

NotFound returns a JSON response for the API. NOTE: we know it's weird to put server-side handlers like NotFound and NotAllowed here in the client/api side package but it unifies where we keep our error handling mechanisms.

Types

type APIKey added in v0.2.0

type APIKey struct {
	ID           string   `json:"id,omitempty"`
	ClientID     string   `json:"client_id"`
	ClientSecret string   `json:"client_secret,omitempty"`
	Name         string   `json:"name"`
	Owner        string   `json:"owner,omitempty"`
	Permissions  []string `json:"permissions,omitempty"`
	Created      string   `json:"created,omitempty"`
	Modified     string   `json:"modified,omitempty"`
}

type APIKeyPage added in v0.2.0

type APIKeyPage struct {
	APIKeys       []*APIKey `json:"api_keys"`
	PrevPageToken string    `json:"prev_page_token"`
	NextPageToken string    `json:"next_page_token"`
}

type APIv1

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

APIv1 implements the TenantClient interface

func (*APIv1) APIKeyCreate added in v0.3.0

func (s *APIv1) APIKeyCreate(ctx context.Context, in *APIKey) (out *APIKey, err error)

func (*APIv1) APIKeyDelete added in v0.2.0

func (s *APIv1) APIKeyDelete(ctx context.Context, id string) (err error)

func (*APIv1) APIKeyDetail added in v0.2.0

func (s *APIv1) APIKeyDetail(ctx context.Context, id string) (out *APIKey, err error)

func (*APIv1) APIKeyList added in v0.2.0

func (s *APIv1) APIKeyList(ctx context.Context, in *PageQuery) (out *APIKeyPage, err error)

func (*APIv1) APIKeyUpdate added in v0.2.0

func (s *APIv1) APIKeyUpdate(ctx context.Context, in *APIKey) (out *APIKey, err error)

func (*APIv1) Do

func (s *APIv1) Do(req *http.Request, data interface{}, checkStatus bool) (rep *http.Response, err error)

Do executes an http request against the server, performs error checking, and deserializes response data into the specified struct.

func (*APIv1) Login added in v0.3.0

func (s *APIv1) Login(ctx context.Context, in *LoginRequest) (out *AuthReply, err error)

func (*APIv1) MemberCreate added in v0.2.0

func (s *APIv1) MemberCreate(ctx context.Context, in *Member) (out *Member, err error)

func (*APIv1) MemberDelete added in v0.2.0

func (s *APIv1) MemberDelete(ctx context.Context, id string) (err error)

func (*APIv1) MemberDetail added in v0.2.0

func (s *APIv1) MemberDetail(ctx context.Context, id string) (out *Member, err error)

func (*APIv1) MemberList added in v0.2.0

func (s *APIv1) MemberList(ctx context.Context, in *PageQuery) (out *MemberPage, err error)

func (*APIv1) MemberUpdate added in v0.2.0

func (s *APIv1) MemberUpdate(ctx context.Context, in *Member) (out *Member, err error)

func (*APIv1) NewRequest

func (s *APIv1) NewRequest(ctx context.Context, method, path string, data interface{}, params *url.Values) (req *http.Request, err error)

func (*APIv1) ProjectAPIKeyCreate added in v0.2.0

func (s *APIv1) ProjectAPIKeyCreate(ctx context.Context, id string, in *APIKey) (out *APIKey, err error)

func (*APIv1) ProjectAPIKeyList added in v0.2.0

func (s *APIv1) ProjectAPIKeyList(ctx context.Context, id string, in *PageQuery) (out *ProjectAPIKeyPage, err error)

func (*APIv1) ProjectCreate added in v0.2.0

func (s *APIv1) ProjectCreate(ctx context.Context, in *Project) (out *Project, err error)

func (*APIv1) ProjectDelete added in v0.2.0

func (s *APIv1) ProjectDelete(ctx context.Context, id string) (err error)

func (*APIv1) ProjectDetail added in v0.2.0

func (s *APIv1) ProjectDetail(ctx context.Context, id string) (out *Project, err error)

func (*APIv1) ProjectList added in v0.2.0

func (s *APIv1) ProjectList(ctx context.Context, in *PageQuery) (out *ProjectPage, err error)

func (*APIv1) ProjectTopicCreate added in v0.2.0

func (s *APIv1) ProjectTopicCreate(ctx context.Context, id string, in *Topic) (out *Topic, err error)

func (*APIv1) ProjectTopicList added in v0.2.0

func (s *APIv1) ProjectTopicList(ctx context.Context, id string, in *PageQuery) (out *ProjectTopicPage, err error)

func (*APIv1) ProjectUpdate added in v0.2.0

func (s *APIv1) ProjectUpdate(ctx context.Context, in *Project) (out *Project, err error)

func (*APIv1) Refresh added in v0.3.0

func (s *APIv1) Refresh(ctx context.Context, in *RefreshRequest) (out *AuthReply, err error)

func (*APIv1) Register added in v0.3.0

func (s *APIv1) Register(ctx context.Context, in *RegisterRequest) (err error)

func (*APIv1) SetCSRFProtect added in v0.2.0

func (c *APIv1) SetCSRFProtect(protect bool) error

SetCSRFProtect is a helper function to set CSRF cookies on the client. This is not possible in a browser because of the HttpOnly flag. This method should only be used for testing purposes and an error is returned if the URL is not localhost. For live clients - the server should set these cookies. If protect is false, then the cookies are removed from the client by setting the cookies to an empty slice.

func (*APIv1) SetCredentials added in v0.2.0

func (c *APIv1) SetCredentials(token string)

SetCredentials is a helper function for external users to override credentials at runtime by directly passing in the token, which is useful for testing. TODO: Pass in a credentials interface instead of the token string.

func (*APIv1) SignUp

func (s *APIv1) SignUp(ctx context.Context, in *ContactInfo) (err error)

func (*APIv1) Status

func (s *APIv1) Status(ctx context.Context) (out *StatusReply, err error)

func (*APIv1) TenantCreate added in v0.1.1

func (s *APIv1) TenantCreate(ctx context.Context, in *Tenant) (out *Tenant, err error)

func (*APIv1) TenantDelete added in v0.2.0

func (s *APIv1) TenantDelete(ctx context.Context, id string) (err error)

func (*APIv1) TenantDetail added in v0.2.0

func (s *APIv1) TenantDetail(ctx context.Context, id string) (out *Tenant, err error)

func (*APIv1) TenantList added in v0.1.1

func (s *APIv1) TenantList(ctx context.Context, in *PageQuery) (out *TenantPage, err error)

func (*APIv1) TenantMemberCreate added in v0.2.0

func (s *APIv1) TenantMemberCreate(ctx context.Context, id string, in *Member) (out *Member, err error)

func (*APIv1) TenantMemberList added in v0.2.0

func (s *APIv1) TenantMemberList(ctx context.Context, id string, in *PageQuery) (out *TenantMemberPage, err error)

func (*APIv1) TenantProjectCreate added in v0.2.0

func (s *APIv1) TenantProjectCreate(ctx context.Context, id string, in *Project) (out *Project, err error)

func (*APIv1) TenantProjectList added in v0.2.0

func (s *APIv1) TenantProjectList(ctx context.Context, id string, in *PageQuery) (out *TenantProjectPage, err error)

func (*APIv1) TenantStats added in v0.3.0

func (s *APIv1) TenantStats(ctx context.Context, id string) (out *TenantStats, err error)

func (*APIv1) TenantUpdate added in v0.2.0

func (s *APIv1) TenantUpdate(ctx context.Context, in *Tenant) (out *Tenant, err error)

func (*APIv1) TopicDelete

func (s *APIv1) TopicDelete(ctx context.Context, id string) (err error)

func (*APIv1) TopicDetail

func (s *APIv1) TopicDetail(ctx context.Context, id string) (out *Topic, err error)

func (*APIv1) TopicList

func (s *APIv1) TopicList(ctx context.Context, in *PageQuery) (out *TopicPage, err error)

func (*APIv1) TopicUpdate added in v0.2.0

func (s *APIv1) TopicUpdate(ctx context.Context, in *Topic) (out *Topic, err error)

type AuthReply added in v0.3.0

type AuthReply struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
}

type ClientOption

type ClientOption func(c *APIv1) error

ClientOptions allows us to configure the APIv1 client when it is created.

func WithClient

func WithClient(client *http.Client) ClientOption

type ContactInfo

type ContactInfo struct {
	FirstName            string `json:"firstName"`
	LastName             string `json:"lastName"`
	Email                string `json:"email"`
	Country              string `json:"country"`
	Title                string `json:"title"`
	Organization         string `json:"organization"`
	CloudServiceProvider string `json:"cloudServiceProvider"`
}

ContactInfo allows users to sign up for email notifications from SendGrid and is specifically used to allow users to request Ensign Private Beta access.

type LoginRequest added in v0.3.0

type LoginRequest struct {
	Email    string `json:"email"`
	Password string `json:"password"`
}

type Member added in v0.2.0

type Member struct {
	ID   string `json:"id" uri:"id"`
	Name string `json:"name"`
	Role string `json:"role"`
}

type MemberPage added in v0.2.0

type MemberPage struct {
	Members       []*Member `json:"members"`
	PrevPageToken string    `json:"prev_page_token"`
	NextPageToken string    `json:"next_page_token"`
}

type PageQuery added in v0.1.1

type PageQuery struct {
	PageSize      uint32 `url:"page_size,omitempty"`
	NextPageToken string `url:"next_page_token,omitempty"`
}

type Project added in v0.2.0

type Project struct {
	ID   string `json:"id" uri:"id"`
	Name string `json:"name"`
}

type ProjectAPIKeyPage added in v0.2.0

type ProjectAPIKeyPage struct {
	ProjectID     string    `json:"project_id"`
	APIKeys       []*APIKey `json:"api_keys"`
	PrevPageToken string    `json:"prev_page_token"`
	NextPageToken string    `json:"next_page_token"`
}

type ProjectPage added in v0.2.0

type ProjectPage struct {
	Projects      []*Project `json:"projects"`
	PrevPageToken string     `json:"prev_page_token"`
	NextPageToken string     `json:"next_page_token"`
}

type ProjectTopicPage added in v0.2.0

type ProjectTopicPage struct {
	ProjectID     string   `json:"project_id"`
	Topics        []*Topic `json:"topics"`
	PrevPageToken string   `json:"prev_page_token"`
	NextPageToken string   `json:"next_page_token"`
}

type RefreshRequest added in v0.3.0

type RefreshRequest struct {
	RefreshToken string `json:"refresh_token"`
}

type RegisterRequest added in v0.3.0

type RegisterRequest struct {
	Name         string `json:"name"`
	Email        string `json:"email"`
	Password     string `json:"password"`
	PwCheck      string `json:"pwcheck"`
	Organization string `json:"organization"`
	Domain       string `json:"domain"`
	AgreeToS     bool   `json:"terms_agreement"`
	AgreePrivacy bool   `json:"privacy_agreement"`
}

func (*RegisterRequest) Validate added in v0.3.0

func (r *RegisterRequest) Validate() error

Validate ensures that all required fields are present without performing complete validation checks such as the password strength.

type Reply

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

Reply contains standard fields that are used for generic API responses and errors.

func ErrorResponse

func ErrorResponse(err interface{}) Reply

Constructs a new response for an error or returns unsuccessful.

type StatusReply

type StatusReply struct {
	Status  string `json:"status"`
	Uptime  string `json:"uptime,omitempty"`
	Version string `json:"version,omitempty"`
}

Returned on status requests.

type Tenant added in v0.1.1

type Tenant struct {
	ID              string `json:"id" uri:"id"`
	Name            string `json:"name"`
	EnvironmentType string `json:"environment_type"`
}

type TenantClient

type TenantClient interface {
	Status(context.Context) (*StatusReply, error)
	SignUp(context.Context, *ContactInfo) error

	Register(context.Context, *RegisterRequest) error
	Login(context.Context, *LoginRequest) (*AuthReply, error)
	Refresh(context.Context, *RefreshRequest) (*AuthReply, error)

	TenantList(context.Context, *PageQuery) (*TenantPage, error)
	TenantCreate(context.Context, *Tenant) (*Tenant, error)
	TenantDetail(ctx context.Context, id string) (*Tenant, error)
	TenantUpdate(context.Context, *Tenant) (*Tenant, error)
	TenantDelete(ctx context.Context, id string) error

	TenantMemberList(ctx context.Context, id string, in *PageQuery) (*TenantMemberPage, error)
	TenantMemberCreate(ctx context.Context, id string, in *Member) (*Member, error)

	TenantStats(ctx context.Context, id string) (*TenantStats, error)

	MemberList(context.Context, *PageQuery) (*MemberPage, error)
	MemberCreate(context.Context, *Member) (*Member, error)
	MemberDetail(ctx context.Context, id string) (*Member, error)
	MemberUpdate(context.Context, *Member) (*Member, error)
	MemberDelete(ctx context.Context, id string) error

	TenantProjectList(ctx context.Context, id string, in *PageQuery) (*TenantProjectPage, error)
	TenantProjectCreate(ctx context.Context, id string, in *Project) (*Project, error)

	ProjectList(context.Context, *PageQuery) (*ProjectPage, error)
	ProjectCreate(context.Context, *Project) (*Project, error)
	ProjectDetail(ctx context.Context, id string) (*Project, error)
	ProjectUpdate(context.Context, *Project) (*Project, error)
	ProjectDelete(ctx context.Context, id string) error

	ProjectTopicList(ctx context.Context, id string, in *PageQuery) (*ProjectTopicPage, error)
	ProjectTopicCreate(ctx context.Context, id string, in *Topic) (*Topic, error)

	TopicList(context.Context, *PageQuery) (*TopicPage, error)
	TopicDetail(ctx context.Context, id string) (*Topic, error)
	TopicUpdate(context.Context, *Topic) (*Topic, error)
	TopicDelete(ctx context.Context, id string) error

	ProjectAPIKeyList(ctx context.Context, id string, in *PageQuery) (*ProjectAPIKeyPage, error)
	ProjectAPIKeyCreate(ctx context.Context, id string, in *APIKey) (*APIKey, error)

	APIKeyCreate(context.Context, *APIKey) (*APIKey, error)
	APIKeyList(context.Context, *PageQuery) (*APIKeyPage, error)
	APIKeyDetail(ctx context.Context, id string) (*APIKey, error)
	APIKeyUpdate(context.Context, *APIKey) (*APIKey, error)
	APIKeyDelete(ctx context.Context, id string) error
}

func New

func New(endpoint string, opts ...ClientOption) (_ TenantClient, err error)

New creates a new API v1 client that implements the Tenant Client interface.

type TenantMemberPage added in v0.2.0

type TenantMemberPage struct {
	TenantID      string    `json:"tenant_id"`
	TenantMembers []*Member `json:"tenant_members"`
	PrevPageToken string    `json:"prev_page_token"`
	NextPageToken string    `json:"next_page_token"`
}

type TenantPage added in v0.1.1

type TenantPage struct {
	Tenants       []*Tenant `json:"tenants"`
	PrevPageToken string    `json:"prev_page_token"`
	NextPageToken string    `json:"next_page_token"`
}

type TenantProjectPage added in v0.2.0

type TenantProjectPage struct {
	TenantID       string     `json:"id"`
	TenantProjects []*Project `json:"tenant_projects"`
	PrevPageToken  string     `json:"prev_page_token"`
	NextPageToken  string     `json:"next_page_token"`
}

type TenantStats added in v0.3.0

type TenantStats struct {
	ID       string `json:"id" uri:"id"`
	Projects int    `json:"projects"`
	Topics   int    `json:"topics"`
	Keys     int    `json:"keys"`
	Data     int    `json:"data"`
}

type Topic

type Topic struct {
	ID   string `json:"id" uri:"id"`
	Name string `json:"topic_name"`
}

type TopicPage

type TopicPage struct {
	Topics        []*Topic `json:"topics"`
	PrevPageToken string   `json:"prev_page_token"`
	NextPageToken string   `json:"next_page_token"`
}

Jump to

Keyboard shortcuts

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