gcp

package
v0.0.19 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2024 License: Apache-2.0 Imports: 41 Imported by: 0

Documentation

Overview

pkg/providers/gcp/provider.go

Index

Constants

This section is empty.

Variables

View Source
var GCPRequiredAPIs = []string{
	"compute.googleapis.com",
	"networkmanagement.googleapis.com",
	"storage-api.googleapis.com",
	"file.googleapis.com",
	"storage.googleapis.com",
	"cloudasset.googleapis.com",
}

Constants related to GCP APIs and configurations

View Source
var NewGCPClientFunc = NewGCPClient
View Source
var NewGCPProviderFunc = NewGCPProviderFactory

Functions

func ConvertGCPResourceState

func ConvertGCPResourceState(state string) models.GCPResourceState

func GenerateTags

func GenerateTags(projectID, uniqueID string) map[string]string

GenerateTags creates a map of tags for GCP resources

func GetGCPClient

func GetGCPClient(
	ctx context.Context,
	organizationID string,
) (gcp_interface.GCPClienter, func(), error)

func GetRequiredAPIs

func GetRequiredAPIs() []string

func NewGCPClient

func NewGCPClient(
	ctx context.Context,
	organizationID string,
) (gcp_interface.GCPClienter, func(), error)

Types

type CloseableClient

type CloseableClient interface {
	Close() error
}

type GCPProvider

type GCPProvider struct {
	ProjectID        string
	OrganizationID   string
	BillingAccountID string
	Client           gcp_interface.GCPClienter
	ClusterDeployer  common_interface.ClusterDeployerer
	CleanupClient    func()
	Config           *viper.Viper
	SSHClient        sshutils.SSHClienter
	SSHUser          string
	SSHPort          int
	// contains filtered or unexported fields
}

GCPProvider implements the Providerer interface for GCP

func NewGCPProvider

func NewGCPProvider(
	ctx context.Context,
	organizationID, billingAccountID string,
) (*GCPProvider, error)

NewGCPProvider creates a new GCP provider

func NewGCPProviderFactory

func NewGCPProviderFactory(
	ctx context.Context,
	organizationID, billingAccountID string,
) (*GCPProvider, error)

NewGCPProviderFactory is the factory function for GCPProvider.

func (*GCPProvider) CheckAuthentication

func (p *GCPProvider) CheckAuthentication(ctx context.Context) error

CheckAuthentication verifies GCP authentication

func (*GCPProvider) CheckPermissions

func (p *GCPProvider) CheckPermissions(ctx context.Context) error

CheckPermissions checks the current user's permissions

func (*GCPProvider) CreateFirewallRules

func (p *GCPProvider) CreateFirewallRules(
	ctx context.Context,
	networkName string,
) error

CreateFirewallRules creates firewall rules for a specified network

func (*GCPProvider) CreateResources

func (p *GCPProvider) CreateResources(ctx context.Context) error

CreateResources implements the ClusterDeployer interface for GCP

func (*GCPProvider) CreateVM

func (p *GCPProvider) CreateVM(
	ctx context.Context,
	vmName string,
) (string, string, error)

Creates the VM and returns the public and private IP addresses

func (*GCPProvider) CreateVPCNetwork

func (p *GCPProvider) CreateVPCNetwork(
	ctx context.Context,
	networkName string,
) error

CreateVPCNetwork creates a VPC network in the specified project

func (*GCPProvider) DestroyProject

func (p *GCPProvider) DestroyProject(
	ctx context.Context,
	projectID string,
) error

DestroyProject destroys a specified GCP project

func (*GCPProvider) DestroyResources

func (p *GCPProvider) DestroyResources(
	ctx context.Context,
	projectID string,
) error

func (*GCPProvider) EnableAPI

func (p *GCPProvider) EnableAPI(ctx context.Context, apiName string) error

EnableAPI enables a specific GCP API for the project

func (*GCPProvider) EnableRequiredAPIs

func (p *GCPProvider) EnableRequiredAPIs(ctx context.Context) error

EnableRequiredAPIs enables all required GCP APIs for the project

func (*GCPProvider) EnsureFirewallRules

func (p *GCPProvider) EnsureFirewallRules(
	ctx context.Context,
	networkName string,
) error

EnsureFirewallRules ensures that firewall rules are set for a network

func (*GCPProvider) EnsureProject

func (p *GCPProvider) EnsureProject(
	ctx context.Context,
) error

EnsureProject ensures that a GCP project exists, creating it if necessary

