clients

package
v0.0.0-...-23a2324 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2024 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBadRequest   = usrerr.New(401, "backend service returned bad request", "")
	ErrNotFound     = usrerr.New(404, "backend service returned not found or no data", "")
	ErrUnauthorized = usrerr.New(401, "backend service returned unauthorized", "")

	ErrUnknownAuthenticationType  = usrerr.New(500, "unknown authentication type", "sources backend error")
	ErrUnknownProvider            = usrerr.New(500, "unknown provider type", "sources backend error")
	ErrMissingProvisioningSources = usrerr.New(500, "missing provisioning source authentication", "sources backend error")

	ErrUnexpectedBackendResponse = usrerr.New(500, "backend service returned unexpected HTTP code", "unexpected backend data")
	ErrNoResponseData            = usrerr.New(500, "no data in response", "missing backend data")
)
View Source
var ErrArchitectureNotSupported = errors.New("architecture is not supported")
View Source
var ErrRegionAndZoneSplit = errors.New("unable to split region and zone for")
View Source
var ErrUnknownRegionZoneCombination = errors.New("unknown region and zone combination")
View Source
var GetAzureClient = func(ctx context.Context, auth *Authentication) (Azure, error) {
	panic("client func not initialized")
}

GetAzureClient returns an Azure client with customer's subscription ID.

View Source
var GetEC2Client = func(ctx context.Context, auth *Authentication, region string) (EC2, error) {
	panic("client func not initialized")
}

GetEC2Client returns an EC2 facade interface with assumed role.

View Source
var GetGCPClient = func(ctx context.Context, auth *Authentication) (GCP, error) {
	panic("client func not initialized")
}

GetGCPClient returns a GCP facade interface.

View Source
var GetImageBuilderClient = func(ctx context.Context) (ImageBuilder, error) {
	panic("client func not initialized")
}

GetImageBuilderClient returns ImageBuilder interface implementation. There are currently two implementations available: HTTP and stub

View Source
var GetRbacClient func(ctx context.Context) Rbac

GetRbacClient returns RBAC interface implementation. There are currently two implementations available: HTTP and stub. In case the client could not be established, the function logs an error and returns an implementation that does not allow any permission.

View Source
var GetServiceAzureClient = func(ctx context.Context) (ServiceAzure, error) {
	panic("client func not initialized")
}

GetServiceAzureClient returns an Azure client for the service account itself.

View Source
var GetServiceEC2Client = func(ctx context.Context, region string) (EC2, error) {
	panic("client func not initialized")
}

GetServiceEC2Client returns an EC2 client for the service account.

View Source
var GetServiceGCPClient func(ctx context.Context) (ServiceGCP, error)

GetServiceGCPClient returns a GCP client for the service account.

View Source
var GetSourcesClient = func(ctx context.Context) (Sources, error) {
	panic("client func not initialized")
}

GetSourcesClient returns Sources interface implementation. There are currently two implementations available: HTTP and stub

Functions

func ConcatBuffers

func ConcatBuffers(fsTypes embed.FS, path string) []byte

Types

type AWSInstanceParams

type AWSInstanceParams struct {
	// The template id to use in order to launch an instance
	LaunchTemplateID string

	// ami of the instance will be launched from
	AMI string

	// InstanceType to launch
	InstanceType types.InstanceType

	// Zone - to deploy into
	Zone string

	// Pubkey to use for the instance access
	KeyName string

	// UserData for the instance launch
	UserData []byte
}

type Access

type Access struct {
	Resource string `json:"resource"`
	Verb     string `json:"verb"`
}

Access represents a permission. ResourceDefinitions are ignored. Inspired by https://github.com/RedHatInsights/rbac-client-go

func NewAccess

func NewAccess(access string) Access

NewAccess constructs new Access from a string in the form of "application:resource:verb". The string may contain wildcards (*).

type AccessList

type AccessList []Access

func (AccessList) CacheKeyName

func (AccessList) CacheKeyName() string

func (AccessList) IsAllowed

func (l AccessList) IsAllowed(res, verb string) bool

IsAllowed returns whether an action against a resource is allowed by an AccessList taking wildcards into consideration.

func (AccessList) String

func (l AccessList) String() string

type AccountDetailsAWS

type AccountDetailsAWS struct {
	AccountID string `json:"account_id" yaml:"account_id"`
}

func (AccountDetailsAWS) CacheKeyName

func (a AccountDetailsAWS) CacheKeyName() string

type AccountDetailsAzure

type AccountDetailsAzure struct {
	TenantID       AzureTenantId `json:"tenant_id"`
	SubscriptionID string        `json:"subscription_id"`
	ResourceGroups []string      `json:"resource_groups"`
}

