client

package module
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2023 License: MIT Imports: 16 Imported by: 8

README

taubyte/go-auth-http

Release License Go Report Card GoDoc Discord

REST client for interfacing with the Taubyte Auth/Vault Protocol

Installation

go get github.com/taubyte/go-auth-http

Testing

The Mock server has been built in python. Make sure you install dependencies: TODO: move mock to golang http mocks

pip3 install -r test_server/requirements.txt

go test -v ./...

License

Please see the LICENSE file for details.

Help

Find us on our Discord

Maintainers

  • Samy Fodil @samyfodil
  • Sam Stoltenberg @skelouse
  • Tafseer Khan @tafseer-khan

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultTimeout is the default timeout for all requests
	DefaultTimeout = 10 * time.Second

	// CreateRepositoryRetryAttempts is the number of times to retry creating a repository
	CreateRepositoryRetryAttempts = uint(3)

	// CreateRepositoryRetryDelay is the delay between retry attempts
	CreateRepositoryRetryDelay = 300 * time.Millisecond
)

Functions

func ErrorBatchRequest

func ErrorBatchRequest(request string, ids []string, projectId string, err error) error

func ErrorProviderNotSupported

func ErrorProviderNotSupported(provider string) error

Types

type CanBeCreated

type CanBeCreated interface {
	Create(c *Client) error
}

type Client

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

func New

func New(ctx context.Context, options ...Option) (*Client, error)

New returns a new Client based on the options provided and an error

func (*Client) Create

func (c *Client) Create(object CanBeCreated) error

Create creates the given CanBeCreated object with the current client

func (*Client) CreateRepository

func (c *Client) CreateRepository(name string, description string, private bool) (id string, err error)

CreateRepository creates a new repository on the git provider. Returns the repository id and an error

func (*Client) GetProjectById

func (c *Client) GetProjectById(projectId string) (*Project, error)

GetProjectById returns the project with the given id and an error Note: The repository field is not populated

func (*Client) GetRepositoryById

func (c *Client) GetRepositoryById(repoId string) (common.Repository, error)

GetRepositoryById returns a common Repository based on the id and an error

func (*Client) GetRepositoryByName

func (c *Client) GetRepositoryByName(fullName string) (common.Repository, error)

GetRepositoryByName returns a common Repository based on the name and an error

func (*Client) Git

func (c *Client) Git() common.Client

Git returns a git client based on the current git provider Currently only github is supported

func (*Client) ListRepositories

func (c *Client) ListRepositories() ([]common.Repository, error)

ListRepositories returns a list of common Repositories and an error

func (*Client) Projects

func (c *Client) Projects() ([]*Project, error)

Projects returns a list of projects and an error

func (*Client) RegisterDomain

func (c *Client) RegisterDomain(fqdn, projectId string) (response DomainResponse, err error)

RegisterDomain returns information for creating a CNAME record

func (*Client) RegisterRepository

func (c *Client) RegisterRepository(repoId string) error

RegisterRepository registers a git repository with the auth server

func (*Client) UnregisterRepository

func (c *Client) UnregisterRepository(repoId string) error

UnregisterRepository un-registers a git repository from the auth server

func (*Client) User

func (c *Client) User() *User

type CreateProjectData

type CreateProjectData struct {
	Config Repository `json:"config"`
	Code   Repository `json:"code"`
}

CreateProjectData is the data that is sent to the server to create a new project The repositories only need an id that is registered with the server

type Device

type Device struct {
	Project     *Project
	Id          string            `json:"id"`
	Description string            `json:"description"`
	Enabled     bool              `json:"enabled"`
	Name        string            `json:"name"`
	PrivateKey  string            `json:"privateKey"`
	PublicKey   string            `json:"publicKey"`
	Tags        []string          `json:"tags"`
	Type        string            `json:"type"`
	Env         map[string]string `json:"env"`
}

Device is the data that is sent to/from the server when getting or updating a device Note: the client and id of the Project are used in calls to the server

func (*Device) Create

func (d *Device) Create(c *Client) error

Create creates a new device for the project

func (*Device) Update

func (d *Device) Update() error