func (*GCPProvider) EnsureVPCNetwork

func (p *GCPProvider) EnsureVPCNetwork(
	ctx context.Context,
	vpcNetworkName string,
) error

func (*GCPProvider) FinalizeDeployment

func (p *GCPProvider) FinalizeDeployment(ctx context.Context) error

FinalizeDeployment finalizes the deployment process

func (*GCPProvider) GetClusterDeployer

func (p *GCPProvider) GetClusterDeployer() common_interface.ClusterDeployerer

GetClusterDeployer returns the current ClusterDeployer

func (*GCPProvider) GetGCPClient

func (p *GCPProvider) GetGCPClient() gcp_interface.GCPClienter

GetGCPClient returns the current GCP client

func (*GCPProvider) GetVMExternalIP

func (p *GCPProvider) GetVMExternalIP(
	ctx context.Context,
	vmName string,
	locationData map[string]string,
) (string, error)

GetVMExternalIP retrieves the external IP of a VM instance

func (*GCPProvider) Initialize

func (p *GCPProvider) Initialize(ctx context.Context) error

Initialize initializes the GCP provider

func (*GCPProvider) ListAllAssetsInProject

func (p *GCPProvider) ListAllAssetsInProject(
	ctx context.Context,
	projectID string,
) ([]*assetpb.Asset, error)

ListAllAssetsInProject lists all assets within a GCP project

func (*GCPProvider) ListBillingAccounts

func (p *GCPProvider) ListBillingAccounts(ctx context.Context) ([]string, error)

ListBillingAccounts lists all billing accounts associated with the GCP organization

func (*GCPProvider) ListProjects

func (p *GCPProvider) ListProjects(
	ctx context.Context,
) ([]*resourcemanagerpb.Project, error)

ListProjects lists all GCP projects

func (*GCPProvider) PollResources

func (p *GCPProvider) PollResources(ctx context.Context) ([]interface{}, error)

PollResources polls resources for updates

func (*GCPProvider) PrepareDeployment

func (p *GCPProvider) PrepareDeployment(ctx context.Context) (*models.Deployment, error)

PrepareDeployment prepares the deployment configuration

func (*GCPProvider) ProcessMachinesConfig

func (p *GCPProvider) ProcessMachinesConfig(
	ctx context.Context,
) (map[string]models.Machiner, map[string]bool, error)

func (*GCPProvider) SetBillingAccount

func (p *GCPProvider) SetBillingAccount(
	ctx context.Context,
	billingAccountID string,
) error

SetBillingAccount sets the billing account for the GCP project

func (*GCPProvider) SetClusterDeployer

func (p *GCPProvider) SetClusterDeployer(deployer common_interface.ClusterDeployerer)

SetClusterDeployer sets a new ClusterDeployer

func (*GCPProvider) SetGCPClient

func (p *GCPProvider) SetGCPClient(client gcp_interface.GCPClienter)

SetGCPClient sets a new GCP client

func (*GCPProvider) StartResourcePolling

func (p *GCPProvider) StartResourcePolling(ctx context.Context) <-chan error

StartResourcePolling starts polling resources for updates

func (*GCPProvider) ValidateMachineType

func (p *GCPProvider) ValidateMachineType(
	ctx context.Context,
	location, machineType string,
) (bool, error)

type GCPVMConfig

type GCPVMConfig struct {
	ProjectID         string
	Region            string
	Zone              string
	VMName            string
	MachineType       string
	SSHUser           string
	PublicKeyMaterial string
}

GCPVMConfig holds the configuration for a GCP VM

type LiveGCPClient

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

func (*LiveGCPClient) CheckAuthentication

func (c *LiveGCPClient) CheckAuthentication(ctx context.Context) error

func (*LiveGCPClient) CheckFirewallRuleExists

func (c *LiveGCPClient) CheckFirewallRuleExists(
	ctx context.Context,
	projectID, ruleName string,
) error

func (*LiveGCPClient) CheckPermissions

func (c *LiveGCPClient) CheckPermissions(ctx context.Context) error

func (*LiveGCPClient) CheckProjectAccess

func (c *LiveGCPClient) CheckProjectAccess(ctx context.Context, projectID string) error

func (*LiveGCPClient) CheckSpecificPermission

func (c *LiveGCPClient) CheckSpecificPermission(ctx context.Context, permission string) error

func (*LiveGCPClient) CreateFirewallRules

func (c *LiveGCPClient) CreateFirewallRules(ctx context.Context, networkName string) error

