gcp

package
v0.100.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//nolint:gosec
	GCPCredentialsEnvName string = "GOOGLE_APPLICATION_CREDENTIALS"
)

GCPCredentialsEnvName contains name of the environment variable used to specify the path to file with CGP service account credentials

View Source
const (
	// MetadataKeyImageName contains a key name used to store metadata on
	// a Storage object with the intended name of the image.
	// The metadata can be then used to associate the object with actual
	// image build using the image name.
	MetadataKeyImageName string = "osbuild-composer-image-name"
)

Variables

Guest OS Features for RHEL8 images

Guest OS Features for RHEL9 images.

Functions

func GuestOsFeaturesByDistro

func GuestOsFeaturesByDistro(distroName string) []*computepb.GuestOsFeature

GuestOsFeaturesByDistro returns the the list of Guest OS Features, which should be used when importing an image of the specified distribution.

In case the provided distribution does not have any specific Guest OS Features list defined, nil is returned.

Types

type GCP

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

GCP structure holds necessary information to authenticate and interact with GCP.

func New

func New(credentials []byte) (*GCP, error)

New returns an authenticated GCP instance, allowing to interact with GCP API.

func NewFromFile

func NewFromFile(path string) (*GCP, error)

NewFromFile loads the credentials from a file and returns an authenticated *GCP object instance.

func (*GCP) ComputeExecuteFunctionForImages

func (g *GCP) ComputeExecuteFunctionForImages(ctx context.Context, f func(*compute.ImageIterator) error) error

ComputeExecuteFunctionForImages will pass all the compute images in the account to a function, which is able to iterate over the images. Useful if something needs to be execute for each image. Uses:

  • Compute Engine API

func (*GCP) ComputeImageDelete

func (g *GCP) ComputeImageDelete(ctx context.Context, name string) error

ComputeImageDelete deletes a Compute Engine image with the given name. If the image existed and was successfully deleted, no error is returned.

Uses:

  • Compute Engine API

func (*GCP) ComputeImageInsert

func (g *GCP) ComputeImageInsert(
	ctx context.Context,
	bucket, object, imageName string,
	regions []string,
	guestOsFeatures []*computepb.GuestOsFeature) (*computepb.Image, error)

ComputeImageInsert imports a previously uploaded archive with raw image into Compute Engine.

The image must be RAW image named 'disk.raw' inside a gzip-ed tarball.

To delete the Storage object (image) used for the image import, use StorageObjectDelete().

bucket - Google storage bucket name with the uploaded image archive object - Google storage object name of the uploaded image imageName - Desired image name after the import. This must be unique within the whole project. regions - A list of valid Google Storage regions where the resulting image should be located.

It is possible to specify multiple regions. Also multi and dual regions are allowed.
If not provided, the region of the used Storage object is used.
See: https://cloud.google.com/storage/docs/locations

guestOsFeatures - A list of features supported by the Guest OS on the imported image.

Uses:

  • Compute Engine API

func (*GCP) ComputeImageShare

func (g *GCP) ComputeImageShare(ctx context.Context, imageName string, shareWith []string) error

ComputeImageShare shares the specified Compute Engine image with list of accounts.

"shareWith" is a list of accounts to share the image with. Items can be one of the following options:

  • `user:{emailid}`: An email address that represents a specific Google account. For example, `alice@example.com`.

  • `serviceAccount:{emailid}`: An email address that represents a service account. For example, `my-other-app@appspot.gserviceaccount.com`.

  • `group:{emailid}`: An email address that represents a Google group. For example, `admins@example.com`.

  • `domain:{domain}`: The G Suite domain (primary) that represents all the users of that domain. For example, `google.com` or `example.com`.

Uses:

  • Compute Engine API

func (*GCP) ComputeImageURL

func (g *GCP) ComputeImageURL(imageName string) string

ComputeImageURL returns an image's URL to Google Cloud Console. The method does not check at all, if the image actually exists or not.

func (*GCP) GetProjectID

func (g *GCP) GetProjectID() string

GetProjectID returns a string with the Project ID of the project, used for all GCP operations.

func (*GCP) StorageObjectDelete

func (g *GCP) StorageObjectDelete(ctx context.Context, bucket, object string) error

StorageObjectDelete deletes the given object from a bucket.

Uses:

  • Storage API

func (*GCP) StorageObjectUpload

func (g *GCP) StorageObjectUpload(ctx context.Context, filename, bucket, object string, metadata map[string]string) (*storage.ObjectAttrs, error)

StorageObjectUpload uploads an OS image to specified Cloud Storage bucket and object. The bucket must exist. MD5 sum of the image file and uploaded object is compared after the upload to verify the integrity of the uploaded image.

The ObjectAttrs is returned if the object has been created.

Uses:

  • Storage API

Jump to

Keyboard shortcuts

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