endpoint

package
v2.2.2 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: MIT Imports: 2 Imported by: 1

Documentation

Overview

Package endpoint manages the API endpoint details

The API uses an endpoint URL and a semantic version number. This structure manages variations on the defaults and provides a function to access the correct URL

Index

Examples

Constants

View Source
const (
	DefaultBaseURL      = "https://api.gb1.brightbox.com/"
	DefaultVersion      = "1.0"
	DefaultOrbitBaseURL = "https://orbit.brightbox.com/"
	DefaultOrbitVersion = "v1"
)

API constants.

Variables

View Source
var Brightbox = oauth2.Endpoint{
	TokenURL:  DefaultBaseURL + "token/",
	AuthStyle: oauth2.AuthStyleInHeader,
}

Brightbox is the default oauth2 endpoint As Brightbox is a direct access API using oauth2 mechanisms there is no AuthURL. Everything is driven via the TokenURL.

FullScope tokens allow access to both the API and Orbit

View Source
var InfrastructureScope = []string{"infrastructure"}

InfrastructureScope tokens are used to access the Brightbox API

View Source
var OrbitScope = []string{"orbit"}

OrbitScope tokens restrict access to Orbit files only

Functions

This section is empty.

Types

type Config

type Config struct {
	BaseURL string
	Version string
	Account string
	Scopes  []string
}

Config contains the endpoint,version and account of the Brightbox API

BaseURL should be an url of the form https://api.region.brightbox.com, e.g: https://api.gb1.brightbox.com. Leave empty to use the default.

Account should be the identifier of the default account to be used with the API. Clients authenticated with Brightbox APIClient credentials are only ever associated with one single Account, so you can leave this empty for those. Client's authenticated with Brightbox User credentials can have access to multiple accounts, so this parameter should be provided.

Version is the major and minor numbers of the version of the Brightbox API you wish to access. Leave blank to use the default "1.0"

Scopes specify optional requested permissions. Leave blank to request a token that can be used for all Brightbox API operations. Use InfrastructureScope or OrbitScope to restrict the token to those areas.

Example
package main

import (
	"fmt"

	"github.com/brightbox/gobrightbox/v2/endpoint"
)

func main() {
	testConfig := &endpoint.Config{
		BaseURL: "https://api.gb2.brightbox.com",
		Version: "2.0",
	}
	u, err := testConfig.APIURL()
	if err == nil {
		fmt.Println(u.String())
	}
}
Output:

https://api.gb2.brightbox.com/2.0/
Example (Account)
package main

import (
	"fmt"

	"github.com/brightbox/gobrightbox/v2/endpoint"
)

func main() {
	testConfig := &endpoint.Config{
		BaseURL: "https://api.gb2.brightbox.com",
		Version: "2.0",
		Account: "acc-testy",
	}
	u, err := testConfig.APIURL()
	if err == nil {
		fmt.Println(u.String())
	}
}
Output:

https://api.gb2.brightbox.com/2.0/?account_id=acc-testy
Example (Defaults)
package main

import (
	"fmt"

	"github.com/brightbox/gobrightbox/v2/endpoint"
)

func main() {
	testConfig := &endpoint.Config{}
	u, err := testConfig.APIURL()
	if err == nil {
		fmt.Println(u.String())
	}
}
Output:

https://api.gb1.brightbox.com/1.0/
Example (Storage)
package main

import (
	"fmt"

	"github.com/brightbox/gobrightbox/v2/endpoint"
)

func main() {
	testConfig := &endpoint.Config{
		BaseURL: "https://files.gb2.brightbox.com",
		Version: "v2",
	}
	u, err := testConfig.StorageURL()
	if err == nil {
		fmt.Println(u)
	}
}
Output:

https://files.gb2.brightbox.com/v2/
Example (StorageAccount)
package main

import (
	"fmt"

	"github.com/brightbox/gobrightbox/v2/endpoint"
)

func main() {
	testConfig := &endpoint.Config{
		Account: "acc-testy",
	}
	u, err := testConfig.StorageURL()
	if err == nil {
		fmt.Println(u)
	}
}
Output:

https://orbit.brightbox.com/v1/acc-testy/
Example (StorageDefaults)
package main

import (
	"fmt"

	"github.com/brightbox/gobrightbox/v2/endpoint"
)

func main() {
	testConfig := &endpoint.Config{}
	u, err := testConfig.StorageURL()
	if err == nil {
		fmt.Println(u)
	}
}
Output:

https://orbit.brightbox.com/v1/
Example (Token)
package main

import (
	"fmt"

	"github.com/brightbox/gobrightbox/v2/endpoint"
)

func main() {
	testConfig := &endpoint.Config{}
	url, err := testConfig.TokenURL()
	if err == nil {
		fmt.Println(url)
	}
}
Output:

https://api.gb1.brightbox.com/token/

func (*Config) APIURL

func (c *Config) APIURL() (*url.URL, error)

APIURL provides the base URL for accessing the API using the Config entries. Where entries are missing, library defaults will be used.

If Account is set, then a query parameter will be added to the URL to reference that account.

APIURL is part of the [brightbox.Oauth2] access interface.

func (*Config) Endpoint

func (c *Config) Endpoint() (*oauth2.Endpoint, error)

Endpoint provides an oauth2 Endpoint from the Brightbox endpoint entries. Where entries are missing, library defaults will be used.

func (*Config) StorageURL

func (c *Config) StorageURL() (string, error)

StorageURL provides the base URL for accessing Orbit using the Config entries. Where entries are missing, library defaults will be used.

If Account is set, then a query parameter will be added to the URL to reference that account.

func (*Config) TokenURL

func (c *Config) TokenURL() (string, error)

TokenURL provides the OAuth2 URL from the Config BaseURL entries. Where entries are missing, library defaults will be used.

Jump to

Keyboard shortcuts

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