cloudyazure

package module
v0.0.15 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 License: MIT Imports: 39 Imported by: 0

README

cloudy-azure

Azure implementation of cloudy providers, excluding MS Graph because that is a separate repe

Documentation

Index

Constants

View Source
const AzureArmCompute = "azure-arm-compute"
View Source
const AzureCredentialsKey = "azure"
View Source
const DefaultRegion = "usgovvirginia"
View Source
const KeyVaultCachedId = "azure-keyvault-cached"
View Source
const KeyVaultId = "azure-keyvault"

Variables

View Source
var AzureBlob = "azure-blob"
View Source
var AzureFiles = "azure-files"

Functions

func AzureGetRequiredEnv added in v0.0.3

func AzureGetRequiredEnv() []string

func ExtractResourceGroupFromID

func ExtractResourceGroupFromID(ctx context.Context, id string) string

func FromStrPointerMap

func FromStrPointerMap(pointerMap map[string]*string) map[string]string

func GetAzureClientSecretCredential

func GetAzureClientSecretCredential(azCfg AzureCredentials) (*azidentity.ClientSecretCredential, error)

func GetStorageAccountType

func GetStorageAccountType(ctx context.Context, env *cloudy.Environment, name string) (string, error)

func IsAvailable

func IsAvailable(restrictions []*armcompute.ResourceSKURestrictions) bool

func IsInLocation

func IsInLocation(region string, locations []*string) bool

func LoadEnvironment

func LoadEnvironment(ctx context.Context) (*cloudy.Environment, error)

func SizeFromResource

func SizeFromResource(ctx context.Context, res *armcompute.ResourceSKU) *cloudyvm.VmSize

func ToStrPointerMap

func ToStrPointerMap(stringMap map[string]string) map[string]*string

func VMAddTag

func VMAddTag(ctx context.Context)

func VMGetPowerState

func VMGetPowerState(vm *armcompute.VirtualMachine) string

func VmStart

func VmStart(ctx context.Context, vmClient *armcompute.VirtualMachinesClient, vmName string, resourceGroup string, wait bool) error

func VmState

func VmState(ctx context.Context, vmClient *armcompute.VirtualMachinesClient, vmAction cloudyvm.VirtualMachineAction, vmName string, resourceGroup string, wait bool) (*cloudyvm.VirtualMachineStatus, error)

func VmStatus

func VmStatus(ctx context.Context, vmClient *armcompute.VirtualMachinesClient, vmName string, resourceGroup string) (*cloudyvm.VirtualMachineStatus, error)

func VmStop

func VmStop(ctx context.Context, vmClient *armcompute.VirtualMachinesClient, vmName string, resourceGroup string, wait bool) error

func VmTerminate

func VmTerminate(ctx context.Context, vmClient *armcompute.VirtualMachinesClient, vmName string, resourceGroup string, wait bool) error

Types

type AVDManagerFactory

type AVDManagerFactory struct {
	AzureVirtualDesktop
}

func (*AVDManagerFactory) Create

func (ms *AVDManagerFactory) Create(cfg interface{}) (cloudy.AVDManager, error)

func (*AVDManagerFactory) FromEnv

func (ms *AVDManagerFactory) FromEnv(env *cloudy.Environment) (interface{}, error)

type AzureBlobFileShareFactory

type AzureBlobFileShareFactory struct{}

func (*AzureBlobFileShareFactory) Create

func (f *AzureBlobFileShareFactory) Create(cfg interface{}) (storage.FileStorageManager, error)

func (*AzureBlobFileShareFactory) FromEnv

func (f *AzureBlobFileShareFactory) FromEnv(env *cloudy.Environment) (interface{}, error)

type AzureBlobStorageFactory

type AzureBlobStorageFactory struct{}

func (*AzureBlobStorageFactory) Create

func (f *AzureBlobStorageFactory) Create(cfg interface{}) (storage.ObjectStorageManager, error)

func (*AzureBlobStorageFactory) FromEnv

func (f *AzureBlobStorageFactory) FromEnv(env *cloudy.Environment) (interface{}, error)

type AzureCosmosDbDatastore

type AzureCosmosDbDatastore struct {
	DB *Cosmosdb
	// contains filtered or unexported fields
}

