goOpenstackAuth

package module
v0.0.0-...-3ccdb84 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2019 License: Apache-2.0 Imports: 11 Imported by: 1

README

go-openstack-auth

Go openstack auth v3 for getting tokens and endpoints

Example:

import (
	auth "github.com/sapcc/go-openstack-auth"
)

	options := auth.AuthV3Options{
		IdentityEndpoint:  viper.GetString(ENV_VAR_AUTH_URL),
		Region:            viper.GetString(ENV_VAR_REGION),
		Username:          viper.GetString(ENV_VAR_USERNAME),
		UserId:            viper.GetString(ENV_VAR_USER_ID),
		Password:          viper.GetString(ENV_VAR_PASSWORD),
		ProjectName:       viper.GetString(ENV_VAR_PROJECT_NAME),
		ProjectId:         viper.GetString(ENV_VAR_PROJECT_ID),
		UserDomainName:    viper.GetString(ENV_VAR_USER_DOMAIN_NAME),
		UserDomainId:      viper.GetString(ENV_VAR_USER_DOMAIN_ID),
		ProjectDomainName: viper.GetString(ENV_VAR_PROJECT_DOMAIN_NAME),
		ProjectDomainId:   viper.GetString(ENV_VAR_PROJECT_DOMAIN_ID),
	}

	authV3 := auth.AuthenticationV3(options)
	token, err := authV3.GetToken()
	if err != nil {
		fmt.Println(err)
	}

	fmt.Println("°°°TOKEN°°°")
	fmt.Println(token.ID)
	fmt.Println("°°°")

	endpoint, err := authV3.GetServiceEndpoint("arc", "staging", "public")
	if err != nil {
		fmt.Println(err)
	}

	fmt.Println("°°°ENDPOINT°°°")
	fmt.Println(endpoint)
	fmt.Println("°°°")

For testing use the mock object:

import (
	auth "github.com/sapcc/go-openstack-auth"
)

func TestMock(t *testing.T) {
	auth.AuthenticationV3 = auth.NewMockAuthenticationV3
	auth.CommonResult1 = map[string]interface{}{"token": map[string]interface{}{"project": map[string]string{"id": "test_project_id", "domain_id": "test_domain_id", "name": "Arc_Test"}}}
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	AuthenticationV3 = NewAuthV3
)
View Source
var Catalog1 = tokens.ServiceCatalog{
	Entries: []tokens.CatalogEntry{
		{ID: "s-8be070817", Name: "Arc", Type: "arc", Endpoints: []tokens.Endpoint{
			{ID: "e-904f431c9", Region: "staging", Interface: "internal", URL: "https://arc-app-staging/internal"},
			{ID: "e-904f431c9", Region: "staging", Interface: "admin", URL: "https://arc-app-staging/admin"},
			{ID: "e-884f431c9", Region: "staging", Interface: "public", URL: "https://arc-app-staging/public"},
			{ID: "e-904f431c9", Region: "production", Interface: "internal", URL: "https://arc-app-prod/internal"},
			{ID: "e-904f431c9", Region: "production", Interface: "admin", URL: "https://arc-app-prod/admin"},
			{ID: "e-884f431c9", Region: "production", Interface: "public", URL: "https://arc-app-prod/public"},
		}},
		{ID: "s-d5e793744", Name: "Lyra", Type: "automation", Endpoints: []tokens.Endpoint{
			{ID: "e-54b8d28fc", Region: "staging", Interface: "public", URL: "https://lyra-app-staging"},
		}},
	},
}
View Source
var CommonResult1 = map[string]interface{}{"token": map[string]interface{}{"project": map[string]string{"id": "p-9597d2775", "domain_id": "o-monsoon2", "name": ""}}}

Functions

func StringDiff

func StringDiff(text1, text2 string) string

func TestServer

func TestServer(code int, body string, headers map[string]string) *httptest.Server

Types

type AuthOptions

type AuthOptions struct {
	IdentityEndpoint            string
	Username                    string
	UserId                      string
	Password                    string
	ProjectName                 string
	ProjectId                   string
	UserDomainName              string
	UserDomainId                string
	ProjectDomainName           string
	ProjectDomainId             string
	ApplicationCredentialID     string
	ApplicationCredentialName   string
	ApplicationCredentialSecret string
}

type AuthV3

type AuthV3 struct {
	Options AuthOptions
	// contains filtered or unexported fields
}

func (*AuthV3) GetOptions

func (a *AuthV3) GetOptions() *AuthOptions

func (*AuthV3) GetProject

func (a *AuthV3) GetProject() (*Project, error)

func (*AuthV3) GetServiceEndpoint

func (a *AuthV3) GetServiceEndpoint(serviceType, region, serviceInterface string) (string, error)

func (*AuthV3) GetToken

func (a *AuthV3) GetToken() (*tokens.Token, error)

type Authentication

type Authentication interface {
	GetToken() (*tokens.Token, error)
	GetServiceEndpoint(serviceType, region, serviceInterface string) (string, error)
	GetProject() (*Project, error)
	GetOptions() *AuthOptions
}

func NewAuthV3

func NewAuthV3(authOpts AuthOptions) Authentication

func NewMockAuthenticationV3

func NewMockAuthenticationV3(authOpts AuthOptions) Authentication

type MockV3

type MockV3 struct {
	Options AuthOptions

	TestServer *httptest.Server
	// contains filtered or unexported fields
}

func (*MockV3) GetOptions

func (a *MockV3) GetOptions() *AuthOptions

func (*MockV3) GetProject

func (a *MockV3) GetProject() (*Project, error)

func (*MockV3) GetServiceEndpoint

func (a *MockV3) GetServiceEndpoint(serviceType, region, serviceInterface string) (string, error)

func (*MockV3) GetToken

func (a *MockV3) GetToken() (*tokens.Token, error)

type Project

type Project struct {
	Name     string `mapstructure:"name"`
	ID       string `mapstructure:"id"`
	DomainID string `mapstructure:"domain_id"`
}

Jump to

Keyboard shortcuts

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