Update will update a device and return an error Note: you must send a device with all current fields or they also will be changed

type DomainResponse

type DomainResponse struct {
	Token string `json:"token"`
	Entry string `json:"entry"`
	Type  string `json:"type"`
}

type Option

type Option func(c *Client) error

func Auth

func Auth(token string) Option

Auth returns an Option that will set the auth token of the client

func Provider

func Provider(provider string) Option

Provider returns an Option that will set the git provider of the client currently only github is supported

func Timeout

func Timeout(duration time.Duration) Option

Timeout returns an Option that will set the timeout of the client

func URL

func URL(url string) Option

URL returns an Option that will set the url of the auth server

func Unsecure

func Unsecure() Option

Unsecure returns an Option that will allow the client to connect to a server with an invalid certificate

type Project

type Project struct {
	Id       string            `json:"id"`
	Name     string            `json:"name"`
	RepoList *RawRepoDataOuter `json:"Repositories"`
	// contains filtered or unexported fields
}

Project is data which is returned from the server when getting a project Note: filling the RepoList field is a separate call

func (Project) Client

func (o Project) Client() *Client

func (*Project) Config

func (p *Project) Config() (*common.ProjectConfig, error)

Config returns the project configuration and an error The configuration is a "config.yaml" file in the root of the repository

func (*Project) Create

func (p *Project) Create(c *Client, configRepoId string, codeRepoId string) error

Create creates a new project with the registered config and code repository ids

func (*Project) Delete

func (p *Project) Delete() (response deleteResponse, err error)

Delete deletes the project and returns an error

func (*Project) DeleteDevices

func (p *Project) DeleteDevices(deviceIds []string) (deleted []string, err error)

DeleteDevices takes a slice of deviceIds to be deleted, returns the deleted devices and an error

func (*Project) Device

func (p *Project) Device(deviceId string) (*Device, error)

Device returns a type Device and an error

func (*Project) Devices

func (p *Project) Devices() ([]*Device, error)

Devices returns a slice of Device and an error

func (*Project) DisableDevices

func (p *Project) DisableDevices(deviceIds []string) (disabled []string, err error)

DisableDevices attempts to disable given deviceIds, returns the disabled devices and an error

func (*Project) EnableDevices

func (p *Project) EnableDevices(deviceIds []string) (enabled []string, err error)

EnableDevices attempts to enable given deviceIds, returns the enabled devices and an error

func (*Project) Repositories

func (p *Project) Repositories() (*RawRepoDataOuter, error)

Repositories will populate then return the repositories field and an error

type ProjectReturn

type ProjectReturn struct {
	Project *Project `json:"project"`
}

ProjectReturn is the data that is returned from the server when creating or getting a project

type ProjectsReturn

type ProjectsReturn struct {
	Projects []*Project `json:"projects"`
}

ProjectsReturn is the data that is returned from the server when listing projects

type RawRepoData

type RawRepoData struct {
	Id       string `json:"id"` // Not exported by auth.taubyte, must use GetID()
	Name     string `json:"name"`
	Fullname string `json:"fullname"`
	Url      string `json:"url"`
}

RawRepoData is the data that is returned from the server when getting repositories of a project

type RawRepoDataOuter

type RawRepoDataOuter struct {
	Code          RawRepoData `json:"code"`
	Configuration RawRepoData `json:"configuration"`
	Provider      string      `json:"provider"`
	URL           string      `json:"url"`
}

RawRepoDataOuter is the data that is returned from the server when fetching repositories of a project

type Repository

type Repository struct {
	Provider string `json:"provider"`
	Id       string `json:"id"`
}

Repository is the data that is sent to the server to register a repository or for creating a project

type User

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

func (*User) Get

func (u *User) Get() (*UserData, error)

Get will fetch the user data from the server and return UserData and an error

type UserData

type UserData struct {
	Company string `json:"company"`
	Email   string `json:"email"`
	Login   string `json:"login"`
	Name    string `json:"name"`
}

UserData is the data that is returned from the server when getting user data

Directories

Path Synopsis
git

Jump to

Keyboard shortcuts

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