func NewAzureCosmosDb

func NewAzureCosmosDb(url string, key string, database string, collection string, v interface{}) *AzureCosmosDbDatastore

func (*AzureCosmosDbDatastore) Close

func (*AzureCosmosDbDatastore) Delete

func (az *AzureCosmosDbDatastore) Delete(ctx context.Context, key string) error

func (*AzureCosmosDbDatastore) Exists

func (az *AzureCosmosDbDatastore) Exists(ctx context.Context, key string) (bool, error)

func (*AzureCosmosDbDatastore) Get

func (az *AzureCosmosDbDatastore) Get(ctx context.Context, key string) (interface{}, error)

func (*AzureCosmosDbDatastore) GetAll

func (az *AzureCosmosDbDatastore) GetAll(ctx context.Context) ([]interface{}, error)

func (*AzureCosmosDbDatastore) Open

func (az *AzureCosmosDbDatastore) Open(ctx context.Context, config interface{}) error

func (*AzureCosmosDbDatastore) Ping

func (*AzureCosmosDbDatastore) Query

func (az *AzureCosmosDbDatastore) Query(ctx context.Context, query *datastore.SimpleQuery) ([]interface{}, error)

func (*AzureCosmosDbDatastore) Save

func (az *AzureCosmosDbDatastore) Save(ctx context.Context, item interface{}, key string) error

Saves an item into the Elastic Search. This item MUST be JSON data. The key is used as the ID for the document and is required to be unique for this index

type AzureCredentialLoader

type AzureCredentialLoader struct{}

func (*AzureCredentialLoader) ReadFromEnv

func (loader *AzureCredentialLoader) ReadFromEnv(env *cloudy.Environment) interface{}

type AzureCredentials

type AzureCredentials struct {
	TenantID     string
	ClientID     string
	ClientSecret string
	Region       string
}

func GetAzureCredentialsFromEnv

func GetAzureCredentialsFromEnv(env *cloudy.Environment) AzureCredentials

type AzureFileShareFactory

type AzureFileShareFactory struct{}

func (*AzureFileShareFactory) Create

func (f *AzureFileShareFactory) Create(cfg interface{}) (storage.FileStorageManager, error)

func (*AzureFileShareFactory) FromEnv

func (f *AzureFileShareFactory) FromEnv(env *cloudy.Environment) (interface{}, error)

type AzureVMController

type AzureVMController struct {
	Vault  *KeyVault
	Client *armcompute.VirtualMachinesClient
	Usage  *armcompute.UsageClient
	Config *AzureVMControllerConfig
	// contains filtered or unexported fields
}

func NewAzureVMController

func NewAzureVMController(ctx context.Context, config *AzureVMControllerConfig) (*AzureVMController, error)

func (*AzureVMController) ConfigureDiskSize

func (vmc *AzureVMController) ConfigureDiskSize(ctx context.Context, vm *cloudyvm.VirtualMachineConfiguration) (int32, error)

func (*AzureVMController) ConfigureVmOsDiskOsTypeType

func (*AzureVMController) ConfigureVmOsProfile

func (*AzureVMController) CreateNIC

CreateNIC - Creates the Network Interface for the virtual machine. It mimics the terraform code listed below. The elements used by this method are: - VM Name / ID (from vm) - Region (from factory) - Resource Group (from factory) - Subnet ID (from vm)

Once created the NIC has an ID and an IP address that we care about. The VirtualMachineConfiguration input is mutated to add the appropriate information.

 az network nic create \
 	--resource-group go-on-azure  \
	--vnet-name go-on-azure-vmVNET \
	--subnet go-on-azure-vmSubnet \
	--name uvm-gotest-ip
resource "azurerm_network_interface" "main-nic" {
    name                      = join("-", [var.vdi-name, random_string.random.result])
    location                  = data.azurerm_resource_group.main-rg.location
    resource_group_name       = data.azurerm_resource_group.main-rg.name

	ip_configuration {
		name                          = join("-", [var.vdi-name, "IP"])
		subnet_id                     = data.azurerm_subnet.main-subnet.id
		private_ip_address_allocation = "Dynamic"
    }
}

NOT WORKING YET

func (*AzureVMController) CreateNSG

