utils

package
v1.14.1 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2022 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	JWTEnvVar            = "SYM_JWT"
	SkipValidationEnvVar = "SYM_TF_SKIP_VALIDATION"
)
View Source
const (
	DocsHome           = "https://docs.symops.com/"
	DocsSupport        = "https://docs.symops.com/docs/support"
	DocsSymflowInstall = "https://docs.symops.com/docs/install-sym-flow"
	DocsSymflowLogin   = "https://docs.symops.com/docs/login-sym-flow"
	DocsImport         = "https://docs.symops.com/docs/reapplying-terraform"
)

Static URLs for specific Sym documentation pages.

Variables

View Source
var (
	ErrConfigFileDoesNotExist = GenerateError("No local Sym config was found. Have you installed the `symflow` CLI and run `symflow login` or set $SYM_JWT?", DocsSymflowInstall)
	ErrConfigFileNoJWT        = GenerateError("Your Sym access token is missing or invalid. Have you run `symflow login` or set $SYM_JWT?", DocsSymflowLogin)
	ErrSymflowNotInstalled    = GenerateError("`symflow` is not installed, please install it and run `symflow login`.", DocsSymflowInstall)
	ErrSymflowNoOrgConfigured = GenerateError("You do not have an org configured via `symflow`, please run `symflow login` or set $SYM_JWT with your Sym access token", DocsSymflowLogin)
)
View Source
var ErrAPIBadRequest = func(messages []Error) error {
	errorMessage := fmt.Sprintf("The Sym API returned a bad request error: %v", messages)
	return GenerateError(errorMessage, DocsSupport)
}
View Source
var ErrAPIConnect = func(endpoint string, requestId string) error {
	errorMessage := fmt.Sprintf("An unexpected error occurred while connecting to the Sym API. Please reach out to Sym Support.\nURL: %s\nRequest ID: %s", endpoint, requestId)
	return GenerateError(errorMessage, DocsSupport)
}
View Source
var ErrAPINotFound = func(endpoint string, requestId string) error {
	errorMessage := fmt.Sprintf("The Sym API URL you tried to use could not be found. Please reach out to Sym Support.\nURL: %s\nStatus Code: 404\nRequest ID: %s", endpoint, requestId)
	return GenerateError(errorMessage, DocsSupport)
}
View Source
var ErrAPIUnexpected = func(endpoint string, requestId string, statusCode int) error {
	errorMessage := fmt.Sprintf("An unexpected error occurred while connecting to the Sym API. Please reach out to Sym Support.\nURL: %s\nStatus Code: %v\nRequest ID: %s", endpoint, statusCode, requestId)
	return GenerateError(errorMessage, DocsSupport)
}
View Source
var ErrInvalidImportTypeSlug = func(resource, identifier string) error {
	errorMessage := fmt.Sprintf("The provided %s identifier %s could not be parsed. Identifiers must be in the form of `TYPE:SLUG`.", resource, identifier)
	return GenerateError(errorMessage, DocsImport)
}
View Source
var ErrInvalidImportUUID = func(resource string) error {
	errorMessage := fmt.Sprintf("Looks like you tried to import a %s by UUID, but it only supports importing by `SLUG`.", resource)
	return GenerateError(errorMessage, DocsImport)
}
View Source
var ErrSymflowWrongOrg = func(symflowOrg string, providerOrg string) error {
	errorMessage := fmt.Sprintf(
		"You are logged in to `symflow` using the %s org, but the Sym provider is configured with the %s org. Please ensure that you are logged in to the correct org via `symflow`.",
		symflowOrg,
		providerOrg,
	)
	return GenerateError(errorMessage, DocsSymflowLogin)
}

Functions

func DiagFromError

func DiagFromError(err error, summary string) diag.Diagnostic

func DiagsCheckError

func DiagsCheckError(diags diag.Diagnostics, err error, summary string) diag.Diagnostics

func DiagsFromError

func DiagsFromError(err error, summary string) diag.Diagnostics

func GenerateError

func GenerateError(detail string, docs string) error

GenerateError generates Sym errors in a standard format.

func GetStr

func GetStr(m map[string]interface{}, key string) (string, bool)

GetStr retrieves a string safely from a given map `m` at the given `key`, if it exists. If the value does not exist or is not a string, returns `("", false)`.

func JsonBytesEqual

func JsonBytesEqual(b1 []byte, b2 []byte) bool

func Optional

func Optional(valueType schema.ValueType, description string) *schema.Schema

func ParseImpl

func ParseImpl(impl string) string

ParseImpl takes in an impl in base64, text, or filename format, and consistently returns the impl in text format, if possible.

func ParseRemoteImpl

func ParseRemoteImpl(impl string) string

ParseRemoteImpl takes in an impl in base64 or text format, and consistently returns the impl in text format, if possible.

func PrefixDiagPaths

func PrefixDiagPaths(diags diag.Diagnostics, prefix cty.Path)

func Required

func Required(valueType schema.ValueType, description string) *schema.Schema

func RequiredCaseInsensitiveString

func RequiredCaseInsensitiveString(description string) *schema.Schema

func SettingsMap

func SettingsMap(description string) *schema.Schema

func StringList

func StringList(required bool, description string) *schema.Schema

func SuppressCaseSensitiveNamesDiffs

func SuppressCaseSensitiveNamesDiffs(k, old, new string, _ *schema.ResourceData) bool

func SuppressEquivalentFileContentDiffs

func SuppressEquivalentFileContentDiffs(k string, old string, new string, _ *schema.ResourceData) bool

SuppressEquivalentFileContentDiffs is a DiffSuppressFunc that can be passed into a schema when the provider receives file content from the API but needs to compare against the file content locally, but the terraform specifies the file name vs. content.

e.g. the API response vs. the terraform, we get something like implementation = "ZnJvbSBzeW0uYW5ub3RhdGlvbnMgaW1wb3J0" implementation = "impl.py"

If the file fails to be read, we will return false to specify that we should not suppress the difference. If the incoming base64 encoding file fails to decode, we will return false.

NOTE: if true is returned, the diff is suppressed and the field whose diff is being suppressed will have a value matching the OLD input. This means that if the diff is suppressed, we need to account for already having a base64 encoded string as the field's value vs. a file path.

func SuppressEquivalentJsonDiffs

func SuppressEquivalentJsonDiffs(k string, old string, new string, _ *schema.ResourceData) bool

SuppressEquivalentJsonDiffs is a DiffSuppressFunc that can be passed into a schema to ensure meaningless differences in JSON are ignored when reading/writing.

e.g. without this function, TF will see the following two blobs as different, and prompt an update. With this function set, the blobs are seen as equivalent:

{"template": "sym:approval", "name": "access"}
{"name": "access", "template": "sym:approval"}

func SuppressFlowDiffs

func SuppressFlowDiffs(k string, old string, new string, d *schema.ResourceData) bool

func SuppressNullSettingsDiffs

func SuppressNullSettingsDiffs(k string, old string, new string, d *schema.ResourceData) bool

SuppressNullSettingsDiffs is a DiffSuppressFunc that can be passed into a schema to account for differences in settings maps received from the API and stored in the Terraform state.

e.g. if a Terraform object's settings are empty:

settings {}

the API may still send the full dictionary of possible settings will null values

{"account_id": null, ...}

where effectively those values are the same, but Terraform's diff will not know that.

SuppressNullSettingsDiffs will be called on each item in the settings map individually as well as on the settings map as a whole.

func TranslateDiagPaths

func TranslateDiagPaths(diags diag.Diagnostics, keyMap map[string]string)

Types

type AuthToken

type AuthToken struct {
	AccessToken string `yaml:"access_token"`
}

type Config

type Config struct {
	AuthToken       *AuthToken `yaml:"auth_token"`
	ClientID        string     `yaml:"client_id"`
	Email           string     `yaml:"email"`
	Org             string     `yaml:"org"`
	LastUpdateCheck string     `yaml:"last_update_check"`
	// contains filtered or unexported fields
}

Config is the deserialized form of the sym config.yml file. Note: Keep this in sync with the file structure in symflow CLI.

func GetConfig

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

GetConfig reads the Sym config file at the given path and relevant environment variables and returns a Config

func GetDefaultConfig

func GetDefaultConfig() (*Config, error)

GetDefaultConfig reads the Sym config at the default config path

func (*Config) ValidateOrg

func (c *Config) ValidateOrg(tfOrg string) error

type Error

type Error struct {
	Field   string `json:"field"`
	Message string `json:"message"`
}

type ErrorResponse

type ErrorResponse struct {
	Error       bool    `json:"error"`
	Errors      []Error `json:"errors"`
	Code        string  `json:"code"`
	StatusCode  int     `json:"status_code"`
	IsRetryable bool    `json:"is_retryable"`
}

Jump to

Keyboard shortcuts

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