config

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package config manages grant application configuration.

Index

Constants

View Source
const (
	FavoriteTypeCloud  = "cloud"
	FavoriteTypeGroups = "groups"
)
View Source
const DefaultCacheTTL = 4 * time.Hour

DefaultCacheTTL is the default eligibility cache TTL.

Variables

This section is empty.

Functions

func AddFavorite

func AddFavorite(cfg *Config, name string, fav Favorite) error

AddFavorite adds a named favorite to the config. Returns an error if the name already exists. Defaults provider to "azure" if empty.

func ConfigDir

func ConfigDir() (string, error)

ConfigDir returns the default config directory path.

func ConfigPath

func ConfigPath() (string, error)

ConfigPath returns the config file path, respecting the GRANT_CONFIG env var.

func ParseCacheTTL added in v0.3.0

func ParseCacheTTL(cfg *Config) time.Duration

ParseCacheTTL returns the configured cache TTL duration. Falls back to DefaultCacheTTL if the config value is empty or unparseable.

func RemoveFavorite

func RemoveFavorite(cfg *Config, name string) error

RemoveFavorite removes a named favorite. Returns an error if not found.

func Save

func Save(cfg *Config, path string) error

Save writes a config to the given path, creating parent directories as needed.

Types

type Config

type Config struct {
	Profile         string              `yaml:"profile"`
	DefaultProvider string              `yaml:"default_provider"`
	CacheTTL        string              `yaml:"cache_ttl,omitempty"`
	Favorites       map[string]Favorite `yaml:"favorites"`
}

Config holds the grant application configuration.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns a Config with default values.

func Load

func Load(path string) (*Config, error)

Load reads a config file from the given path. If the file does not exist, it returns the default config.

func LoadDefaultWithPath added in v0.2.0

func LoadDefaultWithPath() (*Config, string, error)

LoadDefaultWithPath resolves the config path via ConfigPath() and loads the config. Returns the config, the resolved path, and any error.

type Favorite

type Favorite struct {
	Type        string `yaml:"type,omitempty"         json:"type,omitempty"`
	Provider    string `yaml:"provider"               json:"provider"`
	Target      string `yaml:"target"                 json:"target"`
	Role        string `yaml:"role"                   json:"role"`
	Group       string `yaml:"group,omitempty"        json:"group,omitempty"`
	DirectoryID string `yaml:"directory_id,omitempty" json:"directoryId,omitempty"`
}

Favorite represents a saved elevation target.

func GetFavorite

func GetFavorite(cfg *Config, name string) (Favorite, error)

GetFavorite retrieves a favorite by name. Returns an error if not found.

func (Favorite) ResolvedType added in v0.3.0

func (f Favorite) ResolvedType() string

ResolvedType returns the effective favorite type. Empty Type defaults to "cloud" for backward compatibility.

type FavoriteEntry

type FavoriteEntry struct {
	Name string
	Favorite
}

FavoriteEntry pairs a favorite name with its data, used for sorted listing.

func ListFavorites

func ListFavorites(cfg *Config) []FavoriteEntry

ListFavorites returns all favorites sorted alphabetically by name.

Jump to

Keyboard shortcuts

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