gcloud

package module
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2023 License: Apache-2.0 Imports: 33 Imported by: 1

README

Deploystack GCloud Package

Documentation

Overview

Package gcloud wraps up all of the cloud operations for DeployStack into one client. It's mostly used to drive querying GCP projects and settings for DeployStack ui. But it is also used to drive some of the authoring tooling

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrorDomainUntenable is returned when a domain isn't available for registration, but
	// is also not owned by the user. It can't be used in this app
	ErrorDomainUntenable = fmt.Errorf("domain is not available, and not owned by attempting user")
	// ErrorDomainUserDeny is returned when an user declines the choice to purchase.
	ErrorDomainUserDeny = fmt.Errorf("user said no to buying the domain")
)
View Source
var (
	// DefaultRegion is the default compute region used in compute calls.
	DefaultRegion = "us-central1"
	// DefaultMachineType is the default compute machine type used in compute calls.
	DefaultMachineType = "n1-standard"
	// DefaultMachineFamily is the default compute machine type used in compute calls.
	DefaultMachineFamily = "n1"
	// DefaultImageProject is the default project for images used in compute calls.
	DefaultImageProject = "debian-cloud"
	// DefaultImageFamily is the default project for images used in compute calls.
	DefaultImageFamily = "debian-11"
	// DefaultDiskSize is the default size for making disks for Compute Engine
	DefaultDiskSize = "200"
	// DefaultDiskType is the default style of disk
	DefaultDiskType = "pd-standard"
	// DefaultInstanceType is the default machine type of compute engine
	DefaultInstanceType = "n1-standard-1"
	// HTTPServerTags are the instance tags to open up the instance to be a
	// http server
	HTTPServerTags = "[http-server,https-server]"
	// DefaultZone is the default zone used in compute calls.
	DefaultZone = "us-central1-a"

	// ErrorBillingInvalidAccount is the error you get if you pass in a bad
	// Billing Account ID
	ErrorBillingInvalidAccount = fmt.Errorf("not a valid billing account")
	// ErrorBillingNoPermission is the error you get if the user lacks billing
	// related permissions
	ErrorBillingNoPermission = fmt.Errorf("user lacks permission")
	// ErrorProjectCreateTooLong is an error when you try to create a project
	// wuth more than 30 characters
	ErrorProjectCreateTooLong = fmt.Errorf("project_id contains too many characters, limit 30")
	// ErrorProjectCreateTooShort is an error when you try to create a project
	// wuth less than 6 characters
	ErrorProjectCreateTooShort = fmt.Errorf("project_id contains too few characters, minimum 6")
	// ErrorProjectInvalidCharacters is an error when you try and pass bad
	// characters into a CreateProjectCall
	ErrorProjectInvalidCharacters = fmt.Errorf("project_id contains invalid characters")
	// ErrorProjectAlreadyExists is an error when you try and create a project
	// That already exists
	ErrorProjectAlreadyExists = fmt.Errorf("project_id already exists")
	// ErrorProjectDidNotFinish is an error we cannot confirm that project completion actually occured
	ErrorProjectDidNotFinish = fmt.Errorf("project creation did not complete in a timely manner")
)
View Source
var DiskProjects = LabeledValues{
	LabeledValue{Label: "CentOS", Value: "centos-cloud"},
	LabeledValue{Label: "Container-Optimized OS (COS)", Value: "cos-cloud"},
	LabeledValue{Label: "Debian", Value: "debian-cloud", IsDefault: true},
	LabeledValue{Label: "Fedora CoreOS", Value: "fedora-coreos-cloud"},
	LabeledValue{Label: "Red Hat Enterprise Linux (RHEL)", Value: "rhel-cloud"},
	LabeledValue{Label: "Red Hat Enterprise Linux (RHEL) for SAP", Value: "rhel-sap-cloud"},
	LabeledValue{Label: "Rocky Linux", Value: "rocky-linux-cloud"},
	LabeledValue{Label: "SQL Server", Value: "windows-sql-cloud"},
	LabeledValue{Label: "SUSE Linux Enterprise Server (SLES)", Value: "suse-cloud"},
	LabeledValue{Label: "SUSE Linux Enterprise Server (SLES) for SAP", Value: "suse-cloud"},
	LabeledValue{Label: "SUSE Linux Enterprise Server (SLES) BYOS", Value: "suse-byos-cloud"},
	LabeledValue{Label: "Ubuntu LTS", Value: "ubuntu-os-cloud"},
	LabeledValue{Label: "Ubuntu Pro", Value: "ubuntu-os-pro-cloud"},
	LabeledValue{Label: "Windows Server", Value: "windows-cloud"},
}

