keystone

package module
v0.2.24 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

README

Keystone client

Introduction

The openapi folder is generated from keystone.yaml(i.e. the OAS) using openapi-generator-cli.

Another OAS token.json is not used for now because the openapi-generator-cli v5.3.0 does not support object combinations(oneOf, anyOf and allOf), in which case brings too much complexity.

The options parameter in some APIs is not supported.

Build

./build.sh
Note

For openapi-generator-cli does not support oneOf schema, define OneOfstringprojectResponse in model_project_get.go

type OneOfstringprojectResponse interface{}

Usage

Build client by token
// Build client
client, err := keystone.NewDefaultClientByToken("a_keystone_token")
if err != nil {
    panic(err)
}

// API Call
resp, r, err := client.DomainApi.ListDomains(context.TODO()).Execute()
Build client by password
// Build client
client, err := keystone.NewDefaultClient()
if err != nil {
    panic(err)
}

// Authenticate
domain := "default"
scope := model.NewDomainScope(&domain, nil)
user := "drone"
cred := model.NewPasswordCredential(nil, &user, "password", &domain, nil)
response, err := client.Auth.Authenticate(scope, cred)

if err != nil {
    fmt.Printf("%v\n", response)
    fmt.Printf("%v\n", err)
    panic(err)
}
fmt.Println(client.Token)

// API Call
resp, r, err := client.DomainApi.ListDomains(context.TODO()).Execute()
How to change the server configuration?
Default

The client uses the first server (index=0) defined in OAS by default.

- description: Service domain
  url: http://keystone-api.openstack.svc.cluster.local
Change manually in code

Just edit the config object.

config := openapi.NewConfiguration()
config.Servers = openapi.ServerConfigurations{{
    URL:         "localhost:8000",
}}
client, err := keystone.NewClient(config)

Documentation

Index

Constants

View Source
const (
	MethodPassword = "password"
	MethodToken    = "token"
	DefaultDomain  = "default"
)
View Source
const (
	TokenHeader = "X-Auth-Token"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthManager

type AuthManager struct {
	BaseManager
}

func NewAuthManager

func NewAuthManager(client *Client) *AuthManager

func (*AuthManager) AlterScope

func (m *AuthManager) AlterScope(scope model.Scope) (*req.Resp, error)

func (*AuthManager) Authenticate

func (m *AuthManager) Authenticate(scope interface{}, credential interface{}) (*req.Resp, error)

func (*AuthManager) TokenDetail added in v0.1.2

func (m *AuthManager) TokenDetail() (*req.Resp, error)

type BaseManager

type BaseManager struct {
	URLPath string
	// contains filtered or unexported fields
}

func (*BaseManager) Delete

func (m *BaseManager) Delete(subPath string, vs ...interface{}) (*req.Resp, error)

func (*BaseManager) Do

func (m *BaseManager) Do(method, subPath string, vs ...interface{}) (resp *req.Resp, err error)

func (*BaseManager) Get

func (m *BaseManager) Get(subPath string, vs ...interface{}) (*req.Resp, error)

func (*BaseManager) Head

func (m *BaseManager) Head(subPath string, vs ...interface{}) (*req.Resp, error)

func (*BaseManager) Patch

func (m *BaseManager) Patch(subPath string, vs ...interface{}) (*req.Resp, error)

func (*BaseManager) Post

func (m *BaseManager) Post(subPath string, vs ...interface{}) (*req.Resp, error)

func (*BaseManager) Put

func (m *BaseManager) Put(subPath string, vs ...interface{}) (*req.Resp, error)

type Client

type Client struct {
	*req.Req
	Token   string
	BaseURL *url.URL
	// Managers
	Auth *AuthManager
	// OpenAPI
	*openapi.APIClient
}

func NewClient

func NewClient(config *openapi.Configuration) (*Client, error)

func NewClientByToken added in v0.2.0

func NewClientByToken(config *openapi.Configuration, token string) (*Client, error)

func NewDefaultClient

func NewDefaultClient() (*Client, error)

func NewDefaultClientByToken added in v0.2.0

func NewDefaultClientByToken(token string) (*Client, error)

func (*Client) AuthRequired

func (c *Client) AuthRequired() error

func (*Client) Do

func (c *Client) Do(method, url string, vs ...interface{}) (resp *req.Resp, err error)

func (*Client) SetToken

func (c *Client) SetToken(token string)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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