type AccountDetailsGCP

type AccountDetailsGCP struct{}

type AccountIdentity

type AccountIdentity struct {
	AWSDetails *AccountDetailsAWS `json:"aws,omitempty" yaml:"aws"`
}

type ArchitectureType

type ArchitectureType string
const (
	ArchitectureTypeI386        ArchitectureType = "i386"
	ArchitectureTypeX86_64      ArchitectureType = "x86_64"
	ArchitectureTypeArm64       ArchitectureType = "arm64"
	ArchitectureTypeAppleX86_64 ArchitectureType = "apple-x86_64"
	ArchitectureTypeAppleArm64  ArchitectureType = "apple-arm64"
)

func MapArchitectures

func MapArchitectures(_ context.Context, arch string) (ArchitectureType, error)

func (*ArchitectureType) String

func (at *ArchitectureType) String() string

type Authentication

type Authentication struct {
	SourceApplictionID string              `json:"source_application_id"`
	ProviderType       models.ProviderType `json:"type"`
	Payload            string              `json:"payload"`
}

func NewAuthentication

func NewAuthentication(str string, provType models.ProviderType) *Authentication

func NewAuthenticationFromSourceAuthType

func NewAuthenticationFromSourceAuthType(ctx context.Context, str, authType, appID string) (*Authentication, error)

func (*Authentication) Is

func (auth *Authentication) Is(providerType models.ProviderType) bool

Is checks if Authentication is of a given provider type

func (*Authentication) MustBe

func (auth *Authentication) MustBe(providerType models.ProviderType) error

MustBe returns nil, if authentication is of given type. Otherwise, returns an error.

func (*Authentication) String

func (auth *Authentication) String() string

String returns authentication payload string (ARN, Subscription UUID, Project-ID...)

func (*Authentication) Type

func (auth *Authentication) Type() models.ProviderType

Type returns authentication provider type

type Azure

type Azure interface {
	ClientStatuser

	// TenantId returns current subscription's tenant
	TenantId(ctx context.Context) (AzureTenantId, error)

	// EnsureResourceGroup makes sure that group with give name exists in a location
	EnsureResourceGroup(ctx context.Context, name string, location string) (AzureResourceGroup, error)

	// CreateVMs creates multiple Azure virtual machines
	// Returns array of instance IDs and error if something went wrong
	CreateVMs(ctx context.Context, instanceParams AzureInstanceParams, amount int64, vmNamePrefix string) (vmIds []InstanceDescription, err error)

	ListResourceGroups(ctx context.Context) ([]string, error)
}

type AzureInstanceID

type AzureInstanceID string

type AzureInstanceParams

type AzureInstanceParams struct {
	// Location - to deploy into, defaults to Resource Group location
	Location string

	// ResourceGroupName to launch the instance in
	ResourceGroupName string

	// ImageID - the Image ID in format of full Azure ID as
	// for example /subscriptions/{subscriptionID}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/images/{imageName}
	ImageID string

	// Pubkey to use for the instance access
	Pubkey *models.Pubkey

	// InstanceType to launch
	InstanceType InstanceTypeName

	// UserData for the instance launch
	UserData []byte

	// Tags carries list of key-value tags
	Tags map[string]*string
}

AzureInstanceParams define parameters for a single instance launch on Azure.

type AzureOfferingTemplate

type AzureOfferingTemplate struct {
	// OfferingDefaultName that Customer can change while deploying the offering
	OfferingDefaultName string

	// OfferingDefaultDescription describing the offering, can be changed by Customer while deploying
	OfferingDefaultDescription string

	// TenantID of the offering tenant (Azure account)
	TenantID string

	// PrincipalID of the App that will act as an offering Principal or a group that has the service principal as a member.
	PrincipalID string

	// PrincipalName of the offering principal - the display name
	PrincipalName string
}

func (AzureOfferingTemplate) Render

func (tempParams AzureOfferingTemplate) Render(ctx context.Context, wr io.Writer) error

type AzureResourceGroup

type AzureResourceGroup struct {
	ID       string
	Name     string
	Location string
}

type AzureTenantId

type AzureTenantId string

func (AzureTenantId) CacheKeyName

func (a AzureTenantId) CacheKeyName() string

type ClientStatuser

type ClientStatuser interface {
	Status(ctx context.Context) error
}

ClientStatuser provides a function to test client connection. Since most clouds do not provide any "ping" or "status" call, it is usually implemented via some "cheap" operation which is fast and returns minimum amount of data (e.g. list regions or ssh-keys).

