api

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeString ParamType = "string"
	TypeAny    ParamType = "any"

	ActionStore     string = "store"
	ActionStoreTrue string = "store_true"

	DefaultAction string = ActionStore
)
View Source
const (
	DefaultValidatePool = true
)

Variables

View Source
var AliasParameter = CmdParameter{
	Name:        "alias",
	Aliases:     []string{"a"},
	Type:        TypeString,
	Required:    true,
	Description: "alias for the operation",
	EnvVariable: "ALIAS",
	Validator:   validateAlias,
}
View Source
var AttributesParameter = CmdParameter{
	Name:        "attributes",
	Type:        TypeAny,
	Description: "strawberry operation attributes to add into response in yson list format",
	Transformer: transformToStringSlice,

	ElementName:        "attribute",
	ElementType:        TypeString,
	ElementDescription: "strawberry operation attribute to add into response",
}
View Source
var CreateCmdDescriptor = CmdDescriptor{
	Name: "create",
	Parameters: []CmdParameter{
		AliasParameter.AsExplicit(),
		SpecletOptionsParameter,
	},
	Description: "create a new strawberry operation",
	Handler:     HTTPAPI.HandleCreate,
}
View Source
var DescribeOptionsCmdDescriptor = CmdDescriptor{
	Name:        "describe_options",
	Parameters:  []CmdParameter{AliasParameter.AsExplicit()},
	Description: "get available speclet options",
	Handler:     HTTPAPI.HandleDescribeOptions,
}
View Source
var EditOptionsCmdDescriptor = CmdDescriptor{
	Name:        "edit_options",
	Parameters:  []CmdParameter{AliasParameter, OptionsToSetParameter, OptionsToRemoveParameter},
	Description: "edit multiple speclet options",
	Handler:     HTTPAPI.HandleEditOptions,
}
View Source
var ExistsCmdDescriptor = CmdDescriptor{
	Name:        "exists",
	Parameters:  []CmdParameter{AliasParameter.AsExplicit()},
	Description: "check the strawberry operation existence",
	Handler:     HTTPAPI.HandleExists,
}
View Source
var GetBriefInfoCmdDescriptor = CmdDescriptor{
	Name:        "get_brief_info",
	Parameters:  []CmdParameter{AliasParameter.AsExplicit()},
	Description: "show strawberry operation brief info",
	Handler:     HTTPAPI.HandleGetBriefInfo,
}
View Source
var GetOptionCmdDescriptor = CmdDescriptor{
	Name:        "get_option",
	Parameters:  []CmdParameter{AliasParameter, KeyParameter},
	Description: "get speclet option",
	Handler:     HTTPAPI.HandleGetOption,
}
View Source
var GetSpecletCmdDescriptor = CmdDescriptor{
	Name:        "get_speclet",
	Parameters:  []CmdParameter{AliasParameter},
	Description: "get strawberry operation speclet",
	Handler:     HTTPAPI.HandleGetSpeclet,
}
View Source
var KeyParameter = CmdParameter{
	Name:        "key",
	Type:        TypeString,
	Required:    true,
	Description: "speclet option name",
	Validator:   validateOption,
}
View Source
var ListCmdDescriptor = CmdDescriptor{
	Name:        "list",
	Parameters:  []CmdParameter{AttributesParameter},
	Description: "list all strawberry operations on the cluster",
	Handler:     HTTPAPI.HandleList,
}
View Source
var OptionsParameter = CmdParameter{
	Name:        "options",
	Type:        TypeAny,
	Required:    true,
	Description: "speclet options in yson format",
	Validator:   validateSpecletOptions,
}
View Source
var OptionsToRemoveParameter = CmdParameter{
	Name:        "options_to_remove",
	Type:        TypeAny,
	Required:    true,
	Description: "speclet options to remove in yson format",
	Transformer: transformToStringSlice,
}
View Source
var OptionsToSetParameter = CmdParameter{
	Name:        "options_to_set",
	Type:        TypeAny,
	Required:    true,
	Description: "speclet options to set in yson format",
	Validator:   validateSpecletOptions,
}
View Source
var RemoveCmdDescriptor = CmdDescriptor{
	Name:        "remove",
	Parameters:  []CmdParameter{AliasParameter.AsExplicit()},
	Description: "remove the strawberry operation",
	Handler:     HTTPAPI.HandleRemove,
}
View Source
var RemoveOptionCmdDescriptor = CmdDescriptor{
	Name:        "remove_option",
	Parameters:  []CmdParameter{AliasParameter, KeyParameter},
	Description: "remove speclet option",
	Handler:     HTTPAPI.HandleRemoveOption,
}
View Source
var SetOptionCmdDescriptor = CmdDescriptor{
	Name:        "set_option",
	Parameters:  []CmdParameter{AliasParameter, KeyParameter, ValueParameter},
	Description: "set speclet option",
	Handler:     HTTPAPI.HandleSetOption,
}
View Source
var SetOptionsCmdDescriptor = CmdDescriptor{
	Name:        "set_options",
	Parameters:  []CmdParameter{AliasParameter, OptionsParameter},
	Description: "set multiple speclet options",
	Handler:     HTTPAPI.HandleSetOptions,
}
View Source
var SetSpecletCmdDescriptor = CmdDescriptor{
	Name:        "set_speclet",
	Parameters:  []CmdParameter{AliasParameter, SpecletParameter},
	Description: "set strawberry operation speclet",
	Handler:     HTTPAPI.HandleSetSpeclet,
}
View Source
var SpecletOptionsParameter = CmdParameter{
	Name:        "speclet_options",
	Type:        TypeAny,
	Description: "speclet options in yson format",
	Validator:   validateSpecletOptions,
}
View Source
var SpecletParameter = CmdParameter{
	Name:        "speclet",
	Type:        TypeAny,
	Required:    true,
	Description: "speclet in yson format",
	Validator:   validateSpecletOptions,
}
View Source
var StartCmdDescriptor = CmdDescriptor{
	Name:        "start",
	Parameters:  []CmdParameter{AliasParameter.AsExplicit(), UntrackedParameter},
	Description: "start strawberry operation",
	Handler:     HTTPAPI.HandleStart,
}
View Source
var StatusCmdDescriptor = CmdDescriptor{
	Name:        "status",
	Parameters:  []CmdParameter{AliasParameter.AsExplicit()},
	Description: "show strawberry operation status",
	Handler:     HTTPAPI.HandleGetBriefInfo,
}

