fix(preheat): add location when create instance and policy

Signed-off-by: chlins <chlins.zhang@gmail.com>
This commit is contained in:
chlins 2020-10-29 18:11:09 +08:00
parent d1bf0f092a
commit 42d07dbaa7
2 changed files with 10 additions and 29 deletions

View File

@ -957,9 +957,7 @@ paths:
$ref: '#/definitions/Instance'
responses:
'201':
description: Response to insatnce created
schema:
$ref: '#/definitions/InstanceCreatedResp'
$ref: '#/responses/201'
'400':
$ref: '#/responses/400'
'401':
@ -1008,9 +1006,7 @@ paths:
- $ref: '#/parameters/instanceName'
responses:
'200':
description: Instance ID deleted
schema:
$ref: '#/definitions/InstanceDeletedResp'
$ref: '#/responses/200'
'401':
$ref: '#/responses/401'
'403':
@ -1036,9 +1032,7 @@ paths:
$ref: '#/definitions/Instance'
responses:
'200':
description: Success
schema:
$ref: '#/definitions/InstanceUpdateResp'
$ref: '#/responses/200'
'400':
$ref: '#/responses/400'
'401':
@ -2015,24 +2009,6 @@ definitions:
type: integer
format: int64
description: The timestamp of instance setting up
InstanceUpdateResp:
type: object
properties:
updated:
type: integer
description: ID of instance updated
InstanceDeletedResp:
type: object
properties:
removed:
type: integer
description: ID of instance removed
InstanceCreatedResp:
type: object
properties:
id:
type: integer
description: ID of instance created
PreheatPolicy:
type: object
properties:

View File

@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"regexp"
"strings"
"time"
"github.com/go-openapi/runtime/middleware"
@ -68,7 +69,9 @@ func (api *preheatAPI) CreateInstance(ctx context.Context, params operation.Crea
if err != nil {
return api.SendError(ctx, err)
}
return operation.NewCreateInstanceCreated()
location := fmt.Sprintf("%s/%s", strings.TrimSuffix(params.HTTPRequest.URL.Path, "/"), instance.Name)
return operation.NewCreateInstanceCreated().WithLocation(location)
}
func (api *preheatAPI) DeleteInstance(ctx context.Context, params operation.DeleteInstanceParams) middleware.Responder {
@ -238,7 +241,9 @@ func (api *preheatAPI) CreatePolicy(ctx context.Context, params operation.Create
if err != nil {
return api.SendError(ctx, err)
}
return operation.NewCreatePolicyCreated()
location := fmt.Sprintf("%s/%s", strings.TrimSuffix(params.HTTPRequest.URL.Path, "/"), policy.Name)
return operation.NewCreatePolicyCreated().WithLocation(location)
}
// UpdatePolicy is Update preheat policy