register.go 1.9 KB
Newer Older
H
hongming 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*

 Copyright 2019 The KubeSphere 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 v1alpha2

import (
	"github.com/emicklei/go-restful"
	"github.com/emicklei/go-restful-openapi"
H
hongming 已提交
23
	"k8s.io/api/core/v1"
H
hongming 已提交
24
	"k8s.io/apimachinery/pkg/runtime/schema"
H
hongming 已提交
25
	"kubesphere.io/kubesphere/pkg/api"
H
hongming 已提交
26
	"kubesphere.io/kubesphere/pkg/apiserver/runtime"
H
hongming 已提交
27
	"kubesphere.io/kubesphere/pkg/constants"
28
	"kubesphere.io/kubesphere/pkg/informers"
H
hongming 已提交
29
	"kubesphere.io/kubesphere/pkg/models"
R
runzexia 已提交
30
	"net/http"
H
hongming 已提交
31 32
)

R
runzexia 已提交
33 34 35
const (
	GroupName = "tenant.kubesphere.io"
)
H
hongming 已提交
36 37 38

var GroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1alpha2"}

H
hongming 已提交
39
func AddToContainer(c *restful.Container, factory informers.InformerFactory) error {
H
hongming 已提交
40
	ws := runtime.NewWebService(GroupVersion)
H
hongming 已提交
41
	handler := newTenantHandler(factory)
H
hongming 已提交
42 43

	ws.Route(ws.GET("/workspaces").
H
hongming 已提交
44 45
		To(handler.ListWorkspaces).
		Returns(http.StatusOK, api.StatusOK, models.PageableResponse{}).
R
Ray Zhou 已提交
46
		Doc("List all workspaces that belongs to the current user").
H
hongming 已提交
47
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.TenantResourcesTag}))
H
hongming 已提交
48
	ws.Route(ws.GET("/workspaces/{workspace}/namespaces").
H
hongming 已提交
49
		To(handler.ListNamespaces).
H
hongming 已提交
50
		Param(ws.PathParameter("workspace", "workspace name")).
R
Ray Zhou 已提交
51
		Doc("List the namespaces of the specified workspace for the current user").
H
hongming 已提交
52
		Returns(http.StatusOK, api.StatusOK, []v1.Namespace{}).
H
hongming 已提交
53
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.TenantResourcesTag}))
H
hongming 已提交
54 55 56 57

	c.Add(ws)
	return nil
}