type EC2

type EC2 interface {
	ClientStatuser

	// ListAllRegions returns list of all EC2 regions.
	ListAllRegions(ctx context.Context) ([]Region, error)

	// ListAllZones returns list of all EC2 zones within a Region.
	ListAllZones(ctx context.Context, region Region) ([]Zone, error)

	// ImportPubkey imports new ssh key-pair with given tag returning its AWS ID.
	ImportPubkey(ctx context.Context, key *models.Pubkey, tag string) (string, error)

	// GetPubkeyName fetches the AWS key name using given pubkey fingerprint.
	GetPubkeyName(ctx context.Context, fingerprint string) (string, error)

	// DeleteSSHKey deletes a given ssh key-pair found by AWS ID.
	DeleteSSHKey(ctx context.Context, handle string) error

	// ListInstanceTypesWithPaginator lists all instance types.
	ListInstanceTypes(ctx context.Context) ([]*InstanceType, error)

	// ListLaunchTemplates lists all launch templates and returns the next page token.
	ListLaunchTemplates(ctx context.Context) ([]*LaunchTemplate, string, error)

	// RunInstances launches one or more instances.
	//
	// All arguments are required except: launchTemplateID (empty string means no template in use).
	//
	RunInstances(ctx context.Context, details *AWSInstanceParams, amount int32, name string, reservation *models.AWSReservation) ([]*string, *string, error)

	// GetAccountId returns AWS account number.
	GetAccountId(ctx context.Context) (string, error)

	CheckPermission(ctx context.Context, auth *Authentication) ([]string, error)

	DescribeInstanceDetails(ctx context.Context, InstanceIds []string) ([]*InstanceDescription, error)
}

type GCP

type GCP interface {
	ClientStatuser

	// ListAllRegions returns list of all GCP regions
	ListAllRegions(ctx context.Context) ([]Region, error)

	// InsertInstances launches one or more instances and returns a list of instances ids that were created, the GCP operation name and error
	InsertInstances(ctx context.Context, params *GCPInstanceParams, amount int64) ([]*string, *string, error)

	// List of instance IDs associated with a specific label UUID, which serves as a unique identifier for the reservation used when creating these instances
	ListInstancesIDsByLabel(ctx context.Context, uuid string) ([]*string, error)

	GetInstanceDescriptionByID(ctx context.Context, id, zone string) (*InstanceDescription, error)

	// ListLaunchTemplates lists all launch templates and returns the next page token.
	ListLaunchTemplates(ctx context.Context) ([]*LaunchTemplate, string, error)
}

type GCPInstanceParams

type GCPInstanceParams struct {
	// The string pattern used for the name of the VM.
	NamePattern *string

	// Image Name the instance will be launched from
	ImageName string

	// InstanceType to launch
	MachineType string

	// ReservationID contains reservation ID that is stored in GCP label
	ReservationID int64

	// UUID for instance that was created in a reservation
	UUID string

	// The template id to use in order to launch an instance
	LaunchTemplateID string

	// Zone - to deploy into
	Zone string

	// Pubkey to use for the instance access
	KeyBody string

	// StartupScript contains metadata startup script (GCP tools must be installed on the image)
	StartupScript string
}

type ImageBuilder

type ImageBuilder interface {
	// GetAWSAmi returns related AWS image AMI identifier
	// It also verifies the image is built successfully and for the right architecture.
	GetAWSAmi(ctx context.Context, composeUUID uuid.UUID, instanceType InstanceType) (string, error)

	// GetAzureImageInfo returns Resource Group name and image name from the image builder info.
	// It also verifies the image is built successfully and for the right architecture.
	GetAzureImageInfo(ctx context.Context, composeUUID uuid.UUID, instanceType InstanceType) (string, string, error)

	// GetGCPImageName returns GCP image name
	// It also verifies the image is built successfully and for the right architecture.
	GetGCPImageName(ctx context.Context, composeUUID uuid.UUID, instanceType InstanceType) (string, error)

	// Ready returns readiness information
	Ready(ctx context.Context) error
}

ImageBuilder interface provides access to the Image Builder backend service API

type InstanceDescription

type InstanceDescription struct {
	// The id of the instance
	ID string `json:"id,omitempty" yaml:"id"`

	// The public IPv4 dns of the instance or empty when not available
	DNS string `json:"dns,omitempty" yaml:"dns"`

	// The public IPv4 of the instance or empty when not available
	IPv4 string `json:"ipv4,omitempty" yaml:"ipv4"`

	// The IPv4 of the instance or empty when not available
	PrivateIPv4 string `json:"private_ipv4,omitempty" yaml:"private_ipv4"`

	// The IPv6 of the instance or empty when not available
	PrivateIPv6 string `json:"private_ipv6,omitempty" yaml:"private_ipv6"`
}