DiskProjects are the list of projects for disk images for Compute Engine

View Source
var ErrorServiceNotExistOrNotAllowed = fmt.Errorf("Not found or permission denied for service")

ErrorServiceNotExistOrNotAllowed occurs when the user running this code doesn't have permission to enable the service in the project or it's a nonexistent service name.

Functions

This section is empty.

Types

type Client

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

Client is the tool that will handle all of the communication between gcloud and the various product areas

func NewClient

func NewClient(ctx context.Context, ua string) Client

NewClient initiates a new gcloud Client

func (*Client) BillingAccountAttach

func (c *Client) BillingAccountAttach(project, account string) error

BillingAccountAttach will enable billing in a given project

func (*Client) BillingAccountList

func (c *Client) BillingAccountList() ([]*cloudbilling.BillingAccount, error)

BillingAccountList gets a list of the billing accounts a user has access to

func (*Client) CloudBuildTriggerCreate

func (c *Client) CloudBuildTriggerCreate(project string, trigger cloudbuild.BuildTrigger) (*cloudbuild.BuildTrigger, error)

CloudBuildTriggerCreate creates a build trigger in a given project

func (*Client) CloudBuildTriggerDelete

func (c *Client) CloudBuildTriggerDelete(project string, triggerid string) error

CloudBuildTriggerDelete deletes a build trigger in a given project

func (*Client) ComputeRegionList

func (c *Client) ComputeRegionList(project string) ([]string, error)

ComputeRegionList will return a list of regions for Compute Engine

func (Client) DomainIsAvailable

func (c Client) DomainIsAvailable(project, domain string) (*domainspb.RegisterParameters, error)

DomainIsAvailable checks to see if a given domain is available for registration

func (Client) DomainIsVerified

func (c Client) DomainIsVerified(project, domain string) (bool, error)

DomainIsVerified checks to see if a given domain belongs to this user

func (Client) DomainRegister

func (c Client) DomainRegister(project string, domaininfo *domainspb.RegisterParameters, contact ContactData) error

DomainRegister handles registring a domain on behalf of the user.

func (Client) DomainsSearch

func (c Client) DomainsSearch(project, domain string) ([]*domainspb.RegisterParameters, error)

DomainsSearch checks the Cloud Domain api for the input domain

func (*Client) FunctionDelete

func (c *Client) FunctionDelete(project, region, name string) error

FunctionDelete deletes a Cloud Function.

func (*Client) FunctionDeploy

func (c *Client) FunctionDeploy(project, region string, f cloudfunctions.CloudFunction) error

FunctionDeploy deploys a Cloud Function.

func (*Client) FunctionGenerateSignedURL

func (c *Client) FunctionGenerateSignedURL(project, region string) (string, error)

FunctionGenerateSignedURL generates a signed url for use with uploading to Cloud Storage

func (*Client) FunctionGet

func (c *Client) FunctionGet(project, region, name string) (*cloudfunctions.CloudFunction, error)

FunctionGet gets the details of a Cloud Function.

func (*Client) FunctionRegionList

func (c *Client) FunctionRegionList(project string) ([]string, error)

FunctionRegionList will return a list of regions for Cloud Functions

func (*Client) ImageFamilyList

func (c *Client) ImageFamilyList(imgs *compute.ImageList) LabeledValues

ImageFamilyList gets a list of image families

func (*Client) ImageLatestGet

func (c *Client) ImageLatestGet(project, imageproject, imagefamily string) (string, error)

ImageLatestGet retrieves the latest image from a particular family

func (*Client) ImageList

func (c *Client) ImageList(project, imageproject string) (*compute.ImageList, error)

ImageList gets the list of disk images available for a given image project

func (*Client) ImageTypeListByFamily

func (c *Client) ImageTypeListByFamily(imgs *compute.ImageList, project, family string) LabeledValues

