github.com/polarismesh/polaris@v1.17.8/apiserver/httpserver/console_access.go (about)

     1  /*
     2   * Tencent is pleased to support the open source community by making Polaris available.
     3   *
     4   * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
     5   *
     6   * Licensed under the BSD 3-Clause License (the "License");
     7   * you may not use this file except in compliance with the License.
     8   * You may obtain a copy of the License at
     9   *
    10   * https://opensource.org/licenses/BSD-3-Clause
    11   *
    12   * Unless required by applicable law or agreed to in writing, software distributed
    13   * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
    14   * CONDITIONS OF ANY KIND, either express or implied. See the License for the
    15   * specific language governing permissions and limitations under the License.
    16   */
    17  
    18  package httpserver
    19  
    20  import (
    21  	"github.com/emicklei/go-restful/v3"
    22  
    23  	"github.com/polarismesh/polaris/apiserver/httpserver/docs"
    24  )
    25  
    26  const (
    27  	defaultReadAccess string = "default-read"
    28  	defaultAccess     string = "default"
    29  )
    30  
    31  // GetCoreConsoleAccessServer 增加配置中心模块之后,namespace 作为两个模块的公共模块需要独立, restful path 以 /core 开头
    32  func (h *HTTPServer) GetCoreV1ConsoleAccessServer(ws *restful.WebService, include []string) error {
    33  	consoleAccess := []string{defaultAccess}
    34  
    35  	if len(include) == 0 {
    36  		include = consoleAccess
    37  	}
    38  
    39  	var hasDefault = false
    40  	for _, item := range include {
    41  		if item == defaultAccess {
    42  			hasDefault = true
    43  			break
    44  		}
    45  	}
    46  	for _, item := range include {
    47  		switch item {
    48  		case defaultReadAccess:
    49  			if !hasDefault {
    50  				h.addCoreDefaultReadAccess(ws)
    51  			}
    52  		case defaultAccess:
    53  			h.addCoreDefaultAccess(ws)
    54  		}
    55  	}
    56  	return nil
    57  }
    58  
    59  func (h *HTTPServer) addCoreDefaultReadAccess(ws *restful.WebService) {
    60  	ws.Route(ws.GET("/namespaces").To(h.discoverV1.GetNamespaces).Operation("CoreGetNamespaces"))
    61  	ws.Route(ws.GET("/namespaces/token").To(h.discoverV1.GetNamespaceToken).Operation("CoreGetNamespaceToken"))
    62  }
    63  
    64  func (h *HTTPServer) addCoreDefaultAccess(ws *restful.WebService) {
    65  	ws.Route(docs.EnrichCreateNamespacesApiDocs(ws.POST("/namespaces").To(h.discoverV1.CreateNamespaces).
    66  		Operation("CoreCreateNamespaces")))
    67  	ws.Route(docs.EnrichDeleteNamespacesApiDocs(ws.POST("/namespaces/delete").To(h.discoverV1.DeleteNamespaces).
    68  		Operation("CoreDeleteNamespaces")))
    69  	ws.Route(docs.EnrichUpdateNamespacesApiDocs(ws.PUT("/namespaces").To(h.discoverV1.UpdateNamespaces).
    70  		Operation("CoreUpdateNamespaces")))
    71  	ws.Route(docs.EnrichGetNamespacesApiDocs(ws.GET("/namespaces").To(h.discoverV1.GetNamespaces).
    72  		Operation("CoreGetNamespaces")))
    73  	ws.Route(ws.GET("/namespaces/token").To(h.discoverV1.GetNamespaceToken).Operation("CoreGetNamespaceToken"))
    74  	ws.Route(ws.PUT("/namespaces/token").To(h.discoverV1.UpdateNamespaceToken).Operation("CoreUpdateNamespaceToken"))
    75  }