Documentation
¶
Index ¶
- Constants
- Variables
- func ControllerRouter(cfg HTTPAPIConfig, family string, cf strawberry.ControllerFactory, ...) chi.Router
- func HandleDescribe(w http.ResponseWriter, r *http.Request, commands []CmdDescriptor, ...)
- func HandlePing(w http.ResponseWriter, r *http.Request)
- func Marshal(v any, format FormatType) ([]byte, error)
- func NewServer(c HTTPAPIConfig, l log.Logger) *httpserver.HTTPServer
- func Unmarshal(data []byte, v any, format FormatType) error
- type API
- func (a *API) CheckExistence(ctx context.Context, alias string, shouldExist bool) error
- func (a *API) CheckPermissionToOp(ctx context.Context, alias string, permission yt.Permission) error
- func (a *API) CheckPermissionToPool(ctx context.Context, pool string, permission yt.Permission) error
- func (a *API) Create(ctx context.Context, alias string, specletOptions map[string]any) error
- func (a *API) DescribeOptions(ctx context.Context, alias string) ([]strawberry.OptionGroupDescriptor, error)
- func (a *API) EditOptions(ctx context.Context, alias string, optionsToSet map[string]any, ...) error
- func (a *API) Exists(ctx context.Context, alias string) (bool, error)
- func (a *API) GetBriefInfo(ctx context.Context, alias string) (strawberry.OpletBriefInfo, error)
- func (a *API) GetOption(ctx context.Context, alias, key string) (value any, err error)
- func (a *API) GetSpeclet(ctx context.Context, alias string) (speclet map[string]any, err error)
- func (a *API) List(ctx context.Context, attributes []string) ([]AliasWithAttrs, error)
- func (a *API) Remove(ctx context.Context, alias string) error
- func (a *API) RemoveOption(ctx context.Context, alias, key string) error
- func (a *API) SetOption(ctx context.Context, alias, key string, value any) error
- func (a *API) SetSpeclet(ctx context.Context, alias string, speclet map[string]any) error
- func (a *API) Start(ctx context.Context, alias string, untracked bool, userClient yt.Client) error
- func (a *API) Stop(ctx context.Context, alias string) error
- type APIConfig
- type AliasWithAttrs
- type CmdDescriptor
- type CmdParameter
- type FormatType
- type HTTPAPI
- func (a HTTPAPI) HandleCreate(w http.ResponseWriter, r *http.Request, params map[string]any)
- func (a HTTPAPI) HandleDescribeOptions(w http.ResponseWriter, r *http.Request, params map[string]any)
- func (a HTTPAPI) HandleEditOptions(w http.ResponseWriter, r *http.Request, params map[string]any)
- func (a HTTPAPI) HandleExists(w http.ResponseWriter, r *http.Request, params map[string]any)
- func (a HTTPAPI) HandleGetBriefInfo(w http.ResponseWriter, r *http.Request, params map[string]any)
- func (a HTTPAPI) HandleGetOption(w http.ResponseWriter, r *http.Request, params map[string]any)
- func (a HTTPAPI) HandleGetSpeclet(w http.ResponseWriter, r *http.Request, params map[string]any)
- func (a HTTPAPI) HandleList(w http.ResponseWriter, r *http.Request, params map[string]any)
- func (a HTTPAPI) HandleRemove(w http.ResponseWriter, r *http.Request, params map[string]any)
- func (a HTTPAPI) HandleRemoveOption(w http.ResponseWriter, r *http.Request, params map[string]any)
- func (a HTTPAPI) HandleSetOption(w http.ResponseWriter, r *http.Request, params map[string]any)
- func (a HTTPAPI) HandleSetOptions(w http.ResponseWriter, r *http.Request, params map[string]any)
- func (a HTTPAPI) HandleSetSpeclet(w http.ResponseWriter, r *http.Request, params map[string]any)
- func (a HTTPAPI) HandleStart(w http.ResponseWriter, r *http.Request, params map[string]any)
- func (a HTTPAPI) HandleStop(w http.ResponseWriter, r *http.Request, params map[string]any)
- func (a HTTPAPI) ReplyOK(w http.ResponseWriter, result any)
- func (a HTTPAPI) ReplyWithError(w http.ResponseWriter, err error)
- type HTTPAPIConfig
- type HandlerFunc
- type ParamType
- type RequestParams
Constants ¶
const ( TypeString ParamType = "string" TypeAny ParamType = "any" ActionStore string = "store" ActionStoreTrue string = "store_true" DefaultAction string = ActionStore )
const (
DefaultValidatePool = true
)
Variables ¶
var AliasParameter = CmdParameter{ Name: "alias", Aliases: []string{"a"}, Type: TypeString, Required: true, Description: "alias for the operation", EnvVariable: "ALIAS", Validator: validateAlias, }
var AllCommands = []CmdDescriptor{ ListCmdDescriptor, CreateCmdDescriptor, RemoveCmdDescriptor, ExistsCmdDescriptor, StatusCmdDescriptor, GetBriefInfoCmdDescriptor, GetOptionCmdDescriptor, SetOptionCmdDescriptor, RemoveOptionCmdDescriptor, GetSpecletCmdDescriptor, SetSpecletCmdDescriptor, SetOptionsCmdDescriptor, EditOptionsCmdDescriptor, StartCmdDescriptor, StopCmdDescriptor, DescribeOptionsCmdDescriptor, }
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", }
var CreateCmdDescriptor = CmdDescriptor{ Name: "create", Parameters: []CmdParameter{ AliasParameter.AsExplicit(), SpecletOptionsParameter, }, Description: "create a new strawberry operation", Handler: HTTPAPI.HandleCreate, }
var DescribeOptionsCmdDescriptor = CmdDescriptor{ Name: "describe_options", Parameters: []CmdParameter{AliasParameter.AsExplicit()}, Description: "get available speclet options", Handler: HTTPAPI.HandleDescribeOptions, }
var EditOptionsCmdDescriptor = CmdDescriptor{ Name: "edit_options", Parameters: []CmdParameter{AliasParameter, OptionsToSetParameter, OptionsToRemoveParameter}, Description: "edit multiple speclet options", Handler: HTTPAPI.HandleEditOptions, }
var ExistsCmdDescriptor = CmdDescriptor{ Name: "exists", Parameters: []CmdParameter{AliasParameter.AsExplicit()}, Description: "check the strawberry operation existence", Handler: HTTPAPI.HandleExists, }
var GetBriefInfoCmdDescriptor = CmdDescriptor{ Name: "get_brief_info", Parameters: []CmdParameter{AliasParameter.AsExplicit()}, Description: "show strawberry operation brief info", Handler: HTTPAPI.HandleGetBriefInfo, }
var GetOptionCmdDescriptor = CmdDescriptor{ Name: "get_option", Parameters: []CmdParameter{AliasParameter, KeyParameter}, Description: "get speclet option", Handler: HTTPAPI.HandleGetOption, }
var GetSpecletCmdDescriptor = CmdDescriptor{ Name: "get_speclet", Parameters: []CmdParameter{AliasParameter}, Description: "get strawberry operation speclet", Handler: HTTPAPI.HandleGetSpeclet, }
var KeyParameter = CmdParameter{ Name: "key", Type: TypeString, Required: true, Description: "speclet option name", Validator: validateOption, }
var ListCmdDescriptor = CmdDescriptor{ Name: "list", Parameters: []CmdParameter{AttributesParameter}, Description: "list all strawberry operations on the cluster", Handler: HTTPAPI.HandleList, }
var OptionsParameter = CmdParameter{ Name: "options", Type: TypeAny, Required: true, Description: "speclet options in yson format", Validator: validateSpecletOptions, }
var OptionsToRemoveParameter = CmdParameter{ Name: "options_to_remove", Type: TypeAny, Required: true, Description: "speclet options to remove in yson format", Transformer: transformToStringSlice, }
var OptionsToSetParameter = CmdParameter{ Name: "options_to_set", Type: TypeAny, Required: true, Description: "speclet options to set in yson format", Validator: validateSpecletOptions, }
var RemoveCmdDescriptor = CmdDescriptor{ Name: "remove", Parameters: []CmdParameter{AliasParameter.AsExplicit()}, Description: "remove the strawberry operation", Handler: HTTPAPI.HandleRemove, }
var RemoveOptionCmdDescriptor = CmdDescriptor{ Name: "remove_option", Parameters: []CmdParameter{AliasParameter, KeyParameter}, Description: "remove speclet option", Handler: HTTPAPI.HandleRemoveOption, }
var SetOptionCmdDescriptor = CmdDescriptor{ Name: "set_option", Parameters: []CmdParameter{AliasParameter, KeyParameter, ValueParameter}, Description: "set speclet option", Handler: HTTPAPI.HandleSetOption, }
var SetOptionsCmdDescriptor = CmdDescriptor{ Name: "set_options", Parameters: []CmdParameter{AliasParameter, OptionsParameter}, Description: "set multiple speclet options", Handler: HTTPAPI.HandleSetOptions, }
var SetSpecletCmdDescriptor = CmdDescriptor{ Name: "set_speclet", Parameters: []CmdParameter{AliasParameter, SpecletParameter}, Description: "set strawberry operation speclet", Handler: HTTPAPI.HandleSetSpeclet, }
var SpecletOptionsParameter = CmdParameter{ Name: "speclet_options", Type: TypeAny, Description: "speclet options in yson format", Validator: validateSpecletOptions, }
var SpecletParameter = CmdParameter{ Name: "speclet", Type: TypeAny, Required: true, Description: "speclet in yson format", Validator: validateSpecletOptions, }
var StartCmdDescriptor = CmdDescriptor{ Name: "start", Parameters: []CmdParameter{AliasParameter.AsExplicit(), UntrackedParameter}, Description: "start strawberry operation", Handler: HTTPAPI.HandleStart, }
var StatusCmdDescriptor = CmdDescriptor{ Name: "status", Parameters: []CmdParameter{AliasParameter.AsExplicit()}, Description: "show strawberry operation status", Handler: HTTPAPI.HandleGetBriefInfo, }
COMPAT(gudqeit)
var StopCmdDescriptor = CmdDescriptor{ Name: "stop", Parameters: []CmdParameter{AliasParameter.AsExplicit()}, Description: "stop strawberry operation", Handler: HTTPAPI.HandleStop, }
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, }
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 NewServer ¶
func NewServer(c HTTPAPIConfig, l log.Logger) *httpserver.HTTPServer
Types ¶
type API ¶
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 (*API) CheckPermissionToOp ¶
func (*API) CheckPermissionToPool ¶
func (*API) Create ¶
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 (*API) GetBriefInfo ¶ added in v0.0.7
func (a *API) GetBriefInfo(ctx context.Context, alias string) (strawberry.OpletBriefInfo, error)
func (*API) GetSpeclet ¶
func (*API) Remove ¶
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) SetSpeclet ¶
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 (*APIConfig) ValidatePoolAccessOrDefault ¶
type AliasWithAttrs ¶ added in v0.0.4
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 ¶
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 (HTTPAPI) HandleDescribeOptions ¶ added in v0.0.4
func (HTTPAPI) HandleEditOptions ¶ added in v0.0.9
func (HTTPAPI) HandleExists ¶
func (HTTPAPI) HandleGetBriefInfo ¶ added in v0.0.7
func (HTTPAPI) HandleGetOption ¶
func (HTTPAPI) HandleGetSpeclet ¶
func (HTTPAPI) HandleList ¶
func (HTTPAPI) HandleRemove ¶
func (HTTPAPI) HandleRemoveOption ¶
func (HTTPAPI) HandleSetOption ¶
func (HTTPAPI) HandleSetOptions ¶ added in v0.0.4
func (HTTPAPI) HandleSetSpeclet ¶
func (HTTPAPI) HandleStart ¶
func (HTTPAPI) HandleStop ¶
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 HandlerFunc ¶ added in v0.0.6
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"` }