ImageTypeListByFamily retrieves a list of iamge types by the family

func (*Client) JobDelete

func (c *Client) JobDelete(project, region, job string) error

JobDelete deletes a Cloud Scheduler Job

func (*Client) JobSchedule

func (c *Client) JobSchedule(project, region string, job schedulerpb.Job) error

JobSchedule creates a Cloud Scheduler Job

func (*Client) MachineTypeFamilyList

func (c *Client) MachineTypeFamilyList(imgs *compute.MachineTypeList) LabeledValues

MachineTypeFamilyList gets the list of machine type families

func (*Client) MachineTypeList

func (c *Client) MachineTypeList(project, zone string) (*compute.MachineTypeList, error)

MachineTypeList retrieves the list of Machine Types available in a given zone

func (*Client) MachineTypeListByFamily

func (c *Client) MachineTypeListByFamily(imgs *compute.MachineTypeList, family string) LabeledValues

MachineTypeListByFamily retrieves the list of machine types available for each family

func (*Client) ProjectCreate

func (c *Client) ProjectCreate(project, parent, parentType string) error

ProjectCreate does the work of actually creating a new project in your GCP account

func (*Client) ProjectDelete

func (c *Client) ProjectDelete(project string) error

ProjectDelete does the work of actually deleting an existing project in your GCP account

func (*Client) ProjectExists

func (c *Client) ProjectExists(project string) bool

ProjectExists confirms that a project actually exists

func (*Client) ProjectGet

func (c *Client) ProjectGet(project string) (*cloudresourcemanager.Project, error)

ProjectGet returns the details of a single project

func (*Client) ProjectGrantIAMRole

func (c *Client) ProjectGrantIAMRole(project, role, principal string) error

ProjectGrantIAMRole grants a given principal a given role in a given project

func (Client) ProjectIDGet

func (c Client) ProjectIDGet() (string, error)

ProjectIDGet gets the currently set default project

func (*Client) ProjectIDSet

func (c *Client) ProjectIDSet(project string) error

ProjectIDSet sets the currently set default project

func (*Client) ProjectList

func (c *Client) ProjectList() ([]ProjectWithBilling, error)

ProjectList gets a list of the ProjectList a user has access to

func (*Client) ProjectListWithBilling

func (c *Client) ProjectListWithBilling(p []*cloudresourcemanager.Project) ([]ProjectWithBilling, error)

ProjectListWithBilling gets a list of projects with their billing information

func (*Client) ProjectListWithBillingEnabled

func (c *Client) ProjectListWithBillingEnabled() (map[string]bool, error)

ProjectListWithBillingEnabled queries the billing accounts a user has access to to generate a list of projects for each billing account. Will hopefully reduce the number of calls made to billing api

func (*Client) ProjectNumberGet

func (c *Client) ProjectNumberGet(id string) (string, error)

ProjectNumberGet will get the project_number for the input projectid

func (*Client) ProjectParentGet

func (c *Client) ProjectParentGet(id string) (*cloudresourcemanager.ResourceId, error)

ProjectParentGet returns the parent of an input project

func (*Client) RegionList

func (c *Client) RegionList(project, product string) ([]string, error)

RegionList will return a list of RegionsList depending on product type

func (*Client) RunRegionList

func (c *Client) RunRegionList(project string) ([]string, error)

RunRegionList will return a list of regions for Cloud Run

func (*Client) SecretCreate

func (c *Client) SecretCreate(project, name, payload string) error

SecretCreate creates a secret and populates the lastest version with a payload.

func (*Client) SecretDelete

func (c *Client) SecretDelete(project, name string) error

SecretDelete deletes a secret

func (*Client) ServiceAccountCreate

func (c *Client) ServiceAccountCreate(project, username, displayName string) (string, error)

ServiceAccountCreate creates a service account. A little on the nose

func (*Client) ServiceAccountDelete

func (c *Client) ServiceAccountDelete(project, email string) error

ServiceAccountDelete deletes a service account. A little on the nose

func (*Client) ServiceDisable

func (c *Client) ServiceDisable(project, service string) error

ServiceDisable disables a service in the selected project

func (*Client) ServiceEnable

func (c *Client) ServiceEnable(project, service string) error

