common

package
v1.0.18 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2023 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ASCIIBanner = `` /* 521-byte string literal not displayed */

	// Viper downcases key names, so hyphenating for better readability.
	// 'Partial' keys are to be combined with the application ID they are associated with.
	// and NOT used by themselves.
	AccessTokenConfigKey         = "access-token"  // user-scoped API access token key
	RefreshTokenConfigKey        = "refresh-token" // user-scoped API refresh token key
	AccountConfigKeyPartial      = "account"       // app-scoped account ID key
	OrganizationConfigKeyPartial = "organization"  // app-scoped organization ID key
	WalletConfigKeyPartial       = "wallet"        // app-scoped HD wallet ID key
)
View Source
const DefaultPage = 1
View Source
const DefaultRpp = 25
View Source
const InfrastructureTargetAWS = "aws"
View Source
const InfrastructureTargetAzure = "azure"

Variables

View Source
var (
	ApplicationID string
	Application   *ident.Application

	WorkgroupID string
	Workgroup   *WorkgroupType

	OrganizationID string
	Organization   *OrganizationType

	UserID          string
	User            *ident.User
	UserAccessToken string

	SubjectAccountID string

	AccountID   string
	ConnectorID string
	ContractID  string
	NetworkID   string
	L2NetworkID string
	NodeID      string
	WalletID    string

	Manifest *provide.Manifest
	Verbose  bool
)
View Source
var (
	EngineID           string
	ProviderID         string
	Region             string
	TargetID           string
	Image              string
	HealthCheckPath    string
	TaskRole           string
	TCPIngressPorts    string
	UDPIngressPorts    string
	AWSAccessKeyID     string
	AWSSecretAccessKey string
	AzureTenantID      string
	AzureClientID      string
	AzureClientSecret  string
)
View Source
var ApplicationAccessToken string
View Source
var BPIEndpoint string
View Source
var CfgFile string
View Source
var EmailValidation = func(input string) error {
	if input == "" {
		return errors.New("email is required")
	}

	re := regexp.MustCompile("^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$")
	if !re.MatchString(input) {
		return errors.New("invalid email")
	}

	return nil

}
View Source
var ExposeBPITunnel bool
View Source
var ExposeMessagingTunnel bool
View Source
var ExposeWebsocketMessagingTunnel bool
View Source
var HexValidation = func(input string) error {
	re := regexp.MustCompile("^0x[0-9a-fA-F]{40}$")
	isHex := re.MatchString(input)

	if !isHex {
		return errors.New("input is not a Hex")
	}
	return nil
}
View Source
var JSONValidation = func(input string) error {
	if len(input) < 1 {
		return errors.New("field cant be nil")
	}

	var js map[string]interface{}
	if json.Unmarshal([]byte(input), &js) != nil {
		return errors.New("invalid JSON")

	}
	return nil
}
View Source
var MandatoryNumberValidation = func(input string) error {
	if len(input) < 1 {
		return errors.New("field cant be nil")
	}
	_, err := strconv.ParseFloat(input, 64)
	if err != nil {
		return errors.New("invalid number")
	}
	return nil
}
View Source
var MandatoryValidation = func(input string) error {
	if input == "" {
		return errors.New("required")
	}
	return nil
}
View Source
var MessagingEndpoint string
View Source
var NoValidation = func(input string) error {
	return nil
}
View Source
var NumberValidation = func(input string) error {
	_, err := strconv.ParseFloat(input, 64)
	if err != nil {
		return errors.New("invalid number")
	}
	return nil
}
View Source
var OrganizationAccessToken string
View Source
var OrganizationRefreshToken string
View Source
var ResolvedBaselineOrgAddress string // HACK
View Source
var Tunnel bool
View Source
var VaultID string
View Source
var WithoutTunnels bool

Functions

func AuthorizeApplicationContext

func AuthorizeApplicationContext()

func AuthorizeOrganizationContext

func AuthorizeOrganizationContext(persist bool)

func BuildConfigKeyWithID

func BuildConfigKeyWithID(keyPartial, id string) string

BuildConfigKeyWithID combines the given key partial and ID according to a consistent convention. Returns an empty string if the given id is empty. Viper's getters likewise return empty strings when passed an empty string.

func CacheAccessRefreshToken

func CacheAccessRefreshToken(token *ident.Token, id *string)

func CacheCommands

func CacheCommands(cmd *cobra.Command)

func CmdExists

func CmdExists(cmd *cobra.Command, args []string) (bool, string)

func CmdExistsOrExit

func CmdExistsOrExit(cmd *cobra.Command, args []string)

func EtherscanBaseURL

func EtherscanBaseURL(networkID string) *string

func FreeInput

func FreeInput(label string, defaultValue string, validate func(string) error) string

func InfrastructureCredentialsConfigFactory

func InfrastructureCredentialsConfigFactory() map[string]interface{}

func InitConfig

func InitConfig()

initConfig reads in config file and ENV variables if set.

func InitWorkgroupContract

func InitWorkgroupContract(contractAddress string) *nchain.Contract

func IsReleaseContext

func IsReleaseContext() bool

IsReleaseContext returns true if `prvd` is run when `pwd` is the root of a Provide release

func IsReleaseRepositoryContext

func IsReleaseRepositoryContext() bool

IsReleaseRepositoryContext is not yet used...

func ListContainers

func ListContainers(docker *client.Client, stack string) []types.Container

func LogContainer

func LogContainer(docker *client.Client, containerID string) error

func LogContainers

func LogContainers(docker *client.Client, wg *sync.WaitGroup, stack string) error