func (*LiveGCPClient) CreateIP

func (c *LiveGCPClient) CreateIP(
	ctx context.Context,
	projectID, region string,
	addressName string,
) (string, error)

func (*LiveGCPClient) CreateServiceAccount

func (c *LiveGCPClient) CreateServiceAccount(
	ctx context.Context,
	projectID string,
) (*iam.ServiceAccount, error)

func (*LiveGCPClient) CreateVM

func (c *LiveGCPClient) CreateVM(
	ctx context.Context,
	projectID string,
	machine models.Machiner,
) (*computepb.Instance, error)

func (*LiveGCPClient) CreateVPCNetwork

func (c *LiveGCPClient) CreateVPCNetwork(ctx context.Context, networkName string) error

func (*LiveGCPClient) DestroyProject

func (c *LiveGCPClient) DestroyProject(ctx context.Context, projectID string) error

func (*LiveGCPClient) EnableAPI

func (c *LiveGCPClient) EnableAPI(ctx context.Context, projectID, apiName string) error

func (*LiveGCPClient) EnsureFirewallRules

func (c *LiveGCPClient) EnsureFirewallRules(ctx context.Context, networkName string) error

func (*LiveGCPClient) EnsureProject

func (c *LiveGCPClient) EnsureProject(
	ctx context.Context,
	organizationID string,
	projectID string,
	billingAccountID string,
) (string, error)

func (*LiveGCPClient) EnsureServiceAccount

func (c *LiveGCPClient) EnsureServiceAccount(
	ctx context.Context,
	projectID, serviceAccountName string,
) error

func (*LiveGCPClient) EnsureVPCNetwork

func (c *LiveGCPClient) EnsureVPCNetwork(ctx context.Context, projectID string) error

func (*LiveGCPClient) GetParentString

func (c *LiveGCPClient) GetParentString() string

func (*LiveGCPClient) GetVMExternalIP

func (c *LiveGCPClient) GetVMExternalIP(
	ctx context.Context,
	vmName string,
	locationData map[string]string,
) (string, error)

func (*LiveGCPClient) GetVMZone

func (c *LiveGCPClient) GetVMZone(ctx context.Context, projectID, vmName string) (string, error)

func (*LiveGCPClient) IsAPIEnabled

func (c *LiveGCPClient) IsAPIEnabled(ctx context.Context, projectID, apiName string) (bool, error)

func (*LiveGCPClient) ListAllAssetsInProject

func (c *LiveGCPClient) ListAllAssetsInProject(
	ctx context.Context,
	projectID string,
) ([]*assetpb.Asset, error)

func (*LiveGCPClient) ListBillingAccounts

func (c *LiveGCPClient) ListBillingAccounts(ctx context.Context) ([]string, error)

func (*LiveGCPClient) ListProjects

func (*LiveGCPClient) ProjectExists

func (c *LiveGCPClient) ProjectExists(ctx context.Context, projectID string) (bool, error)

func (*LiveGCPClient) SetBillingAccount

func (c *LiveGCPClient) SetBillingAccount(
	ctx context.Context,
	projectID string,
	billingAccountID string,
) error

func (*LiveGCPClient) SetParentString

func (c *LiveGCPClient) SetParentString(organizationID string)

func (*LiveGCPClient) StartResourcePolling

func (c *LiveGCPClient) StartResourcePolling(ctx context.Context) error

func (*LiveGCPClient) TestCloudStorageAPI

func (c *LiveGCPClient) TestCloudStorageAPI(ctx context.Context, projectID string) error

func (*LiveGCPClient) TestComputeEngineAPI

func (c *LiveGCPClient) TestComputeEngineAPI(
	ctx context.Context,
	projectID string,
	elapsedTime, maxElapsedTime time.Duration,
) error

func (*LiveGCPClient) TestIAMPermissions

func (c *LiveGCPClient) TestIAMPermissions(ctx context.Context, projectID string) error

func (*LiveGCPClient) TestServiceUsageAPI

func (c *LiveGCPClient) TestServiceUsageAPI(ctx context.Context, projectID string) error

func (*LiveGCPClient) UpdateResourceState

func (c *LiveGCPClient) UpdateResourceState(
	resourceName, resourceType string,
	state models.MachineResourceState,
) error

func (*LiveGCPClient) ValidateMachineType

func (c *LiveGCPClient) ValidateMachineType(
	ctx context.Context,
	machineType, location string,
) (bool, error)

Jump to

Keyboard shortcuts

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