data "azurerm_network_security_group" "vdi-security-group" {
    name = var.vdi-nsg
    resource_group_name = data.azurerm_resource_group.main-rg.name
}

func (*AzureVMController) CreateVirtualMachine

func (vmc *AzureVMController) CreateVirtualMachine(ctx context.Context, vm *cloudyvm.VirtualMachineConfiguration) error

CreateVirtualMachine

resource "azurerm_linux_virtual_machine" "main-vm" {
    name                    = var.vdi-name
    computer_name           = var.vdi-name
    admin_username          = "salt"
    resource_group_name     = var.app-rg-name
    location                = var.def-location
    size                    = var.vdi-size
    source_image_id         = "/subscriptions/${var.subscription-id}/resourceGroups/${var.app-rg-name}/providers/Microsoft.Compute/galleries/${var.source-image-gallery-name}/images/${var.source-image}/versions/${var.source-image-version}"
    network_interface_ids   = [
        azurerm_network_interface.main-nic.id,
    ]

    admin_ssh_key {
        username = "salt"
        public_key = file("${path.module}/vdi-terraform_id_rsa.pub")
    }

    os_disk {
        caching              = "ReadWrite"
        storage_account_type = "Standard_LRS"
    }

    tags = {
        Application            = "SKYBORG"
        "Functional Area "     = "VDI"
        "User Principle Name"  = var.user-principle-name
    }
}

func (*AzureVMController) DeleteNIC

func (vmc *AzureVMController) DeleteNIC(ctx context.Context, vmId string, nicName string) error

func (*AzureVMController) DeleteVM

func (*AzureVMController) DeleteVMOSDisk

func (*AzureVMController) FindBestSubnet

func (vmc *AzureVMController) FindBestSubnet(ctx context.Context, availableSubnets []string) (string, error)

Finds the best subnet based on IP availabilty

func (*AzureVMController) GetAvailableIPS

func (vmc *AzureVMController) GetAvailableIPS(ctx context.Context, subnet string) (int, error)

Finds the best subnet based on IP availabilty

func (*AzureVMController) GetLatestImageVersion

func (vmc *AzureVMController) GetLatestImageVersion(ctx context.Context, imageName string) (string, error)

func (*AzureVMController) GetLimits

func (*AzureVMController) GetNIC

Find NIC if it already exists

func (*AzureVMController) GetNSG

func (*AzureVMController) GetVM

Find VM if it already exists

func (*AzureVMController) GetVMSize

func (vmc *AzureVMController) GetVMSize(ctx context.Context, size string) (*cloudyvm.VmSize, error)

func (*AzureVMController) GetVMSizes

func (vmc *AzureVMController) GetVMSizes(ctx context.Context) (map[string]*cloudyvm.VmSize, error)

func (*AzureVMController) GetVmOsDisk

func (*AzureVMController) ListAll

func (*AzureVMController) ListWithTag

func (vmc *AzureVMController) ListWithTag(ctx context.Context, tag string) ([]*cloudyvm.VirtualMachineStatus, error)

func (*AzureVMController) SetState

func (*AzureVMController) Start

func (vmc *AzureVMController) Start(ctx context.Context, vmName string, wait bool) error

func (*AzureVMController) Status

func (*AzureVMController) Stop

func (vmc *AzureVMController) Stop(ctx context.Context, vmName string, wait bool) error

func (*AzureVMController) Terminate

func (vmc *AzureVMController) Terminate(ctx context.Context, vmName string, wait bool) error

func (*AzureVMController) ValidateConfiguration

func (vmc *AzureVMController) ValidateConfiguration(ctx context.Context, vm *cloudyvm.VirtualMachineConfiguration) error

type AzureVMControllerConfig

type AzureVMControllerConfig struct {
	AzureCredentials
	SubscriptionID string
	ResourceGroup  string

	// ??
	NetworkResourceGroup            string // From Environment Variable
	SourceImageGalleryResourceGroup string
	SourceImageGalleryName          string   // From Environment Variable
	Vnet                            string   // From Environment Variable
	AvailableSubnets                []string // From Environment Variable
	NetworkSecurityGroupName        string   // From Environment Variable
	NetworkSecurityGroupID          string   // From Environment Variable
	// SaltCmd                         string   // From Environment Variable
	VaultURL string

	DomainControllerOverride string
	DomainControllers        []*string // From Environment Variable

	LogBody bool
}