InstanceDescription defines a model for an instance description

type InstanceType

type InstanceType struct {
	// The name of the instance type
	Name InstanceTypeName `json:"name,omitempty" yaml:"name"`

	// Virtual CPU (maps to hypervisor hyper-thread)
	VCPUs int32 `json:"vcpus,omitempty" yaml:"vcpus"`

	// Core (physical or virtual core)
	Cores int32 `json:"cores,omitempty" yaml:"cores"`

	// The size of the memory, in MiB.
	MemoryMiB int64 `json:"memory_mib,omitempty" yaml:"memory_mib"`

	// The total size of ephemeral disks, in GB. Is set to 0 if local disk(s) are not available.
	EphemeralStorageGB int64 `json:"storage_gb" yaml:"storage_gb"`

	// Does the instance type supports RHEL
	Supported bool `json:"supported" yaml:"supported"`

	// Instance type's Architecture: i386, arm64, x86_64
	Architecture ArchitectureType `json:"architecture,omitempty" yaml:"arch"`

	// Extra information for Azure, nil for other types
	AzureDetail *InstanceTypeDetailAzure `json:"azure,omitempty" yaml:"azure,omitempty"`
}

InstanceType defines a model for an instance type that corresponds to one in a cloud provider.

func (*InstanceType) SetEphemeralStorageFromMB

func (it *InstanceType) SetEphemeralStorageFromMB(storageMb int64)

func (*InstanceType) SetMemoryFromBytes

func (it *InstanceType) SetMemoryFromBytes(memKib int64)

func (*InstanceType) SetMemoryFromGiB

func (it *InstanceType) SetMemoryFromGiB(memGib int64)

func (*InstanceType) SetMemoryFromKiB

func (it *InstanceType) SetMemoryFromKiB(memKib int64)

func (*InstanceType) String

func (it *InstanceType) String() string

type InstanceTypeDetailAzure

type InstanceTypeDetailAzure struct {
	GenV1 bool `json:"gen_v1" yaml:"gen_v1"`
	GenV2 bool `json:"gen_v2" yaml:"gen_v2"`
}

InstanceTypeDetailAzure contains specific details for Azure.

type InstanceTypeInfo

type InstanceTypeInfo struct {
	RegisteredTypes      RegisteredInstanceTypes
	RegionalAvailability RegionalTypeAvailability
}

func (*InstanceTypeInfo) InstanceTypesForZone

func (iii *InstanceTypeInfo) InstanceTypesForZone(region, zone string, supported *bool) ([]*InstanceType, error)

type InstanceTypeName

type InstanceTypeName string

func (*InstanceTypeName) String

func (it *InstanceTypeName) String() string

type LaunchTemplate

type LaunchTemplate struct {
	// ID is an identifier, for example "lt-94397398248932342" for AWS EC2.
	ID string

	// Name describes the launch template, user defined.
	Name string
}

LaunchTemplate represents a generic launch template for a hyperscaler.

type Rbac

type Rbac interface {
	// GetPrincipalAccess return an ACL object that can be used to check permissions
	GetPrincipalAccess(ctx context.Context) (RbacAcl, error)

	// Ready returns readiness information
	Ready(ctx context.Context) error
}

Rbac interface provides access to the RBAC backend service API. Each action that needs to check must provide resource (e.g. pubkey) and action (e.g. write) in order to check permission presence for principal that is in the identity headers. Definition of permissions and default roles are at https://github.com/RedHatInsights/rbac-config (app named "provisioning").

type RbacAcl

type RbacAcl interface {
	// IsAllowed checks if current account can perform "verb" on particular "resource"
	IsAllowed(res, verb string) bool
}

RBAC Access Control List is used to determine if current account can perform an operation on a particular resource

var AllPermissionsRbacAcl RbacAcl = allPermAcl{}

AllPermissionsRbacAcl is an access list which grants all access. This is used in unit tests.

var NoPermissionsRbacAcl RbacAcl = noPermAcl{}

NoPermissionsRbacAcl is an access list which denies all access. This is used in case there is no ACL in context.

type Region

type Region string

Region represents a provider's region (e.g. 'us-east-1' for EC2 or 'eastus' for Azure)

func (Region) String

func (r Region) String() string

type RegionalTypeAvailability

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

RegionalTypeAvailability type is used to capture available instance types per region and zone.

func NewRegionalInstanceTypes

