forked from TrueCloudLab/frostfs-rest-gw
[#7] Make container name optional
Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
parent
3e7e04b3b1
commit
70e25e6caf
6 changed files with 46 additions and 53 deletions
|
@ -772,22 +772,36 @@ func restContainerPut(ctx context.Context, t *testing.T, clientPool *pool.Pool)
|
||||||
attrKey: attrValue,
|
attrKey: attrValue,
|
||||||
}
|
}
|
||||||
|
|
||||||
req := operations.PutContainerBody{
|
// try to create container without name but with name-scope-global
|
||||||
ContainerName: util.NewString("cnr"),
|
body, err := json.Marshal(&operations.PutContainerBody{})
|
||||||
}
|
|
||||||
body, err := json.Marshal(&req)
|
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
reqURL, err := url.Parse(testHost + "/v1/containers")
|
reqURL, err := url.Parse(testHost + "/v1/containers")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
query := reqURL.Query()
|
query := reqURL.Query()
|
||||||
query.Add("skip-native-name", "true")
|
query.Add("name-scope-global", "true")
|
||||||
query.Add(walletConnectQuery, strconv.FormatBool(useWalletConnect))
|
query.Add(walletConnectQuery, strconv.FormatBool(useWalletConnect))
|
||||||
reqURL.RawQuery = query.Encode()
|
reqURL.RawQuery = query.Encode()
|
||||||
|
|
||||||
request, err := http.NewRequest(http.MethodPut, reqURL.String(), bytes.NewReader(body))
|
request, err := http.NewRequest(http.MethodPut, reqURL.String(), bytes.NewReader(body))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
prepareCommonHeaders(request.Header, bearerToken)
|
prepareCommonHeaders(request.Header, bearerToken)
|
||||||
|
|
||||||
|
doRequest(t, httpClient, request, http.StatusBadRequest, nil)
|
||||||
|
|
||||||
|
// create container with name in local scope
|
||||||
|
body, err = json.Marshal(&operations.PutContainerBody{})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
reqURL, err = url.Parse(testHost + "/v1/containers")
|
||||||
|
require.NoError(t, err)
|
||||||
|
query = reqURL.Query()
|
||||||
|
query.Add(walletConnectQuery, strconv.FormatBool(useWalletConnect))
|
||||||
|
reqURL.RawQuery = query.Encode()
|
||||||
|
|
||||||
|
request, err = http.NewRequest(http.MethodPut, reqURL.String(), bytes.NewReader(body))
|
||||||
|
require.NoError(t, err)
|
||||||
|
prepareCommonHeaders(request.Header, bearerToken)
|
||||||
request.Header.Add("X-Attribute-"+attrKey, attrValue)
|
request.Header.Add("X-Attribute-"+attrKey, attrValue)
|
||||||
|
|
||||||
addr := &operations.PutContainerOKBody{}
|
addr := &operations.PutContainerOKBody{}
|
||||||
|
|
|
@ -154,8 +154,8 @@ func init() {
|
||||||
{
|
{
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": false,
|
"default": false,
|
||||||
"description": "Provide this parameter to skip registration container name in NNS service",
|
"description": "Provide this parameter to register container name in NNS service",
|
||||||
"name": "skip-native-name",
|
"name": "name-scope-global",
|
||||||
"in": "query"
|
"in": "query"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -165,9 +165,6 @@ func init() {
|
||||||
"required": true,
|
"required": true,
|
||||||
"schema": {
|
"schema": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required": [
|
|
||||||
"containerName"
|
|
||||||
],
|
|
||||||
"properties": {
|
"properties": {
|
||||||
"basicAcl": {
|
"basicAcl": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
@ -1221,8 +1218,8 @@ func init() {
|
||||||
{
|
{
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": false,
|
"default": false,
|
||||||
"description": "Provide this parameter to skip registration container name in NNS service",
|
"description": "Provide this parameter to register container name in NNS service",
|
||||||
"name": "skip-native-name",
|
"name": "name-scope-global",
|
||||||
"in": "query"
|
"in": "query"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -1232,9 +1229,6 @@ func init() {
|
||||||
"required": true,
|
"required": true,
|
||||||
"schema": {
|
"schema": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required": [
|
|
||||||
"containerName"
|
|
||||||
],
|
|
||||||
"properties": {
|
"properties": {
|
||||||
"basicAcl": {
|
"basicAcl": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
|
|
@ -85,8 +85,7 @@ type PutContainerBody struct {
|
||||||
BasicACL string `json:"basicAcl,omitempty"`
|
BasicACL string `json:"basicAcl,omitempty"`
|
||||||
|
|
||||||
// container name
|
// container name
|
||||||
// Required: true
|
ContainerName string `json:"containerName,omitempty"`
|
||||||
ContainerName *string `json:"containerName"`
|
|
||||||
|
|
||||||
// placement policy
|
// placement policy
|
||||||
PlacementPolicy string `json:"placementPolicy,omitempty"`
|
PlacementPolicy string `json:"placementPolicy,omitempty"`
|
||||||
|
@ -94,24 +93,6 @@ type PutContainerBody struct {
|
||||||
|
|
||||||
// Validate validates this put container body
|
// Validate validates this put container body
|
||||||
func (o *PutContainerBody) Validate(formats strfmt.Registry) error {
|
func (o *PutContainerBody) Validate(formats strfmt.Registry) error {
|
||||||
var res []error
|
|
||||||
|
|
||||||
if err := o.validateContainerName(formats); err != nil {
|
|
||||||
res = append(res, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(res) > 0 {
|
|
||||||
return errors.CompositeValidationError(res...)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (o *PutContainerBody) validateContainerName(formats strfmt.Registry) error {
|
|
||||||
|
|
||||||
if err := validate.Required("container"+"."+"containerName", "body", o.ContainerName); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,12 +25,12 @@ func NewPutContainerParams() PutContainerParams {
|
||||||
var (
|
var (
|
||||||
// initialize parameters with default values
|
// initialize parameters with default values
|
||||||
|
|
||||||
skipNativeNameDefault = bool(false)
|
nameScopeGlobalDefault = bool(false)
|
||||||
walletConnectDefault = bool(false)
|
walletConnectDefault = bool(false)
|
||||||
)
|
)
|
||||||
|
|
||||||
return PutContainerParams{
|
return PutContainerParams{
|
||||||
SkipNativeName: &skipNativeNameDefault,
|
NameScopeGlobal: &nameScopeGlobalDefault,
|
||||||
|
|
||||||
WalletConnect: &walletConnectDefault,
|
WalletConnect: &walletConnectDefault,
|
||||||
}
|
}
|
||||||
|
@ -60,11 +60,11 @@ type PutContainerParams struct {
|
||||||
In: body
|
In: body
|
||||||
*/
|
*/
|
||||||
Container PutContainerBody
|
Container PutContainerBody
|
||||||
/*Provide this parameter to skip registration container name in NNS service
|
/*Provide this parameter to register container name in NNS service
|
||||||
In: query
|
In: query
|
||||||
Default: false
|
Default: false
|
||||||
*/
|
*/
|
||||||
SkipNativeName *bool
|
NameScopeGlobal *bool
|
||||||
/*Use wallect connect signature scheme or not
|
/*Use wallect connect signature scheme or not
|
||||||
In: query
|
In: query
|
||||||
Default: false
|
Default: false
|
||||||
|
@ -119,8 +119,8 @@ func (o *PutContainerParams) BindRequest(r *http.Request, route *middleware.Matc
|
||||||
res = append(res, errors.Required("container", "body", ""))
|
res = append(res, errors.Required("container", "body", ""))
|
||||||
}
|
}
|
||||||
|
|
||||||
qSkipNativeName, qhkSkipNativeName, _ := qs.GetOK("skip-native-name")
|
qNameScopeGlobal, qhkNameScopeGlobal, _ := qs.GetOK("name-scope-global")
|
||||||
if err := o.bindSkipNativeName(qSkipNativeName, qhkSkipNativeName, route.Formats); err != nil {
|
if err := o.bindNameScopeGlobal(qNameScopeGlobal, qhkNameScopeGlobal, route.Formats); err != nil {
|
||||||
res = append(res, err)
|
res = append(res, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,8 +174,8 @@ func (o *PutContainerParams) bindXBearerSignatureKey(rawData []string, hasKey bo
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// bindSkipNativeName binds and validates parameter SkipNativeName from query.
|
// bindNameScopeGlobal binds and validates parameter NameScopeGlobal from query.
|
||||||
func (o *PutContainerParams) bindSkipNativeName(rawData []string, hasKey bool, formats strfmt.Registry) error {
|
func (o *PutContainerParams) bindNameScopeGlobal(rawData []string, hasKey bool, formats strfmt.Registry) error {
|
||||||
var raw string
|
var raw string
|
||||||
if len(rawData) > 0 {
|
if len(rawData) > 0 {
|
||||||
raw = rawData[len(rawData)-1]
|
raw = rawData[len(rawData)-1]
|
||||||
|
@ -191,9 +191,9 @@ func (o *PutContainerParams) bindSkipNativeName(rawData []string, hasKey bool, f
|
||||||
|
|
||||||
value, err := swag.ConvertBool(raw)
|
value, err := swag.ConvertBool(raw)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.InvalidType("skip-native-name", "query", "bool", raw)
|
return errors.InvalidType("name-scope-global", "query", "bool", raw)
|
||||||
}
|
}
|
||||||
o.SkipNativeName = &value
|
o.NameScopeGlobal = &value
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -320,10 +320,13 @@ func createContainer(ctx context.Context, p *pool.Pool, stoken *session.Token, p
|
||||||
cnrOptions := []container.Option{
|
cnrOptions := []container.Option{
|
||||||
container.WithPolicy(pp),
|
container.WithPolicy(pp),
|
||||||
container.WithCustomBasicACL(basicACL),
|
container.WithCustomBasicACL(basicACL),
|
||||||
container.WithAttribute(container.AttributeName, *request.ContainerName),
|
|
||||||
container.WithAttribute(container.AttributeTimestamp, strconv.FormatInt(time.Now().Unix(), 10)),
|
container.WithAttribute(container.AttributeTimestamp, strconv.FormatInt(time.Now().Unix(), 10)),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if request.ContainerName != "" {
|
||||||
|
container.WithAttribute(container.AttributeName, request.ContainerName)
|
||||||
|
}
|
||||||
|
|
||||||
for key, val := range userAttrs {
|
for key, val := range userAttrs {
|
||||||
cnrOptions = append(cnrOptions, container.WithAttribute(key, val))
|
cnrOptions = append(cnrOptions, container.WithAttribute(key, val))
|
||||||
}
|
}
|
||||||
|
@ -332,8 +335,11 @@ func createContainer(ctx context.Context, p *pool.Pool, stoken *session.Token, p
|
||||||
cnr.SetOwnerID(stoken.OwnerID())
|
cnr.SetOwnerID(stoken.OwnerID())
|
||||||
cnr.SetSessionToken(stoken)
|
cnr.SetSessionToken(stoken)
|
||||||
|
|
||||||
if !*params.SkipNativeName { // we don't check for nil because there is default false value
|
if *params.NameScopeGlobal { // we don't check for nil because there is default false value
|
||||||
container.SetNativeName(cnr, *request.ContainerName)
|
if request.ContainerName == "" {
|
||||||
|
return nil, fmt.Errorf("container name must not be empty to be registered in NNS")
|
||||||
|
}
|
||||||
|
container.SetNativeName(cnr, request.ContainerName)
|
||||||
}
|
}
|
||||||
|
|
||||||
var prm pool.PrmContainerPut
|
var prm pool.PrmContainerPut
|
||||||
|
|
|
@ -222,8 +222,8 @@ paths:
|
||||||
- $ref: '#/parameters/signatureKeyParam'
|
- $ref: '#/parameters/signatureKeyParam'
|
||||||
- $ref: '#/parameters/signatureScheme'
|
- $ref: '#/parameters/signatureScheme'
|
||||||
- in: query
|
- in: query
|
||||||
name: skip-native-name
|
name: name-scope-global
|
||||||
description: Provide this parameter to skip registration container name in NNS service
|
description: Provide this parameter to register container name in NNS service
|
||||||
type: boolean
|
type: boolean
|
||||||
default: false
|
default: false
|
||||||
- in: body
|
- in: body
|
||||||
|
@ -239,8 +239,6 @@ paths:
|
||||||
type: string
|
type: string
|
||||||
basicAcl:
|
basicAcl:
|
||||||
type: string
|
type: string
|
||||||
required:
|
|
||||||
- containerName
|
|
||||||
example:
|
example:
|
||||||
containerId: container
|
containerId: container
|
||||||
placementPolicy: "REP 3"
|
placementPolicy: "REP 3"
|
||||||
|
|
Loading…
Reference in a new issue