operations

package
v0.9.7 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Execute

func Execute(oper Operation) error

Types

type ApiOperation

type ApiOperation struct {
	// contains filtered or unexported fields
}
Example (Run_output)
client := &MockNormalApiOperationApiClient{}
oper := NewApiOperation("GET", "https://somewhere", bytes.NewBufferString(""), client)

oper.run()
Output:

{
  "say": "hello"
}
Example (Run_with_error_output)
client := &MockErrorApiOperationApiClient{}
oper := NewApiOperation("GET", "https://somewhere", bytes.NewBufferString(""), client)

oper.run()
Output:

func NewApiOperation

func NewApiOperation(method string, path string, body *bytes.Buffer, client ApiOperationApiClient) *ApiOperation

type ApiOperationApiClient

type ApiOperationApiClient interface {
	Request(method string, path string, body io.Reader) ([]byte, error)
}

type AppOperation

type AppOperation struct {
	// contains filtered or unexported fields
}
Example (Run_delete_confirm_n_output)
client := &MockAppOperationApiClient{}
oper := NewAppOperation("asd", Delete, false, client, &MockAppOperationInputReaderNo{})

oper.run()
Output:

You are attempting to delete asd
This operation cannot be undone. Are you sure? [y/n]:
Example (Run_delete_confirm_y_output)
client := &MockAppOperationApiClient{}
oper := NewAppOperation("asd", Delete, false, client, &MockAppOperationInputReaderYes{})

oper.run()
Output:

You are attempting to delete asd
This operation cannot be undone. Are you sure? [y/n]: Deleted asd
Example (Run_delete_no_confirm_output)
client := &MockAppOperationApiClient{}
oper := NewAppOperation("asd", Delete, true, client, nil /* because it doesnt matter */)

oper.run()
Output:

You are attempting to delete asd
Deleted asd
Example (Run_show_output_when_no_heritage)
client := &MockAppOperationApiClient{}
oper := NewAppOperation("asd", Show, true, client, &MockAppOperationInputReaderYes{})

oper.run()
Output:

func NewAppOperation

func NewAppOperation(name string, op_type OperationType, no_confirm bool, client AppOperationApiClient, input_reader utils.UserInputReader) *AppOperation

type AppOperationApiClient

type AppOperationApiClient interface {
	Get(path string, body io.Reader) ([]byte, error)
	Delete(path string, body io.Reader) ([]byte, error)
}

type LoginInfo

type LoginInfo interface {
	GetEndpoint() string
	GetAuth() string
}

type LoginInfoOperation

type LoginInfoOperation struct {
	// contains filtered or unexported fields
}
Example (Run_output)
package main

import ()

type mockLogin struct{}

func (m mockLogin) GetAuth() string {
	return "fooauth"
}

func (m mockLogin) GetEndpoint() string {
	return "https://example.com"
}

func main() {

	op := NewLoginInfoOperation(&mockLogin{})
	op.run()

}
Output:

Endpoint: https://example.com
Auth:     fooauth

func NewLoginInfoOperation

func NewLoginInfoOperation(info LoginInfo) *LoginInfoOperation

type LoginOperation

type LoginOperation struct {
	// contains filtered or unexported fields
}
Example (Run_output)
op := NewLoginOperation("https://endpoint", "somethingrando", "gh_token", "vault_token", "https://vault_url", &mockLoginOperationExternals{})
op.run()
Output:

Example (Run_with_github)
ext := &mockLoginOperationExternals{
	readString:           "aw\n",
	readError:            nil,
	loginWithGithubUser:  &api.User{},
	loginWithGithubError: nil,
	readFileBytes:        []byte("stuff"),
}

op := NewLoginOperation("https://endpoint", "github", "", "", "", ext)
op.run()
Output:

Logging in with Github
Create new GitHub access token with read:org permission here https://github.com/settings/tokens/new
GitHub Token: Generating your SSH key pair...
Registering your public key...
Example (Run_with_github_already_has_ssh)
ext := &mockLoginOperationExternals{
	readString:           "aw\n",
	readError:            nil,
	loginWithGithubUser:  &api.User{},
	loginWithGithubError: nil,
	readFileBytes:        []byte("stuff"),
	fileExistsBool:       true,
}