func NewRegionalInstanceTypes() *RegionalTypeAvailability

func (*RegionalTypeAvailability) Add

func (rit *RegionalTypeAvailability) Add(region, zone string, it InstanceType)

func (*RegionalTypeAvailability) Load

func (rit *RegionalTypeAvailability) Load(fsTypes embed.FS, path string) error

func (*RegionalTypeAvailability) NamesForZone

func (rit *RegionalTypeAvailability) NamesForZone(region, zone string) ([]InstanceTypeName, error)

func (*RegionalTypeAvailability) Save

func (rit *RegionalTypeAvailability) Save(directory string) error

func (*RegionalTypeAvailability) Sprint

func (rit *RegionalTypeAvailability) Sprint(fRegion, fZone string) string

type RegisteredInstanceTypes

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

RegisteredInstanceTypes holds all details about instance types.

func NewRegisteredInstanceTypes

func NewRegisteredInstanceTypes() *RegisteredInstanceTypes

func (*RegisteredInstanceTypes) Get

Get returns instance type by name or nil when such type does not exist.

func (*RegisteredInstanceTypes) Load

func (rit *RegisteredInstanceTypes) Load(buffer []byte) error

Load existing instances from YAML buffer

func (*RegisteredInstanceTypes) Print

func (rit *RegisteredInstanceTypes) Print(typeName string)

Print is useful for debugging

func (*RegisteredInstanceTypes) Register

func (rit *RegisteredInstanceTypes) Register(it InstanceType)

Register puts instance type into the list and sets the supported flag. Currently, only instances with more than 1.5 GB (not GiB) are considered as supported.

The function prints a warning to standard input if a type was already registered but has a different fields. Some hyperscalers (e.g. Azure) can have different attributes for the same types in different zones (e.g. ephemeral storage size). Unless there is a bigger difference, this isn't a problem. This helps to track these during generation.

func (*RegisteredInstanceTypes) Save

func (rit *RegisteredInstanceTypes) Save(filename string) error

Save instance list to YAML

type ServiceAzure

type ServiceAzure interface {
	RegisterInstanceTypes(ctx context.Context, instanceTypes *RegisteredInstanceTypes, regionalTypes *RegionalTypeAvailability) error
}

type ServiceGCP

type ServiceGCP interface {
	// RegisterInstanceTypes
	RegisterInstanceTypes(ctx context.Context, instanceTypes *RegisteredInstanceTypes, regionalTypes *RegionalTypeAvailability) error

	// ListMachineTypes returns list of all GCP machine types
	ListMachineTypes(ctx context.Context, zone string) ([]*InstanceType, error)

	// ListAllRegionsAndZones returns list of all GCP regions
	ListAllRegionsAndZones(ctx context.Context) ([]Region, []Zone, error)
}

type Source

type Source struct {
	// ID of the resource
	ID string

	// The name of the source
	Name string

	// Source Type ID (number assigned to AWS source or Azure source)
	SourceTypeID string

	// UUID of the inventory source installation
	Uid string

	// Provider name as string
	Provider models.ProviderType

	// Status of the source
	Status string
}

Source defines model for Source. Maps 1:1 to Source Database.

type Sources

type Sources interface {
	// ListProvisioningSourcesByProvider returns sources filtered by provider that have provisioning credentials assigned
	ListProvisioningSourcesByProvider(ctx context.Context, provider models.ProviderType) ([]*Source, int, error)

	// ListAllProvisioningSources returns all sources that have provisioning credentials assigned
	ListAllProvisioningSources(ctx context.Context) ([]*Source, int, error)

	// GetAuthentication returns authentication associated with provisioning app for given sourceId
	GetAuthentication(ctx context.Context, sourceId string) (*Authentication, error)

	// Ready returns readiness information
	Ready(ctx context.Context) error
}

Sources interface provides access to the Sources backend service API

type Zone

type Zone string

Zone represents a provider's zone. There are multiple types of zones (regional, wireless, cities) based on the provider. This type does not make any difference, as long as they have unique names. The name must include region in the name, so it is unique for each provider.

func (Zone) String

func (z Zone) String() string

Directories

Path Synopsis
ec2
gcp
image_builder
Package image_builder provides primitives to interact with the openapi HTTP API.
Package image_builder provides primitives to interact with the openapi HTTP API.
rbac
Package rbac provides primitives to interact with the openapi HTTP API.
Package rbac provides primitives to interact with the openapi HTTP API.
sources
Package sources provides primitives to interact with the openapi HTTP API.
Package sources provides primitives to interact with the openapi HTTP API.

Jump to

Keyboard shortcuts

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