Skip to content

Commit

Permalink
Merge pull request #7096 from ywk253100/190308_policy_api_bak
Browse files Browse the repository at this point in the history
Implement replication policy management API
  • Loading branch information
ywk253100 authored Mar 11, 2019
2 parents 52eb89c + d1f4c20 commit d76e8b1
Show file tree
Hide file tree
Showing 15 changed files with 952 additions and 19 deletions.
239 changes: 239 additions & 0 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2035,6 +2035,167 @@ paths:
description: The resource does not exist.
'500':
description: Unexpected internal errors.
/replication/policies:
get:
summary: List replication policies
description: |
This endpoint let user list replication policies
parameters:
- name: name
in: query
type: string
required: false
description: The replication policy name.
- name: page
in: query
type: integer
format: int32
required: false
description: The page nubmer.
- name: page_size
in: query
type: integer
format: int32
required: false
description: The size of per page.
tags:
- Products
responses:
'200':
description: Get policy successfully.
schema:
type: array
items:
$ref: '#/definitions/ReplicationPolicy'
'400':
$ref: '#/responses/BadRequest'
'401':
$ref: '#/responses/Unauthorized'
'403':
$ref: '#/responses/Forbidden'
'500':
$ref: '#/responses/InternalServerError'
post:
summary: Create a replication policy
description: |
This endpoint let user create a replication policy
parameters:
- name: policy
in: body
description: The policy model.
required: true
schema:
$ref: '#/definitions/ReplicationPolicy'
tags:
- Products
responses:
'201':
$ref: '#/responses/Created'
'400':
$ref: '#/responses/BadRequest'
'401':
$ref: '#/responses/Unauthorized'
'403':
$ref: '#/responses/Forbidden'
'404':
$ref: '#/responses/NotFound'
'409':
$ref: '#/responses/Conflict'
'415':
$ref: '#/responses/UnsupportedMediaType'
'500':
$ref: '#/responses/InternalServerError'
'/replication/policies/{id}':
get:
summary: Get replication policy.
description: |
This endpoint let user get replication policy by specific ID.
parameters:
- name: id
in: path
type: integer
format: int64
required: true
description: policy ID
tags:
- Products
responses:
'200':
description: Get the replication policy successfully.
schema:
$ref: '#/definitions/ReplicationPolicy'
'400':
$ref: '#/responses/BadRequest'
'401':
$ref: '#/responses/Unauthorized'
'403':
$ref: '#/responses/Forbidden'
'404':
$ref: '#/responses/NotFound'
'500':
$ref: '#/responses/InternalServerError'
put:
summary: Update the replication policy
description: |
This endpoint let user update policy.
parameters:
- name: id
in: path
type: integer
format: int64
required: true
description: policy ID
- name: policy
in: body
description: The replication policy model.
required: true
schema:
$ref: '#/definitions/ReplicationPolicy'
tags:
- Products
responses:
'200':
$ref: '#/responses/OK'
'400':
$ref: '#/responses/BadRequest'
'401':
$ref: '#/responses/Unauthorized'
'403':
$ref: '#/responses/Forbidden'
'404':
$ref: '#/responses/NotFound'
'409':
$ref: '#/responses/Conflict'
'500':
$ref: '#/responses/InternalServerError'
delete:
summary: Delete the replication policy specified by ID.
description: |
Delete the replication policy specified by ID.
parameters:
- name: id
in: path
type: integer
format: int64
required: true
description: Replication policy ID
tags:
- Products
responses:
'200':
$ref: '#/responses/OK'
'400':
$ref: '#/responses/BadRequest'
'401':
$ref: '#/responses/Unauthorized'
'403':
$ref: '#/responses/Forbidden'
'404':
$ref: '#/responses/NotFound'
'412':
$ref: '#/responses/PreconditionFailed'
'500':
$ref: '#/responses/InternalServerError'
/labels:
get:
summary: List labels according to the query strings.
Expand Down Expand Up @@ -3505,8 +3666,26 @@ paths:
'500':
description: Unexpected internal errors.
responses:
OK:
description: 'Success'
Created:
description: 'Created'
BadRequest:
description: 'Bad Request'
Unauthorized:
description: 'Unauthorized'
Forbidden:
description: 'Forbidden'
NotFound:
description: 'Not Found'
Conflict:
description: 'Conflict'
PreconditionFailed:
description: 'Precondition Failed'
UnsupportedMediaType:
description: 'The Media Type of the request is not supported, it has to be "application/json"'
InternalServerError:
description: 'Internal Server Error'
definitions:
Search:
type: object
Expand Down Expand Up @@ -3836,6 +4015,57 @@ definitions:
error_job_count:
type: integer
description: The error job count number for the policy.
ReplicationPolicy:
type: object
properties:
id:
type: integer
format: int64
description: The policy ID.
name:
type: string
description: The policy name.
description:
type: string
description: The description of the policy.
src_registry_id:
type: integer
format: int64
description: The source registry ID.
src_namespaces:
type: array
description: The source namespaces
items:
type: string
dest_registry_id:
type: integer
format: int64
description: The destination registry ID.
dest_namespace:
type: string
description: The destination namespace.
trigger:
$ref: '#/definitions/RepTrigger'
filters:
type: array
description: The replication policy filter array.
items:
$ref: '#/definitions/ReplicationFilter'
deletion:
type: boolean
description: Whether to replicate the deletion operation.
override:
type: boolean
description: Whether to override the resources on the destination registry.
enabled:
type: boolean
description: Whether the policy is enabled or not.
creation_time:
type: string
description: The create time of the policy.
update_time:
type: string
description: The update time of the policy.
RepTrigger:
type: object
properties:
Expand Down Expand Up @@ -3873,6 +4103,15 @@ definitions:
metadata:
type: object
description: This map object is the replication policy filter metadata.
ReplicationFilter:
type: object
properties:
type:
type: string
description: 'The replication policy filter type.'
value:
type: string
description: 'The value of replication policy filter.'
RegistryCredential:
type: object
properties:
Expand Down
3 changes: 3 additions & 0 deletions src/core/api/harborapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ func init() {
beego.Router("/api/replication/executions/:id([0-9]+)/tasks", &ReplicationOperationAPI{}, "get:ListTasks")
beego.Router("/api/replication/executions/:id([0-9]+)/tasks/:tid([0-9]+)/log", &ReplicationOperationAPI{}, "get:GetTaskLog")

beego.Router("/api/replication/policies", &ReplicationPolicyAPI{}, "get:List;post:Create")
beego.Router("/api/replication/policies/:id([0-9]+)", &ReplicationPolicyAPI{}, "get:Get;put:Update;delete:Delete")

// Charts are controlled under projects
chartRepositoryAPIType := &ChartRepositoryAPI{}
beego.Router("/api/chartrepo/health", chartRepositoryAPIType, "get:GetHealthStatus")
Expand Down
8 changes: 8 additions & 0 deletions src/core/api/replication_execution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ func (f *fakedPolicyManager) Get(id int64) (*model.Policy, error) {
}
return nil, nil
}
func (f *fakedPolicyManager) GetByName(name string) (*model.Policy, error) {
if name == "duplicate_name" {
return &model.Policy{
Name: "duplicate_name",
}, nil
}
return nil, nil
}
func (f *fakedPolicyManager) Update(*model.Policy, ...string) error {
return nil
}
Expand Down
Loading

0 comments on commit d76e8b1

Please sign in to comment.