feat(http): add labels endpoints to organizations (#1827)
* feat(http): add labels endpoints to organizations * make fmtpull/10616/head
parent
e0fc798595
commit
a4363800bd
|
@ -76,7 +76,7 @@ func NewAPIHandler(b *APIBackend) *APIHandler {
|
|||
h.BucketHandler.BucketService = b.BucketService
|
||||
h.BucketHandler.BucketOperationLogService = b.BucketOperationLogService
|
||||
|
||||
h.OrgHandler = NewOrgHandler(b.UserResourceMappingService)
|
||||
h.OrgHandler = NewOrgHandler(b.UserResourceMappingService, b.LabelService)
|
||||
h.OrgHandler.OrganizationService = b.OrganizationService
|
||||
h.OrgHandler.BucketService = b.BucketService
|
||||
h.OrgHandler.OrganizationOperationLogService = b.OrganizationOperationLogService
|
||||
|
|
|
@ -23,6 +23,7 @@ type OrgHandler struct {
|
|||
BucketService platform.BucketService
|
||||
UserResourceMappingService platform.UserResourceMappingService
|
||||
SecretService platform.SecretService
|
||||
LabelService platform.LabelService
|
||||
}
|
||||
|
||||
const (
|
||||
|
@ -36,13 +37,17 @@ const (
|
|||
organizationsIDSecretsPath = "/api/v2/orgs/:id/secrets"
|
||||
// TODO(desa): need a way to specify which secrets to delete. this should work for now
|
||||
organizationsIDSecretsDeletePath = "/api/v2/orgs/:id/secrets/delete"
|
||||
organizationsIDLabelsPath = "/api/v2/orgs/:id/labels"
|
||||
organizationsIDLabelsNamePath = "/api/v2/orgs/:id/labels/:name"
|
||||
)
|
||||
|
||||
// NewOrgHandler returns a new instance of OrgHandler.
|
||||
func NewOrgHandler(mappingService platform.UserResourceMappingService) *OrgHandler {
|
||||
func NewOrgHandler(mappingService platform.UserResourceMappingService,
|
||||
labelService platform.LabelService) *OrgHandler {
|
||||
h := &OrgHandler{
|
||||
Router: httprouter.New(),
|
||||
UserResourceMappingService: mappingService,
|
||||
LabelService: labelService,
|
||||
}
|
||||
|
||||
h.HandlerFunc("POST", organizationsPath, h.handlePostOrg)
|
||||
|
@ -65,6 +70,10 @@ func NewOrgHandler(mappingService platform.UserResourceMappingService) *OrgHandl
|
|||
// TODO(desa): need a way to specify which secrets to delete. this should work for now
|
||||
h.HandlerFunc("POST", organizationsIDSecretsDeletePath, h.handleDeleteSecrets)
|
||||
|
||||
h.HandlerFunc("GET", organizationsIDLabelsPath, newGetLabelsHandler(h.LabelService))
|
||||
h.HandlerFunc("POST", organizationsIDLabelsPath, newPostLabelHandler(h.LabelService))
|
||||
h.HandlerFunc("DELETE", organizationsIDLabelsNamePath, newDeleteLabelHandler(h.LabelService))
|
||||
|
||||
return h
|
||||
}
|
||||
|
||||
|
|
|
@ -28,8 +28,7 @@ func initOrganizationService(f platformtesting.OrganizationFields, t *testing.T)
|
|||
}
|
||||
}
|
||||
|
||||
mappingService := mock.NewUserResourceMappingService()
|
||||
handler := NewOrgHandler(mappingService)
|
||||
handler := NewOrgHandler(mock.NewUserResourceMappingService(), mock.NewLabelService())
|
||||
handler.OrganizationService = svc
|
||||
handler.BucketService = svc
|
||||
server := httptest.NewServer(handler)
|
||||
|
@ -124,8 +123,7 @@ func TestSecretService_handleGetSecrets(t *testing.T) {
|
|||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
mappingService := mock.NewUserResourceMappingService()
|
||||
h := NewOrgHandler(mappingService)
|
||||
h := NewOrgHandler(mock.NewUserResourceMappingService(), mock.NewLabelService())
|
||||
h.SecretService = tt.fields.SecretService
|
||||
|
||||
u := fmt.Sprintf("http://any.url/api/v2/orgs/%s/secrets", tt.args.orgID)
|
||||
|
@ -195,8 +193,7 @@ func TestSecretService_handlePatchSecrets(t *testing.T) {
|
|||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
mappingService := mock.NewUserResourceMappingService()
|
||||
h := NewOrgHandler(mappingService)
|
||||
h := NewOrgHandler(mock.NewUserResourceMappingService(), mock.NewLabelService())
|
||||
h.SecretService = tt.fields.SecretService
|
||||
|
||||
b, err := json.Marshal(tt.args.secrets)
|
||||
|
@ -272,8 +269,7 @@ func TestSecretService_handleDeleteSecrets(t *testing.T) {
|
|||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
mappingService := mock.NewUserResourceMappingService()
|
||||
h := NewOrgHandler(mappingService)
|
||||
h := NewOrgHandler(mock.NewUserResourceMappingService(), mock.NewLabelService())
|
||||
h.SecretService = tt.fields.SecretService
|
||||
|
||||
b, err := json.Marshal(tt.args.secrets)
|
||||
|
|
106
http/swagger.yml
106
http/swagger.yml
|
@ -2512,6 +2512,112 @@ paths:
|
|||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
'/orgs/{orgID}/labels':
|
||||
get:
|
||||
tags:
|
||||
- Organizations
|
||||
summary: list all labels for a organization
|
||||
parameters:
|
||||
- in: path
|
||||
name: orgID
|
||||
schema:
|
||||
type: string
|
||||
required: true
|
||||
description: ID of the organization
|
||||
responses:
|
||||
'200':
|
||||
description: a list of all labels for an organization
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
labels:
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
links:
|
||||
$ref: "#/components/schemas/Links"
|
||||
default:
|
||||
description: unexpected error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
post:
|
||||
tags:
|
||||
- Organizations
|
||||
summary: add a label to an organization
|
||||
parameters:
|
||||
- in: path
|
||||
name: orgID
|
||||
schema:
|
||||
type: string
|
||||
required: true
|
||||
description: ID of the organization
|
||||
requestBody:
|
||||
description: label to add
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
label:
|
||||
type: string
|
||||
responses:
|
||||
'200':
|
||||
description: a list of all labels for an organization
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
labels:
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
links:
|
||||
$ref: "#/components/schemas/Links"
|
||||
default:
|
||||
description: unexpected error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
'/orgs/{orgID}/labels/{label}':
|
||||
delete:
|
||||
tags:
|
||||
- Organizations
|
||||
summary: delete a label from an organization
|
||||
parameters:
|
||||
- in: path
|
||||
name: orgID
|
||||
schema:
|
||||
type: string
|
||||
required: true
|
||||
description: ID of the organization
|
||||
- in: path
|
||||
name: label
|
||||
schema:
|
||||
type: string
|
||||
required: true
|
||||
description: the label name
|
||||
responses:
|
||||
'204':
|
||||
description: delete has been accepted
|
||||
'404':
|
||||
description: organization not found
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
default:
|
||||
description: unexpected error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
'/orgs/{orgID}/secrets':
|
||||
get:
|
||||
tags:
|
||||
|
|
Loading…
Reference in New Issue