type AzureVMControllerFactory

type AzureVMControllerFactory struct{}

func (*AzureVMControllerFactory) Create

func (f *AzureVMControllerFactory) Create(cfg interface{}) (cloudyvm.VMController, error)

func (*AzureVMControllerFactory) FromEnv

func (f *AzureVMControllerFactory) FromEnv(env *cloudy.Environment) (interface{}, error)

type AzureVMSizeCache

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

func (*AzureVMSizeCache) Load

func (*AzureVMSizeCache) Merge

func (azs *AzureVMSizeCache) Merge(ctx context.Context, datatype datastore.Datatype[any])

type AzureVirtualDesktop

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

func NewAzureVirtualDesktop

func NewAzureVirtualDesktop(ctx context.Context, config AzureVirtualDesktopConfig) (*AzureVirtualDesktop, error)

func (*AzureVirtualDesktop) AssignRoleToUser

func (avd *AzureVirtualDesktop) AssignRoleToUser(ctx context.Context, rg string, roleid string, upn string) error

func (*AzureVirtualDesktop) AssignSessionHost

func (avd *AzureVirtualDesktop) AssignSessionHost(ctx context.Context, rg string, hpname string, sessionhost string, userobjectid string) error

func (*AzureVirtualDesktop) DeleteSessionHost

func (avd *AzureVirtualDesktop) DeleteSessionHost(ctx context.Context, rg string, hpname string, sessionhost string) error

func (*AzureVirtualDesktop) DeleteUserSession

func (avd *AzureVirtualDesktop) DeleteUserSession(ctx context.Context, rg string, hpname string, sessionHost string, upn string) error

func (*AzureVirtualDesktop) DisconnecteUserSession

func (avd *AzureVirtualDesktop) DisconnecteUserSession(ctx context.Context, rg string, hpname string, sessionHost string, upn string) error

func (*AzureVirtualDesktop) FindFirstAvailableHostPool

func (avd *AzureVirtualDesktop) FindFirstAvailableHostPool(ctx context.Context, rg string, upn string) (*string, error)

func (*AzureVirtualDesktop) RetrieveRegistrationToken

func (avd *AzureVirtualDesktop) RetrieveRegistrationToken(ctx context.Context, rg string, hpname string) (*string, error)

type AzureVirtualDesktopConfig

type AzureVirtualDesktopConfig struct {
	AzureCredentials
	// contains filtered or unexported fields
}

type BlobContainerShare

type BlobContainerShare struct {
	Account    string
	AccountKey string
	UrlSlug    string
	Client     *azblob.Client
}

THe BlobContainerShare provides file shares based on the Azure Blob Storage

func NewBlobContainerShare

func NewBlobContainerShare(ctx context.Context, account string, accountKey string, urlslug string) (*BlobContainerShare, error)

func (*BlobContainerShare) Create

func (bfs *BlobContainerShare) Create(ctx context.Context, key string, tags map[string]string) (*storage.FileShare, error)

func (*BlobContainerShare) Delete

func (bfs *BlobContainerShare) Delete(ctx context.Context, key string) error

func (*BlobContainerShare) Exists

func (bfs *BlobContainerShare) Exists(ctx context.Context, key string) (bool, error)

func (*BlobContainerShare) Get

func (*BlobContainerShare) List

type BlobFileShare

type BlobFileShare struct {
	Client             *armstorage.FileSharesClient
	Credentials        AzureCredentials
	SubscriptionID     string
	ResourceGroupName  string
	StorageAccountName string
}

THe BlobFileShare provides file shares based on the Azure Blob Storage

func (*BlobFileShare) Connect

func (bfs *BlobFileShare) Connect(ctx context.Context) error

func (*BlobFileShare) Create

func (bfs *BlobFileShare) Create(ctx context.Context, key string, tags map[string]string) (*storage.FileShare, error)

func (*BlobFileShare) Delete

func (bfs *BlobFileShare) Delete(ctx context.Context, key string) error

func (*BlobFileShare) Exists

func (bfs *BlobFileShare) Exists(ctx context.Context, key string) (bool, error)

