Skip to content

Commit

Permalink
Merge pull request #10681 from ywk253100/200207_legacy_api_version
Browse files Browse the repository at this point in the history
Bump up the version of legacy APIs to v2.0
  • Loading branch information
ywk253100 committed Feb 11, 2020
2 parents 8a74fcb + 6c3399b commit b9a274c
Show file tree
Hide file tree
Showing 13 changed files with 257 additions and 286 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -476,7 +476,7 @@ swagger_client:
wget -q https://repo1.maven.org/maven2/io/swagger/swagger-codegen-cli/2.3.1/swagger-codegen-cli-2.3.1.jar -O swagger-codegen-cli.jar
rm -rf harborclient
mkdir harborclient
java -jar swagger-codegen-cli.jar generate -i api/harbor/swagger.yaml -l python -o harborclient
java -jar swagger-codegen-cli.jar generate -i api/v2.0/legacy_swagger.yaml -l python -o harborclient
cd harborclient; python ./setup.py install
pip install docker -q
pip freeze
Expand Down
File renamed without changes.
58 changes: 2 additions & 56 deletions api/harbor/swagger.yaml → api/v2.0/legacy_swagger.yaml
Expand Up @@ -2,12 +2,12 @@ swagger: '2.0'
info:
title: Harbor API
description: These APIs provide services for manipulating Harbor project.
version: 1.10.0
version: '2.0'
host: localhost
schemes:
- http
- https
basePath: /api
basePath: /api/v2.0
produces:
- application/json
- text/plain
Expand Down Expand Up @@ -2328,60 +2328,6 @@ paths:
description: No registry found.
'500':
description: Unexpected internal errors.
/internal/syncregistry:
post:
summary: Sync repositories from registry to DB.
description: |
This endpoint is for syncing all repositories of registry with database.
tags:
- Products
responses:
'200':
description: Sync repositories successfully.
'401':
description: User need to log in first.
'403':
description: User does not have permission of admin role.
'415':
$ref: '#/responses/UnsupportedMediaType'
'500':
description: Unexpected internal errors.
/internal/syncquota:
post:
summary: Sync quota from registry/chart to DB.
description: |
This endpoint is for syncing quota usage of registry/chart with database.
tags:
- Products
responses:
'200':
description: Sync repositories successfully.
'401':
description: User need to log in first.
'403':
description: User does not have permission of system admin role.
/internal/switchquota:
put:
summary: Enable or disable quota.
description: |
This endpoint is for enable/disable quota. When quota is disabled, no resource require/release in image/chart push and delete.
tags:
- Products
parameters:
- name: switcher
in: body
required: true
schema:
$ref: '#/definitions/QuotaSwitcher'
responses:
'200':
description: Enable/Disable quota successfully.
'401':
description: User need to log in first.
'403':
description: User does not have permission of system admin role.
'500':
description: Unexpected internal errors.
/systeminfo:
get:
summary: Get general system info
Expand Down
2 changes: 1 addition & 1 deletion make/photon/portal/Dockerfile
Expand Up @@ -11,7 +11,7 @@ RUN apt-get update \
COPY src/portal/package.json /build_dir
COPY src/portal/package-lock.json /build_dir
COPY src/portal/scripts /build_dir
COPY ./api/harbor/swagger.yaml /build_dir
COPY ./api/v2.0/legacy_swagger.yaml /build_dir/swagger.yaml
COPY ./api/v2.0/swagger.yaml /build_dir/swagger2.yaml

RUN python -c 'import sys, yaml, json; y=yaml.load(sys.stdin.read()); print json.dumps(y)' < swagger.yaml > swagger.json
Expand Down
68 changes: 68 additions & 0 deletions src/server/route.go
@@ -0,0 +1,68 @@
// Copyright Project Harbor Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package server

import (
"github.com/astaxie/beego"
"github.com/goharbor/harbor/src/common"
"github.com/goharbor/harbor/src/core/api"
"github.com/goharbor/harbor/src/core/config"
"github.com/goharbor/harbor/src/core/controllers"
"github.com/goharbor/harbor/src/core/service/notifications/admin"
"github.com/goharbor/harbor/src/core/service/notifications/jobs"
"github.com/goharbor/harbor/src/core/service/notifications/registry"
"github.com/goharbor/harbor/src/core/service/notifications/scheduler"
"github.com/goharbor/harbor/src/core/service/token"
)