COMPAT(gudqeit)

View Source
var StopCmdDescriptor = CmdDescriptor{
	Name:        "stop",
	Parameters:  []CmdParameter{AliasParameter.AsExplicit()},
	Description: "stop strawberry operation",
	Handler:     HTTPAPI.HandleStop,
}
View Source
var UntrackedParameter = CmdParameter{
	Name:   "untracked",
	Action: ActionStoreTrue,
	Description: "start operation via user credentials; " +
		"operation will not be tracked by the controller; " +
		"highly unrecommended for production operations",
	Validator: validateBool,
}
View Source
var ValueParameter = CmdParameter{
	Name:        "value",
	Type:        TypeAny,
	Required:    true,
	Description: "speclet option value",
}

Functions

func ControllerRouter added in v0.0.4

func ControllerRouter(cfg HTTPAPIConfig, family string, cf strawberry.ControllerFactory, l log.Logger) chi.Router

func HandleDescribe

func HandleDescribe(w http.ResponseWriter, r *http.Request, commands []CmdDescriptor, clusters []string)

func HandlePing

func HandlePing(w http.ResponseWriter, r *http.Request)

func Marshal added in v0.0.6

func Marshal(v any, format FormatType) ([]byte, error)

func Unmarshal added in v0.0.6

func Unmarshal(data []byte, v any, format FormatType) error

Types

type API

type API struct {
	Ytc yt.Client
	// contains filtered or unexported fields
}

API implements all the controllers-api logic.

func NewAPI

func NewAPI(ytc yt.Client, cfg APIConfig, ctl strawberry.Controller, l log.Logger) *API

func (*API) CheckExistence

func (a *API) CheckExistence(ctx context.Context, alias string, shouldExist bool) error

func (*API) CheckPermissionToOp

func (a *API) CheckPermissionToOp(ctx context.Context, alias string, permission yt.Permission) error

func (*API) CheckPermissionToPool

func (a *API) CheckPermissionToPool(ctx context.Context, pool string, permission yt.Permission) error

func (*API) Create

func (a *API) Create(
	ctx context.Context,
	alias string,
	specletOptions map[string]any,
) error

Create creates a new strawberry operation in cypress. If the creation fails due to a transient error, the resulting state can be inconsistent, because we can not create an access control object node in transactions. Anyway, it's guaranteed that in such state the Create command can be retried and that this state can be completely removed via Remove command.