func PromptPagination

func PromptPagination(paginate bool, page uint64, rpp uint64) (uint64, uint64)

func PurgeContainers

func PurgeContainers(docker *client.Client, stack string, purgeVolumes bool)

func PurgeNetwork

func PurgeNetwork(docker *client.Client, stack string)

func RegisterWorkgroupOrganization

func RegisterWorkgroupOrganization(workgroupID string)

func RequireAPIToken

func RequireAPIToken() string

func RequireAccount

func RequireAccount(params map[string]interface{}) error

RequireAccount is equivalent to a required --account flag

func RequireApplication

func RequireApplication() error

RequireApplication is equivalent to a required --application flag

func RequireApplicationToken

func RequireApplicationToken() string

func RequireConnector

func RequireConnector(params map[string]interface{}) error

RequireConnector is equivalent to a required --connector flag

func RequireContract

func RequireContract(contractID, contractType *string, printCreationTxLink bool) (*nchain.Contract, error)

func RequireInfrastructureFlags

func RequireInfrastructureFlags(cmd *cobra.Command, withImage bool)

func RequireL1Network

func RequireL1Network() error

RequireL1Network is equivalent to a required --network flag; but list options filtered to show only public l1 networks

func RequireL2Network

func RequireL2Network() error

RequireL2Network is equivalent to a required --l2 flag; but list options filtered to show only public l2 networks

func RequireNetwork

func RequireNetwork() error

RequireNetwork is equivalent to a required --network flag

func RequireOrganization

func RequireOrganization() error

RequireOrganization is equivalent to a required --organization flag

func RequireOrganizationEndpoints

func RequireOrganizationEndpoints(fn func(), tunnelShutdownFn func(*string), apiPort, messagingPort, websocketMessagingPort int)

RequireOrganizationEndpoints fn is the function to call after the tunnel has been established, prior to the runloop and signal handling is installed

func RequireOrganizationKeypair

func RequireOrganizationKeypair(spec string) (*vault.Key, error)

func RequireOrganizationVault

func RequireOrganizationVault() error

func RequirePrivacyPolicyAgreement

func RequirePrivacyPolicyAgreement() bool

RequirePrivacyPolicyAgreement is equivalent to a required --privacy flag

func RequireTermsOfServiceAgreement

func RequireTermsOfServiceAgreement() bool

RequireTermsOfServiceAgreement is equivalent to a required --terms flag

func RequireUserAccessToken

func RequireUserAccessToken() string

func RequireVault

func RequireVault() error

RequireVault is equivalent to a required --vault flag

func RequireWallet

func RequireWallet() error

RequireWallet is equivalent to a required --wallet flag

func RequireWorkgroup

func RequireWorkgroup() error

RequireWorkgroup is equivalent to a required --workgroup flag

func ResolveOrganizationToken

func ResolveOrganizationToken() (*ident.Token, error)

func SHA256

func SHA256(str string) string

SHA256 is a convenience method to return the sha256 hash of the given input

func SelectInput

func SelectInput(args []string, label string) string

func StopContainers

func StopContainers(docker *client.Client, stack string)

Types

type OrganizationMetadata

type OrganizationMetadata struct {
	Address           string                                       `json:"address"`
	BPIEndpoint       string                                       `json:"bpi_endpoint"`
	Domain            string                                       `json:"domain"`
	MessagingEndpoint string                                       `json:"messaging_endpoint"`
	Workgroups        map[uuid.UUID]*OrganizationWorkgroupMetadata `json:"workgroups"`
}

Organization metadata

type OrganizationType

type OrganizationType struct {
	ident.Organization
	Metadata *OrganizationMetadata `json:"metadata"`
}

Organization model; called OrganizationType because Organization is already declared in common

type OrganizationWorkgroupMetadata

type OrganizationWorkgroupMetadata struct {
	BPIEndpoint              *string                 `json:"bpi_endpoint"`
	MessagingEndpoint        *string                 `json:"messaging_endpoint"`
	OperatorSeparationDegree uint32                  `json:"operator_separation_degree"`
	Privacy                  *WorkgroupMetadataLegal `json:"privacy,omitempty"`
	SystemSecretIDs          []*uuid.UUID            `json:"system_secret_ids"`
	TOS                      *WorkgroupMetadataLegal `json:"tos,omitempty"`
	VaultID                  *uuid.UUID              `json:"vault_id"`
}

Organization workgroup metadata

type WorkgroupConfig

type WorkgroupConfig struct {
	Environment        *string      `json:"environment"`
	L2NetworkID        *uuid.UUID   `json:"l2_network_id"`
	L3NetworkID        *uuid.UUID   `json:"l3_network_id"`
	OnboardingComplete bool         `json:"onboarding_complete"`
	SystemSecretIDs    []*uuid.UUID `json:"system_secret_ids"`
	VaultID            *uuid.UUID   `json:"vault_id"`
	WebhookSecret      *string      `json:"webhook_secret"`
}

WorkgroupConfig is a baseline workgroup configuration object

type WorkgroupMetadataLegal

type WorkgroupMetadataLegal struct {
	AgreedAt  *time.Time `json:"agreed_at"`
	Signature *string    `json:"signature"`
}

Organization workgroup metadata legal data

type WorkgroupType

type WorkgroupType struct {
	baseline.Workgroup
	Config *WorkgroupConfig `json:"config"`
}

Workgroup is a baseline workgroup context; called WorkgroupType because Workgroup is already declared in common

Jump to

Keyboard shortcuts

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