func registerRoutes() {
// Controller API:
beego.Router("/c/login", &controllers.CommonController{}, "post:Login")
beego.Router("/c/log_out", &controllers.CommonController{}, "get:LogOut")
beego.Router("/c/reset", &controllers.CommonController{}, "post:ResetPassword")
beego.Router("/c/userExists", &controllers.CommonController{}, "post:UserExists")
beego.Router("/c/sendEmail", &controllers.CommonController{}, "get:SendResetEmail")
beego.Router(common.OIDCLoginPath, &controllers.OIDCController{}, "get:RedirectLogin")
beego.Router("/c/oidc/onboard", &controllers.OIDCController{}, "post:Onboard")
beego.Router(common.OIDCCallbackPath, &controllers.OIDCController{}, "get:Callback")

beego.Router("/api/internal/configurations", &api.ConfigAPI{}, "get:GetInternalConfig;put:Put")
beego.Router("/api/internal/syncregistry", &api.InternalAPI{}, "post:SyncRegistry")
beego.Router("/api/internal/renameadmin", &api.InternalAPI{}, "post:RenameAdmin")
beego.Router("/api/internal/switchquota", &api.InternalAPI{}, "put:SwitchQuota")
beego.Router("/api/internal/syncquota", &api.InternalAPI{}, "post:SyncQuota")

beego.Router("/service/notifications", &registry.NotificationHandler{})
beego.Router("/service/notifications/jobs/adminjob/:id([0-9]+)", &admin.Handler{}, "post:HandleAdminJob")
beego.Router("/service/notifications/jobs/replication/:id([0-9]+)", &jobs.Handler{}, "post:HandleReplicationScheduleJob")
beego.Router("/service/notifications/jobs/replication/task/:id([0-9]+)", &jobs.Handler{}, "post:HandleReplicationTask")
beego.Router("/service/notifications/jobs/webhook/:id([0-9]+)", &jobs.Handler{}, "post:HandleNotificationJob")
beego.Router("/service/notifications/jobs/retention/task/:id([0-9]+)", &jobs.Handler{}, "post:HandleRetentionTask")
beego.Router("/service/notifications/schedules/:id([0-9]+)", &scheduler.Handler{}, "post:Handle")
beego.Router("/service/notifications/jobs/scan/:uuid", &jobs.Handler{}, "post:HandleScan")

beego.Router("/service/token", &token.Handler{})

// chart repository services
if config.WithChartMuseum() {
chartRepositoryAPIType := &api.ChartRepositoryAPI{}
beego.Router("/chartrepo/:repo/index.yaml", chartRepositoryAPIType, "get:GetIndexByRepo")
beego.Router("/chartrepo/index.yaml", chartRepositoryAPIType, "get:GetIndex")
beego.Router("/chartrepo/:repo/charts/:filename", chartRepositoryAPIType, "get:DownloadChart")
}

// Error pages
beego.ErrorController(&controllers.ErrorController{})
}
7 changes: 2 additions & 5 deletions src/server/server.go
Expand Up @@ -16,15 +16,12 @@ package server

import (
"github.com/goharbor/harbor/src/server/registry"
// "github.com/goharbor/harbor/src/server/registry"
v1 "github.com/goharbor/harbor/src/server/v1.0/route"
v2 "github.com/goharbor/harbor/src/server/v2.0/route"
)

// RegisterRoutes register all routes
func RegisterRoutes() {
// TODO move the v1 APIs to v2
v1.RegisterRoutes() // v1.0 APIs
v2.RegisterRoutes() // v2.0 APIs
registerRoutes() // service/internal API/UI controller/etc.
registry.RegisterRoutes() // OCI registry APIs
v2.RegisterRoutes() // v2.0 APIs
}

0 comments on commit b9a274c

Please sign in to comment.