func (*BlobFileShare) Get

func (bfs *BlobFileShare) Get(ctx context.Context, key string) (*storage.FileShare, error)

func (*BlobFileShare) List

func (bfs *BlobFileShare) List(ctx context.Context) ([]*storage.FileShare, error)

type BlobStorage

type BlobStorage struct {
	Account    string
	AccountKey string
	Container  string
	UrlSlug    string
	Client     *container.Client
}

Object Storage

func NewBlobContainer

func NewBlobContainer(ctx context.Context, account string, accountKey string, container string, urlslug string) (*BlobStorage, error)

func NewBlobContainerFrom

func NewBlobContainerFrom(ctx context.Context, client *container.Client) *BlobStorage

func (*BlobStorage) Delete

func (b *BlobStorage) Delete(ctx context.Context, key string) error

func (*BlobStorage) Download

func (b *BlobStorage) Download(ctx context.Context, key string) (io.ReadCloser, error)

func (*BlobStorage) Exists

func (b *BlobStorage) Exists(ctx context.Context, key string) (bool, error)

func (*BlobStorage) List

func (*BlobStorage) ListNative

func (b *BlobStorage) ListNative(ctx context.Context, prefix string) ([]*container.BlobItem, []*container.BlobPrefix, error)

func (*BlobStorage) TagsToMap

func (b *BlobStorage) TagsToMap(tags *container.BlobTags) map[string]string

func (*BlobStorage) ToStoredObject

func (b *BlobStorage) ToStoredObject(item *container.BlobItem) *storage.StoredObject

func (*BlobStorage) UpdateMetadata added in v0.0.5

func (b *BlobStorage) UpdateMetadata(ctx context.Context, key string, tags map[string]string) error

func (*BlobStorage) Upload

func (b *BlobStorage) Upload(ctx context.Context, key string, data io.Reader, tags map[string]string) error

type BlobStorageAccount

type BlobStorageAccount struct {
	Account    string
	AccountKey string
	UrlSlug    string
	Client     *azblob.Client
}