func (*API) DescribeOptions added in v0.0.4

func (a *API) DescribeOptions(ctx context.Context, alias string) ([]strawberry.OptionGroupDescriptor, error)

func (*API) EditOptions added in v0.0.9

func (a *API) EditOptions(
	ctx context.Context,
	alias string,
	optionsToSet map[string]any,
	optionsToRemove []string,
) error

func (*API) Exists

func (a *API) Exists(ctx context.Context, alias string) (bool, error)

func (*API) GetBriefInfo added in v0.0.7

func (a *API) GetBriefInfo(ctx context.Context, alias string) (strawberry.OpletBriefInfo, error)

func (*API) GetOption

func (a *API) GetOption(ctx context.Context, alias, key string) (value any, err error)

func (*API) GetSpeclet

func (a *API) GetSpeclet(ctx context.Context, alias string) (speclet map[string]any, err error)

func (*API) List

func (a *API) List(ctx context.Context, attributes []string) ([]AliasWithAttrs, error)

func (*API) Remove

func (a *API) Remove(ctx context.Context, alias string) error

Remove deletes the strawberry operation from cypress. If the deletion fails due to a transient error, the state can be partially removed, but it's guaranteed that the Remove command can be retried to delete the state completely.

func (*API) RemoveOption

func (a *API) RemoveOption(ctx context.Context, alias, key string) error

func (*API) SetOption

func (a *API) SetOption(ctx context.Context, alias, key string, value any) error

func (*API) SetSpeclet

func (a *API) SetSpeclet(ctx context.Context, alias string, speclet map[string]any) error

func (*API) Start

func (a *API) Start(ctx context.Context, alias string, untracked bool, userClient yt.Client) error

func (*API) Stop

func (a *API) Stop(ctx context.Context, alias string) error

type APIConfig

type APIConfig struct {
	// ControllerFactories contains mapping from controller families to controller factories.
	ControllerFactories map[string]strawberry.ControllerFactory
	// ControllerMappings contains rules of mapping host to a particular controller.
	// See https://github.com/go-chi/hostrouter/blob/master/README.md for key examples.
	ControllerMappings map[string]string
	AgentInfo          strawberry.AgentInfo
	BaseACL            []yt.ACE
	RobotUsername      string
	ValidatePoolAccess *bool
}

func (*APIConfig) ControllerMappingsOrDefault added in v0.0.4

func (c *APIConfig) ControllerMappingsOrDefault() map[string]string

func (*APIConfig) ValidatePoolAccessOrDefault

func (c *APIConfig) ValidatePoolAccessOrDefault() bool

type AliasWithAttrs added in v0.0.4

type AliasWithAttrs struct {
	Alias string         `yson:",value" json:"$value"`
	Attrs map[string]any `yson:",attrs" json:"$attributes"`
}

type CmdDescriptor

type CmdDescriptor struct {
	Name        string         `yson:"name"`
	Parameters  []CmdParameter `yson:"parameters"`
	Description string         `yson:"description,omitempty"`
	Handler     HandlerFunc    `yson:"-"`
}

type CmdParameter

type CmdParameter struct {
	Name        string                 `yson:"name"`
	Aliases     []string               `yson:"aliases,omitempty"`
	Type        ParamType              `yson:"type"`
	Required    bool                   `yson:"required"`
	Action      string                 `yson:"action,omitempty"`
	Description string                 `yson:"description,omitempty"`
	EnvVariable string                 `yson:"env_variable,omitempty"`
	Validator   func(any) error        `yson:"-"`
	Transformer func(any) (any, error) `yson:"-"`

	ElementName        string    `yson:"element_name,omitempty"`
	ElementType        ParamType `yson:"element_type,omitempty"`
	ElementAliases     []string  `yson:"element_aliases,omitempty"`
	ElementDescription string    `yson:"element_description,omitempty"`
}

func (*CmdParameter) ActionOrDefault

func (c *CmdParameter) ActionOrDefault() string

func (CmdParameter) AsExplicit

func (c CmdParameter) AsExplicit() CmdParameter

AsExplicit returns a copy of the parameter with empty EnvVariable field, so this parameter should be set explicitly in CLI.

type FormatType added in v0.0.6

type FormatType string
const (
	FormatJSON FormatType = "json"
	FormatYSON FormatType = "yson"

	DefaultFormat FormatType = FormatYSON
)

