openapi

package
v1.3.0-rc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 10, 2021 License: Apache-2.0 Imports: 34 Imported by: 0

README

* OpenAPI

** 新增API
    - 在目录 =/openapi/api/apis/= 下新增go文件,(example.go)
#+BEGIN_SRC go
  //example.go
  package apis

  var EXAMPLE = ApiSpec{
	  Path:        "/example/<example-id>/path",
	  BackendPath: "/example/backend/<example-id>/path",
	  Host:        "example.dice.marathon.l4lb.thisdcos.directory:9093",
	  Scheme:      "http",
	  Method:      "GET",
	  CheckLogin:  true,	// 是否需要验证登陆
	  CheckToken:  true,    // 是否用token验证
	  // doc: swagger spec, https://swagger.io/docs/specification/2-0/basic-structure
	  // json: {"desc": "string", "id": 1, "stats": {"timeLastModified": "2018-2-3 15:32:33"}}
	  Doc:         `
  summary: example-summary
  parameters:
    - in: path
      name: example-id
      type: integer
      required: true
      produces:
    - application/json
  responses:
    '200':
      description: OK
      schema:
	type: object
	properties:
	  desc:
	    type: string
	  id:
	    type: integer
	  stats:
	    type: object
	    properties:
	      timeLastModified:
		type: string
		format: date-time
  `,
  }

#+END_SRC   

    - make openapi



** token验证
   
*** 1. 创建 Client
#+BEGIN_SRC 
curl -XPOST $OPENAPIHOST/api/openapi/manager/clients -d '{
"accessTokenValiditySeconds": 433200, "autoApprove": false,
"clientId": "testId",
"clientLogoUrl": "http://123.com ", "clientNam e": "测试应用", "clientSecret": "secret", "refreshTokenValiditySeconds": 433200, "userId": 1
}'
#+END_SRC

- accessTokenValiditySeconds token有效时长(单位s)



*** 2. 申请 Token
#+BEGIN_SRC 
SECRET = base64(<client-Id>:<client-secret>)
curl -XPOST $OPENAPIHOST/api/openapi/client-token -H "Authorization: Basic $SECRET"
#+END_SRC    


*** 3. 使用Token
测试token是否生效:
#+BEGIN_SRC 
curl $OPENAPIHOST/api/openapi/client-token -H "Authorization: Bearer <token>"   <----- 注意有个空格
#+END_SRC

对于 =CheckToken=true= 的API,可以使用token验证


*** 4. 后端服务
    请求至后端服务在Header中有 Client-ID, Client-Name 信息


** BasicAuth 验证
   对 =CheckBasicAuth=true= 的API有效
   
   token = base64(<username>:<password>)
   
   http header: "Authorization: Basic <token>"

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetRealIP

func GetRealIP(request *http.Request) string

GetRealIP 获取真实ip

func IsHTTPS

func IsHTTPS(req *http.Request) (bool, error)

func NewReverseProxyWithAuth

func NewReverseProxyWithAuth(auth *auth.Auth, bundle *bundle.Bundle) (http.Handler, error)

func NewServer

func NewServer() (*http.Server, error)

Types

type ApiData

type ApiData struct {
	Success bool        `json:"success"`
	Err     interface{} `json:"err"`
	Data    interface{} `json:"data"`
}

type LoginServer

type LoginServer struct {
	// contains filtered or unexported fields
}

func NewLoginServer

func NewLoginServer() (*LoginServer, error)

func (*LoginServer) LoginCB

func (s *LoginServer) LoginCB(rw http.ResponseWriter, req *http.Request)

func (*LoginServer) Logout

func (s *LoginServer) Logout(rw http.ResponseWriter, req *http.Request)

func (*LoginServer) PwdLogin

func (s *LoginServer) PwdLogin(rw http.ResponseWriter, req *http.Request)

func (*LoginServer) ServeHTTP

func (s *LoginServer) ServeHTTP(rw http.ResponseWriter, req *http.Request)

func (*LoginServer) UserInfo

func (s *LoginServer) UserInfo(rw http.ResponseWriter, req *http.Request)

type PwdLoginRequest

type PwdLoginRequest struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

type PwdLoginResponse

type PwdLoginResponse struct {
	SessionID string `json:"sessionid"`
	ucauth.UserInfo
}

type ReverseProxyWithAuth

type ReverseProxyWithAuth struct {
	// contains filtered or unexported fields
}

func (*ReverseProxyWithAuth) ServeHTTP

func (r *ReverseProxyWithAuth) ServeHTTP(rw http.ResponseWriter, req *http.Request)

Directories

Path Synopsis
api
apis/dicehub
Package apis dice api集合 Package apis dice api集合
Package apis dice api集合 Package apis dice api集合
Package monitor collect and export openapi metrics Package monitor collect and export openapi metrics
Package monitor collect and export openapi metrics Package monitor collect and export openapi metrics
ws

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL