config

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: 10 Imported by: 1

README

deploystack/config

GoDoc

The subpackage manages all of the configuration details for DeployStack.

DeployStack Config Settings
Name Type Description
title string You know what a title is
duration number An estimate as to how long this installation takes
description string A text explanation of the stack. Useful in yaml config, as it can contain formatting.
collect_project boolean Whether or not to walk the user through picking or creating a project.
collect_region boolean Whether or not to walk the user through picking a regions
register_domain boolean Whether or not to walk the user through registering a domain
configure_gce_instance boolean Whether or not to walk the user through configuring a compute engine instance
region_type string Which product to select a region for
Options: compute, run, functions
region_default string The highlighted and default choice for region.
collect_zone string Whether or not to walk the user through picking a zone
hard_settings Deprecated Use author_settings below Hard Settings are for key value pairs to hardset and not get from the user.
"basename":"appprefix"
prepend_project bool Whether or not to prepend the project id to the default value. Useful for resources like buckets that have to have globally unique names.
path_terraform string Path that DeployStack should regard as the terraform folder.
path_messages string Path that DeployStack should look for messages, description and success.
path_scripts string Path that DeployStack should look for scripts that can be injected into DeployStack routine.
author_settings Documentation Below Author Settings are collections of settings that we would not like to prompt a user for.
custom_settings Documentation Below Custom Settings are collections of settings that we would like to prompt a user for.
projects Documentation Below Projects are a list of projects with settings that will surface the project selector interface for.
products Documentation Below Products are a list of products or other labels for structured documentation
Author Settings Options
Name Type Description
name string The name of the variable
value string The value of the varible as a string
type string A Terraform type that will be set in the terraform.tfvars file when deploystack is done: string, number, bool, list, map
list []string If type is list, you populate this with an array to populate the eventual setting - leave value blank
map map[string]string] If type is map, you populate this with an map to populate the eventual setting - leave value blank
Custom Settings Options
Name Type Description
name string The name of the variable
description string The description of the variable to prompt the user with
default string A default value for the variable.
options array An array of options to turn this into a custom select interface
Note Optionally you can pass a | to divide an option into a value and a label like so:
"weirdConfigSetting|User Readable Label"
Projects Settings Options
Name Type Description
allow_duplicates bool Whether or not a user can use the same project multiple times, defaults to false
Project Settings Options
Name Type Description
variable_name string The name of the variable
user_prompt string The description of the variable to prompt the user with
set_as_default string Whether or not to set this as the default project for the user
Product Settings Options
Name Type Description
product string The name of a product or other label for part of a solution. Used to add structured documentation.
info string The description of the product or other label.
UI Controls
Header
title: "A Sample Stack"
name: "sample"
duration: 9 
documentation_link: "https://cloud.google.com/shell/docs/cloud-shell-tutorials/deploystack"
products :
- info: "VM template" 
  product: "Instance Template"   
- info: "Clustering" 
  product: "Managed Instance Group"   
- info: "Load Balancing" 
  product: "Load Balancer"       
description:  | 
  This is additional stuff that will go here and be formatted. 
  * You can add a bullet list
  * That's totally cool

UI for Project Selector

Project Selector
collect_project: true

UI for Project Selector

Region Selector
collect_region: true
region_type: "run"
region_default: "us-central1"

UI for Region Selector

Zone Selector
collect_zone: true

UI for Zone Selector

Custom Settings - no options
custom_settings:
  - name : "nodes"
    description: "Please enter the number of nodes"
    default: 3

UI for Custom Settings with no options

Custom Settings - options
custom_settings:
  - name : "nodes2"
    description: "Please enter the number of nodes"
    default: 3
    options: ["1", "2", "3"]

UI for Custom Settings with options

Domain Registration
register_domain: truee

UI for Domain Registration

Documentation

Overview

Package config holds all of the data structures for DeployStack. Having them in main package caused circular dependecy issues.

Index

Constants

This section is empty.

Variables

View Source
var ErrConfigNotExist = fmt.Errorf("could not find and parse a config file")

ErrConfigNotExist is what happens when a config file either does not exist or exists but is not readable.

Functions

This section is empty.

Types

type Config

type Config struct {
	Title                string            `json:"title" yaml:"title"`
	Name                 string            `json:"name" yaml:"name"`
	Description          string            `json:"description" yaml:"description"`
	Duration             int               `json:"duration" yaml:"duration"`
	Project              bool              `json:"collect_project" yaml:"collect_project"`
	ProjectNumber        bool              `json:"collect_project_number" yaml:"collect_project_number"`
	BillingAccount       bool              `json:"collect_billing_account" yaml:"collect_billing_account"`
	Domain               bool              `json:"register_domain" yaml:"register_domain"`
	Region               bool              `json:"collect_region" yaml:"collect_region"`
	RegionType           string            `json:"region_type" yaml:"region_type"`
	RegionDefault        string            `json:"region_default" yaml:"region_default"`
	Zone                 bool              `json:"collect_zone" yaml:"collect_zone"`
	HardSet              map[string]string `json:"hard_settings" yaml:"hard_settings"`
	CustomSettings       Customs           `json:"custom_settings" yaml:"custom_settings"`
	AuthorSettings       Settings          `json:"author_settings" yaml:"author_settings"`
	ConfigureGCEInstance bool              `json:"configure_gce_instance" yaml:"configure_gce_instance"`
	DocumentationLink    string            `json:"documentation_link" yaml:"documentation_link"`
	PathTerraform        string            `json:"path_terraform" yaml:"path_terraform"`
	PathMessages         string            `json:"path_messages" yaml:"path_messages"`
	PathScripts          string            `json:"path_scripts" yaml:"path_scripts"`
	Projects             Projects          `json:"projects" yaml:"projects"`
	Products             []Product         `json:"products" yaml:"products"`
	// contains filtered or unexported fields
}

Config represents the settings this app will collect from a user. It should be in a json file. The idea is minimal programming has to be done to setup a DeployStack and export out a tfvars file for terraform part of solution.

func NewConfigJSON

func NewConfigJSON(content []byte) (Config, error)

NewConfigJSON returns a Config object from a file read.

func NewConfigYAML

func NewConfigYAML(content []byte) (Config, error)

NewConfigYAML returns a Config object from a file read.

func (*Config) ComputeName

func (c *Config) ComputeName(path string) error

ComputeName uses the git repo in the working directory to compute the shortname for the application.

func (Config) Copy added in v1.9.0

func (c Config) Copy() Config

Copy produces a copy of a config file for manipulating it without changing the original

func (*Config) GetAuthorSettings added in v1.4.0

func (c *Config) GetAuthorSettings() Settings

GetAuthorSettings delivers the combined Hardset and AuthorSettings variables

func (*Config) Getwd added in v1.9.0

func (c *Config) Getwd() string

func (Config) Marshal added in v1.9.0

func (c Config) Marshal(format string) ([]byte, error)

Marshal returns a string representation in format `json` or `yaml`

func (*Config) Setwd added in v1.9.0

func (c *Config) Setwd(wd string)

type Custom

type Custom struct {
	Setting        `json:"-"  yaml:"-"`
	Name           string   `json:"name"  yaml:"name"`
	Description    string   `json:"description"  yaml:"description"`
	Default        string   `json:"default"  yaml:"default"`
	Options        []string `json:"options"  yaml:"options"`
	PrependProject bool     `json:"prepend_project"  yaml:"prepend_project"`
	Validation     string   `json:"validation,omitempty"  yaml:"validation,omitempty"`
	// contains filtered or unexported fields
}

Custom represents a custom setting that we would like to collect from a user We will collect these settings from the user before continuing.

type Customs

type Customs []Custom

Customs are a slice of Custom variables.

func (Customs) Get

func (cs Customs) Get(name string) Custom

Get returns one Custom Variable

type Product added in v1.9.0

type Product struct {
	Info    string `json:"info" yaml:"info"`
	Product string `json:"product" yaml:"product"`
}

Product is some info about a GCP product

type Project

type Project struct {
	Name         string `json:"variable_name"  yaml:"variable_name"`
	UserPrompt   string `json:"user_prompt"  yaml:"user_prompt"`
	SetAsDefault bool   `json:"set_as_default"  yaml:"set_as_default"`
	// contains filtered or unexported fields
}

Project represets a GCP project for use in a stack

type Projects

type Projects struct {
	Items           []Project `json:"items"  yaml:"items"`
	AllowDuplicates bool      `json:"allow_duplicates"  yaml:"allow_duplicates"`
}

Projects is a list of projects that we will collect info for

type Report added in v1.5.0

type Report struct {
	Path   string
	WD     string
	Config Config
}

Report is collection of data about multiple configs in the same root used for multi stack repos

func FindConfigReports added in v1.5.0

func FindConfigReports(dir string) ([]Report, error)

FindConfigReports walks through a directory and finds all of the configs in the folder

func NewReport added in v1.5.0

func NewReport(file string) (Report, error)

NewReport Generates a new config report for a given file

type Setting added in v1.3.0

type Setting struct {
	Name  string            `json:"name"  yaml:"name"`
	Value string            `json:"value"  yaml:"value"`
	Type  string            `json:"type"  yaml:"type"`
	List  []string          `json:"list"  yaml:"list"`
	Map   map[string]string `json:"map"  yaml:"map"`
}

Setting is a item that will be translated to a varaible in a terraform file

func (*Setting) TFVars added in v1.4.0

func (s *Setting) TFVars() string

TFVars emits the name value combination here in away that terraform excepts in a tfvars file

func (Setting) TFvarsName added in v1.4.0

func (s Setting) TFvarsName() string

TFvarsName formats the name for the tfvars format

func (Setting) TFvarsValue added in v1.4.0

func (s Setting) TFvarsValue() string

TFvarsValue formats the value for the tfvars format

type Settings added in v1.3.0

type Settings []Setting

Settings are a collection of setting

func (*Settings) Add added in v1.3.0

func (s *Settings) Add(key, value string)

Add either creates a new setting or updates the existing one

func (*Settings) AddComplete added in v1.4.0

func (s *Settings) AddComplete(set Setting)

AddComplete adds an whole setting to the settings control

func (*Settings) Find added in v1.3.0

func (s *Settings) Find(key string) *Setting

Find locates a setting in the slice

func (*Settings) Replace added in v1.3.0

func (s *Settings) Replace(set Setting)

Replace will look for a setting with the same name, and overwrite the value

func (*Settings) Search added in v1.3.0

func (s *Settings) Search(q string) Settings

Search returns all settings whose names contain a particular string

func (*Settings) Sort added in v1.3.0

func (s *Settings) Sort()

Sort sorts the slice according to Setting.Name ascendings

type Stack

type Stack struct {
	Settings Settings
	Config   Config
}

Stack represents the input config and output settings for this DeployStack

func NewStack

func NewStack() Stack

NewStack returns an initialized Stack

func (*Stack) AddSetting

func (s *Stack) AddSetting(key, value string)

AddSetting stores a setting key/value pair.

func (*Stack) AddSettingComplete added in v1.4.0

func (s *Stack) AddSettingComplete(set Setting)

AddSettingComplete passes a completely intact setting to the underlying setting structure

func (*Stack) DeleteSetting

func (s *Stack) DeleteSetting(key string)

DeleteSetting removes a setting value.

func (*Stack) FindAndRead added in v1.9.0

func (s *Stack) FindAndRead(path string, required bool) error

FindAndRead figures out a default config, or reads it if it is there has option to insure various things and folders exist

func (*Stack) FindAndReadRequired

func (s *Stack) FindAndReadRequired(path string) error

FindAndReadRequired finds and reads in a Config from a json file.

func (*Stack) GetSetting

func (s *Stack) GetSetting(key string) string

GetSetting returns a setting value.

func (Stack) Terraform

func (s Stack) Terraform() string

Terraform returns all of the settings as a Terraform variables format.

func (Stack) TerraformFile

func (s Stack) TerraformFile(filename string) error

TerraformFile exports TFVars format to input file.

Jump to

Keyboard shortcuts

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