dotazure

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 7, 2025 License: MIT Imports: 8 Imported by: 2 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Dotazure

releases reference ci

Locate and load environment variables defined when provisioning an Azure Developer CLI project.

Getting Started

If you do not already have an Azure Developer CLI (azd) project, you can create one:

azd init

After you define some resources e.g., an Azure Key Vault, you can provision those resources which will create a .env file with any output parameters:

azd up

Example

After azd up provisions resources and creates a .env file, you can call Load() to load those environment variables from the default environment e.g.,

package main

import (
    "errors"
    "fmt"
    "os"

    "github.com/heaths/go-dotazure"
)

func main() {
    if loaded, err := dotazure.Load(); err != nil {
        panic(err)
    } else if loaded {
        fmt.Fprintln(os.Stderr, "loaded environment variables")
    }

    // Assumes bicep contains e.g.
    //
    // output AZURE_KEYVAULT_URL string = kv.properties.vaultUri
    vaultURL, _ := os.LookupEnv("AZURE_KEYVAULT_URL")
    fmt.Printf("AZURE_KEYVAULT_URL=%q\n", vaultURL)
}

If you want to customize behavior, you can call Load() with various With* option functions.

License

Licensed under the MIT license.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Load

func Load(opts ...LoadOption) (bool, error)

Load loads environment variables for an Azure Developer CLI project.

Locates the `.env` file from the default environment name if an Azure Developer CLI project was already provisioned. Returns true if a `.env` file was found and loaded successfully; otherwise, returns an error.

Types

type AzdContext

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

AzdContext contains project information for the Azure Development CLI.

func NewAzdContext

func NewAzdContext(opts ...AzdContextOption) (*AzdContext, error)

NewAzdContext constructs a new AzdContext from the given options.

func (*AzdContext) EnvironmentDirectory

func (c *AzdContext) EnvironmentDirectory() string

EnvironmentDirectory gets the path to the .azure directory.

func (*AzdContext) EnvironmentFile

func (c *AzdContext) EnvironmentFile() string

EnvironmentFile gets the path to the .env file under EnvironmentRoot.

func (*AzdContext) EnvironmentName

func (c *AzdContext) EnvironmentName() string

EnvironmentName gets the name of the environment.

func (*AzdContext) EnvironmentRoot

func (c *AzdContext) EnvironmentRoot() string

EnvironmentRoot gets the path to the environment directory under EnvironmentDirectory.

func (*AzdContext) ProjectDirectory

func (c *AzdContext) ProjectDirectory() string

ProjectDirectory gets the directory containing the azure.yaml project file.

func (*AzdContext) ProjectPath

func (c *AzdContext) ProjectPath() string

ProjectPath gets the path to the azure.yaml project file.

type AzdContextOption

type AzdContextOption func(*config) error

AzdContextOption configures options for constructing an AzdContext.

func WithCurrentDirectory

func WithCurrentDirectory(path string) AzdContextOption

WithCurrentDirectory sets a different current directory for NewAzdContext.

func WithEnvironmentName

func WithEnvironmentName(name string) AzdContextOption

WithEnvironmentName sets custom environment name for NewAzdContext.

type LoadOption

type LoadOption func(*loader) error

LoadOption configures options for loading environment variables.

func WithContext

func WithContext(context *AzdContext) LoadOption

WithContext sets the AzdContext to use for discovery.

func WithReplace

func WithReplace(replace bool) LoadOption

WithReplace sets whether to replace environment variables that were already set.

Directories

Path Synopsis
cmd
secrets command

Jump to

Keyboard shortcuts

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