type HTTPAPI

type HTTPAPI struct {
	API *API
	L   log.Logger
	// contains filtered or unexported fields
}

HTTPAPI is a lightweight wrapper of API which handles http requests and transforms them to proper API calls.

func NewHTTPAPI

func NewHTTPAPI(ytc yt.Client, config APIConfig, ctl strawberry.Controller, l log.Logger, disableAuth bool) HTTPAPI

func (HTTPAPI) HandleCreate

func (a HTTPAPI) HandleCreate(w http.ResponseWriter, r *http.Request, params map[string]any)

func (HTTPAPI) HandleDescribeOptions added in v0.0.4

func (a HTTPAPI) HandleDescribeOptions(w http.ResponseWriter, r *http.Request, params map[string]any)

func (HTTPAPI) HandleEditOptions added in v0.0.9

func (a HTTPAPI) HandleEditOptions(w http.ResponseWriter, r *http.Request, params map[string]any)

func (HTTPAPI) HandleExists

func (a HTTPAPI) HandleExists(w http.ResponseWriter, r *http.Request, params map[string]any)

func (HTTPAPI) HandleGetBriefInfo added in v0.0.7

func (a HTTPAPI) HandleGetBriefInfo(w http.ResponseWriter, r *http.Request, params map[string]any)

func (HTTPAPI) HandleGetOption

func (a HTTPAPI) HandleGetOption(w http.ResponseWriter, r *http.Request, params map[string]any)

func (HTTPAPI) HandleGetSpeclet

func (a HTTPAPI) HandleGetSpeclet(w http.ResponseWriter, r *http.Request, params map[string]any)

func (HTTPAPI) HandleList

func (a HTTPAPI) HandleList(w http.ResponseWriter, r *http.Request, params map[string]any)

func (HTTPAPI) HandleRemove

func (a HTTPAPI) HandleRemove(w http.ResponseWriter, r *http.Request, params map[string]any)

func (HTTPAPI) HandleRemoveOption

func (a HTTPAPI) HandleRemoveOption(w http.ResponseWriter, r *http.Request, params map[string]any)

func (HTTPAPI) HandleSetOption

func (a HTTPAPI) HandleSetOption(w http.ResponseWriter, r *http.Request, params map[string]any)

func (HTTPAPI) HandleSetOptions added in v0.0.4

func (a HTTPAPI) HandleSetOptions(w http.ResponseWriter, r *http.Request, params map[string]any)

func (HTTPAPI) HandleSetSpeclet

func (a HTTPAPI) HandleSetSpeclet(w http.ResponseWriter, r *http.Request, params map[string]any)

func (HTTPAPI) HandleStart

func (a HTTPAPI) HandleStart(w http.ResponseWriter, r *http.Request, params map[string]any)

func (HTTPAPI) HandleStop

func (a HTTPAPI) HandleStop(w http.ResponseWriter, r *http.Request, params map[string]any)

func (HTTPAPI) ReplyOK added in v0.0.9

func (a HTTPAPI) ReplyOK(w http.ResponseWriter, result any)

func (HTTPAPI) ReplyWithError added in v0.0.9

func (a HTTPAPI) ReplyWithError(w http.ResponseWriter, err error)

type HTTPAPIConfig

type HTTPAPIConfig struct {
	BaseAPIConfig APIConfig

	ClusterInfos    []strawberry.AgentInfo
	LocationAliases map[string][]string
	Token           string
	DisableAuth     bool
	Endpoint        string
}

type HandlerFunc added in v0.0.6

type HandlerFunc func(api HTTPAPI, w http.ResponseWriter, r *http.Request, params map[string]any)

type ParamType

type ParamType string

type RequestParams

type RequestParams struct {
	// Params contains request parameters which are set by the user.
	// E.g. in CLI "--xxx yyy" should set an "xxx" parameter with the value "yyy".
	Params map[string]any `yson:"params" json:"params"`

	// Unparsed indicates that:
	//
	// 1. All params with a "store" action are provided as YSON strings or an array of YSON strings
	//    and should be parsed to proper types,
	// 2. Params with a "store_true" action can be provided as true/false,
	// 3. A null value for a param is equivalent to a missing param.
	//
	// It can be useful in CLI, where all params' types are unknown.
	Unparsed bool `yson:"unparsed" json:"unparsed"`
}

Jump to

Keyboard shortcuts

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