ServiceEnable enable a service in the selected project so that query calls to various lists will work.

func (*Client) ServiceIsEnabled

func (c *Client) ServiceIsEnabled(project, service string) (bool, error)

ServiceIsEnabled checks to see if the existing service is already enabled in the project we are trying to enable it in.

func (*Client) StorageBucketCreate

func (c *Client) StorageBucketCreate(project, bucket string) error

StorageBucketCreate creates a storage bucket in Cloud Storage

func (*Client) StorageBucketDelete

func (c *Client) StorageBucketDelete(project, bucket string) error

StorageBucketDelete deletes a storage bucket in Cloud Storage

func (*Client) StorageObjectCreate

func (c *Client) StorageObjectCreate(project, bucket, path string) (string, error)

StorageObjectCreate creates an object in a particular bucket in Cloud Storage

func (*Client) StorageObjectDelete

func (c *Client) StorageObjectDelete(project, bucket, gspath string) error

StorageObjectDelete deletes an object in a particular bucket in Cloud Storage

func (*Client) ZoneList

func (c *Client) ZoneList(project, region string) ([]string, error)

ZoneList will return a list of ComputeZoneList in a given region

type ContactData

type ContactData struct {
	AllContacts DomainRegistrarContact `yaml:"allContacts"`
}

ContactData represents the structure that we need for Registrar Contact Data

func NewContactData

func NewContactData() ContactData

NewContactData returns a properly initialized ContactData

func (ContactData) DomainContact

func (c ContactData) DomainContact() (domainspb.ContactSettings, error)

DomainContact outputs a varible in the format that Domain Registration API needs.

func (*ContactData) ReadFrom added in v1.10.0

func (c *ContactData) ReadFrom(r io.Reader) (int64, error)

ReadFrom populates the content of ContactData from a reader

func (ContactData) WriteTo added in v1.10.0

func (c ContactData) WriteTo(w io.Writer) (int64, error)

WriteTo writes the content of ContactData to a writer

func (ContactData) YAML

func (c ContactData) YAML() (string, error)

YAML outputs the content of this structure into the contact format needed for domain registration

type DomainRegistrarContact

type DomainRegistrarContact struct {
	Email         string        `yaml:"email"`
	Phone         string        `yaml:"phoneNumber"`
	PostalAddress PostalAddress `yaml:"postalAddress"`
}

DomainRegistrarContact represents the data required to register a domain with a public registrar.

type LabeledValue

type LabeledValue struct {
	Value     string
	Label     string
	IsDefault bool
}

LabeledValue is a struct that contains a label/value pair

func NewLabeledValue

func NewLabeledValue(s string) LabeledValue

NewLabeledValue takes a string and converts it to a LabeledValue. If a | delimiter is present it will split into a different label/value

type LabeledValues

type LabeledValues []LabeledValue

LabeledValues is collection of LabledValue structs

func NewLabeledValues

func NewLabeledValues(sl []string, defaultValue string) LabeledValues

NewLabeledValues takes a slice of strings and returns a list of LabeledValues

func (*LabeledValues) GetDefault

func (l *LabeledValues) GetDefault() LabeledValue

GetDefault returns the deafult value of the LabeledValues list

func (*LabeledValues) LongestLen

func (l *LabeledValues) LongestLen() int

LongestLen returns the length of longest LABEL in the list

func (*LabeledValues) SetDefault

func (l *LabeledValues) SetDefault(value string)

SetDefault sets the default value of the list

func (*LabeledValues) Sort

func (l *LabeledValues) Sort()

Sort orders the LabeledValues by Label

type PostalAddress

type PostalAddress struct {
	RegionCode         string   `yaml:"regionCode"`
	PostalCode         string   `yaml:"postalCode"`
	AdministrativeArea string   `yaml:"administrativeArea"`
	Locality           string   `yaml:"locality"`
	AddressLines       []string `yaml:"addressLines"`
	Recipients         []string `yaml:"recipients"`
}

PostalAddress represents the mail address in a DomainRegistrarContact

type ProjectWithBilling

type ProjectWithBilling struct {
	Name           string
	ID             string
	BillingEnabled bool
}

ProjectWithBilling is a project with it's billing status

Jump to

Keyboard shortcuts

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