ObjectStorageManager {

func NewBlobStorageAccount

func NewBlobStorageAccount(ctx context.Context, account string, accountKey string, urlslug string) (*BlobStorageAccount, error)

func (*BlobStorageAccount) Create

func (sa *BlobStorageAccount) Create(ctx context.Context, key string, openToPublic bool, tags map[string]string) (storage.ObjectStorage, error)

func (*BlobStorageAccount) Delete

func (sa *BlobStorageAccount) Delete(ctx context.Context, key string) error

func (*BlobStorageAccount) Exists

func (sa *BlobStorageAccount) Exists(ctx context.Context, key string) (bool, error)

func (*BlobStorageAccount) Get

func (*BlobStorageAccount) GetBlobContainer

func (sa *BlobStorageAccount) GetBlobContainer(ctx context.Context, name string) (*storage.StorageArea, error)

func (*BlobStorageAccount) GetItem

func (sa *BlobStorageAccount) GetItem(ctx context.Context, key string) (*storage.StorageArea, error)

func (*BlobStorageAccount) List

type CosmosObject

type CosmosObject struct {
	documentdb.Document
	Item interface{}
}

type Cosmosdb

type Cosmosdb struct {
	Database   string
	Collection string

	Model interface{}
	// contains filtered or unexported fields
}

func NewCosmosdb

func NewCosmosdb(db string, coll string, key string, endpoint string, model interface{}) (*Cosmosdb, error)

func (*Cosmosdb) Add

func (c *Cosmosdb) Add(id string, v interface{}) error

Create user

func (*Cosmosdb) Exists

func (c *Cosmosdb) Exists(id string) (bool, error)

Get user by given id

func (*Cosmosdb) Get

func (c *Cosmosdb) Get(id string) (interface{}, error)

Get user by given id

func (*Cosmosdb) GetAll

func (c *Cosmosdb) GetAll() ([]interface{}, error)

Get user by given id

func (*Cosmosdb) GetRaw

func (c *Cosmosdb) GetRaw(id string) (*CosmosObject, error)

Get user by given id

func (*Cosmosdb) Remove

func (c *Cosmosdb) Remove(id string) error

func (*Cosmosdb) Update

func (c *Cosmosdb) Update(id string, item interface{}) error

Update user by id

func (*Cosmosdb) Upsert

func (c *Cosmosdb) Upsert(id string, item interface{}) error

Update or insert

type KeyVault

type KeyVault struct {
	AzureCredentials
	VaultURL string
	Client   *azsecrets.Client
}

func NewKeyVault

func NewKeyVault(ctx context.Context, vaultURL string, credentials AzureCredentials) (*KeyVault, error)

func NewKeyVaultFromEnv added in v0.0.3

func NewKeyVaultFromEnv(env *cloudy.Environment) (*KeyVault, error)

func (*KeyVault) Configure

func (k *KeyVault) Configure(ctx context.Context) error

func (*KeyVault) DeleteSecret

func (k *KeyVault) DeleteSecret(ctx context.Context, key string) error

func (*KeyVault) GetSecret

func (k *KeyVault) GetSecret(ctx context.Context, key string) (string, error)

func (*KeyVault) GetSecretBinary

func (k *KeyVault) GetSecretBinary(ctx context.Context, key string) ([]byte, error)

func (*KeyVault) IsConflictErr

func (k *KeyVault) IsConflictErr(err error) bool

func (*KeyVault) IsNotFound

func (k *KeyVault) IsNotFound(err error) bool

func (*KeyVault) SaveSecret

func (k *KeyVault) SaveSecret(ctx context.Context, key string, data string) error

SaveSecret saves the secret in key vault. There are a few funny things that can happen here.

func (*KeyVault) SaveSecretBinary

func (k *KeyVault) SaveSecretBinary(ctx context.Context, key string, secret []byte) error

type KeyVaultConfig

type KeyVaultConfig struct {
	AzureCredentials
	VaultURL string `cloudyenv:"AZ_VAULT_URL"`
}

type KeyVaultEnvironment

type KeyVaultEnvironment struct {
	Vault  *KeyVault
	Prefix string
}

func NewKeyVaultEnvironmentService

func NewKeyVaultEnvironmentService(ctx context.Context, vaultURL string, credentials AzureCredentials, prefix string) (*KeyVaultEnvironment, error)

func (*KeyVaultEnvironment) Get

func (kve *KeyVaultEnvironment) Get(name string) (string, error)

func (*KeyVaultEnvironment) SaveAll

func (kve *KeyVaultEnvironment) SaveAll(ctx context.Context, items map[string]string) error

type KeyVaultEnvironmentCachedFactory

type KeyVaultEnvironmentCachedFactory struct{}

func (*KeyVaultEnvironmentCachedFactory) Create

func (c *KeyVaultEnvironmentCachedFactory) Create(cfg interface{}) (cloudy.EnvironmentService, error)

func (*KeyVaultEnvironmentCachedFactory) FromEnv

func (c *KeyVaultEnvironmentCachedFactory) FromEnv(env *cloudy.Environment) (interface{}, error)

type KeyVaultEnvironmentConfig

type KeyVaultEnvironmentConfig struct {
	AzureCredentials
	VaultURL string
	Prefix   string
}

type KeyVaultEnvironmentFactory

type KeyVaultEnvironmentFactory struct{}

func (*KeyVaultEnvironmentFactory) Create

func (c *KeyVaultEnvironmentFactory) Create(cfg interface{}) (cloudy.EnvironmentService, error)

func (*KeyVaultEnvironmentFactory) FromEnv

func (c *KeyVaultEnvironmentFactory) FromEnv(env *cloudy.Environment) (interface{}, error)

type KeyVaultFactory

type KeyVaultFactory struct{}

func (*KeyVaultFactory) Create

func (c *KeyVaultFactory) Create(cfg interface{}) (secrets.SecretProvider, error)

func (*KeyVaultFactory) FromEnv

func (c *KeyVaultFactory) FromEnv(env *cloudy.Environment) (interface{}, error)

func (*KeyVaultFactory) ListRequiredEnv added in v0.0.3

func (c *KeyVaultFactory) ListRequiredEnv(env *cloudy.Environment) []string

type User

type User struct {
	documentdb.Document
	Name  string `json:"name,omitempty"`
	Email string `json:"email,omitempty"`
}

User document

Jump to

Keyboard shortcuts

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