op := NewLoginOperation("https://endpoint", "github", "", "", "", ext)
op.run()
Output:

Logging in with Github
Create new GitHub access token with read:org permission here https://github.com/settings/tokens/new
GitHub Token: Registering your public key...
Example (Run_with_github_token)
ext := &mockLoginOperationExternals{
	readString:           "aw\n",
	readError:            nil,
	loginWithGithubUser:  &api.User{},
	loginWithGithubError: nil,
	readFileBytes:        []byte("stuff"),
}

op := NewLoginOperation("https://endpoint", "github", "gh_token", "", "", ext)
op.run()
Output:

Logging in with Github
Generating your SSH key pair...
Registering your public key...
Example (Run_with_github_token_already_has_ssh)
ext := &mockLoginOperationExternals{
	readString:           "aw\n",
	readError:            nil,
	loginWithGithubUser:  &api.User{},
	loginWithGithubError: nil,
	readFileBytes:        []byte("stuff"),
	fileExistsBool:       true,
}

op := NewLoginOperation("https://endpoint", "github", "gh_token", "", "", ext)
op.run()
Output:

Logging in with Github
Registering your public key...
Example (Run_with_vault)
ext := &mockLoginOperationExternals{
	readString:          "aw\n",
	readError:           nil,
	loginWithVaultUser:  &api.User{},
	loginWithVaultError: nil,
	readFileBytes:       []byte("stuff"),
}

op := NewLoginOperation("https://endpoint", "vault", "", "", "", ext)
op.run()
Output:

Logging in with Vault
Create new GitHub access token with read:org permission here https://github.com/settings/tokens/new
GitHub Token: URL of vault server (e.g. https://vault.degica.com)
Vault server URL: Generating your SSH key pair...
Registering your public key...
Example (Run_with_vault_already_has_ssh)
ext := &mockLoginOperationExternals{
	readString:          "aw\n",
	readError:           nil,
	loginWithVaultUser:  &api.User{},
	loginWithVaultError: nil,
	readFileBytes:       []byte("stuff"),
	fileExistsBool:      true,
}

op := NewLoginOperation("https://endpoint", "vault", "", "", "", ext)
op.run()
Output:

Logging in with Vault
Create new GitHub access token with read:org permission here https://github.com/settings/tokens/new
GitHub Token: URL of vault server (e.g. https://vault.degica.com)
Vault server URL: Registering your public key...
Example (Run_with_vault_already_has_ssh_given_url)
ext := &mockLoginOperationExternals{
	readString:          "aw\n",
	readError:           nil,
	loginWithVaultUser:  &api.User{},
	loginWithVaultError: nil,
	readFileBytes:       []byte("stuff"),
	fileExistsBool:      true,
}

op := NewLoginOperation("https://endpoint", "vault", "", "", "https://vaultserv", ext)
op.run()
Output:

Logging in with Vault
Create new GitHub access token with read:org permission here https://github.com/settings/tokens/new
GitHub Token: Registering your public key...
Example (Run_with_vault_given_url)
ext := &mockLoginOperationExternals{
	readString:          "aw\n",
	readError:           nil,
	loginWithVaultUser:  &api.User{},
	loginWithVaultError: nil,
	readFileBytes:       []byte("stuff"),
}

op := NewLoginOperation("https://endpoint", "vault", "", "", "https://vaultserv", ext)
op.run()
Output:

Logging in with Vault
Create new GitHub access token with read:org permission here https://github.com/settings/tokens/new
GitHub Token: Generating your SSH key pair...
Registering your public key...
Example (Run_with_vault_token)
ext := &mockLoginOperationExternals{
	readString:          "aw\n",
	readError:           nil,
	loginWithVaultUser:  &api.User{},
	loginWithVaultError: nil,
	readFileBytes:       []byte("stuff"),
}

op := NewLoginOperation("https://endpoint", "vault", "", "gh_token", "", ext)
op.run()
Output:

Logging in with Vault
URL of vault server (e.g. https://vault.degica.com)
Vault server URL: Generating your SSH key pair...
Registering your public key...
Example (Run_with_vault_token_already_has_ssh)
ext := &mockLoginOperationExternals{
	readString:          "aw\n",
	readError:           nil,
	loginWithVaultUser:  &api.User{},
	loginWithVaultError: nil,
	readFileBytes:       []byte("stuff"),
	fileExistsBool:      true,
}

op := NewLoginOperation("https://endpoint", "vault", "", "gh_token", "", ext)
op.run()
Output:

Logging in with Vault
URL of vault server (e.g. https://vault.degica.com)
Vault server URL: Registering your public key...
Example (Run_with_vault_token_already_has_ssh_given_url)
ext := &mockLoginOperationExternals{
	readString:          "aw\n",
	readError:           nil,
	loginWithVaultUser:  &api.User{},
	loginWithVaultError: nil,
	readFileBytes:       []byte("stuff"),
	fileExistsBool:      true,
}

op := NewLoginOperation("https://endpoint", "vault", "", "gh_token", "https://vaultserv", ext)
op.run()
Output:

Logging in with Vault
Registering your public key...
Example (Run_with_vault_token_given_url)
ext := &mockLoginOperationExternals{
	readString:          "aw\n",
	readError:           nil,
	loginWithVaultUser:  &api.User{},
	loginWithVaultError: nil,
	readFileBytes:       []byte("stuff"),
}

op := NewLoginOperation("https://endpoint", "vault", "", "gh_token", "https://vaultserv", ext)
op.run()
Output:

Logging in with Vault
Generating your SSH key pair...
Registering your public key...
Example (Run_with_vault_token_given_url_but_fails)
ext := &mockLoginOperationExternals{
	readString:          "aw\n",
	readError:           nil,
	loginWithVaultUser:  nil,
	loginWithVaultError: &mockLoginVaultError{},
	readFileBytes:       []byte("stuff"),
}

op := NewLoginOperation("https://endpoint", "vault", "", "gh_token", "https://vaultserv", ext)
op.run()
Output:

Logging in with Vault

func NewLoginOperation

func NewLoginOperation(endpoint string, backend string, ghToken string, vaultToken string, vaultUrl string, ext LoginOperationExternals) *LoginOperation

type LoginOperationClient

type LoginOperationClient interface {
	LoginWithGithub(endpoint string, token string) (*api.User, error)
	LoginWithVault(vault_url string, token string) (*api.User, error)
	Patch(path string, body io.Reader) ([]byte, error)
}

type LoginOperationExternals

type LoginOperationExternals interface {
	// User Input Reader
	Read(secret bool) (string, error)

	// CommandRunner
	RunCommand(name string, arg ...string) error

	// FileOps
	FileExists(path string) bool
	ReadFile(path string) ([]byte, error)

	// Client stuff
	LoginOperationClient
	ReloadDefaultClient() (LoginOperationClient, error)

	// Config stuff
	WriteLogin(auth string, token string, endpoint string) error
	GetPublicKeyPath() string
	GetPrivateKeyPath() string
}

type Operation

type Operation interface {
	// contains filtered or unexported methods
}

type OperationType

type OperationType string
const (
	Delete OperationType = "Delete"
	Show                 = "Show"
)

type ProxyLoginOperationClient

type ProxyLoginOperationClient struct {
	Client *api.Client
}

A proxy class to satisfy the interfaces

func (ProxyLoginOperationClient) LoginWithGithub

func (p ProxyLoginOperationClient) LoginWithGithub(endpoint string, token string) (*api.User, error)

func (ProxyLoginOperationClient) LoginWithVault

func (p ProxyLoginOperationClient) LoginWithVault(vault_url string, token string) (*api.User, error)

func (ProxyLoginOperationClient) Patch

func (p ProxyLoginOperationClient) Patch(path string, body io.Reader) ([]byte, error)

func (ProxyLoginOperationClient) ReloadDefaultClient

func (p ProxyLoginOperationClient) ReloadDefaultClient() (LoginOperationClient, error)

Jump to

Keyboard shortcuts

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