verify

package
v0.0.0-...-2a79a0e Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2024 License: Apache-2.0, MPL-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Copied from the official Google Cloud auto-generated client.
	ProjectRegex         = "(?:(?:[-a-z0-9]{1,63}\\.)*(?:[a-z](?:[-a-z0-9]{0,61}[a-z0-9])?):)?(?:[0-9]{1,19}|(?:[a-z0-9](?:[-a-z0-9]{0,61}[a-z0-9])?))"
	ProjectRegexWildCard = "(?:(?:[-a-z0-9]{1,63}\\.)*(?:[a-z](?:[-a-z0-9]{0,61}[a-z0-9])?):)?(?:[0-9]{1,19}|(?:[a-z0-9](?:[-a-z0-9]{0,61}[a-z0-9])?)|-)"
	RegionRegex          = "[a-z](?:[-a-z0-9]{0,61}[a-z0-9])?"
	SubnetworkRegex      = "[a-z](?:[-a-z0-9]{0,61}[a-z0-9])?"

	SubnetworkLinkRegex = "projects/(" + ProjectRegex + ")/regions/(" + RegionRegex + ")/subnetworks/(" + SubnetworkRegex + ")$"

	RFC1035NameTemplate = "[a-z](?:[-a-z0-9]{%d,%d}[a-z0-9])"
	CloudIoTIdRegex     = "^[a-zA-Z][-a-zA-Z0-9._+~%]{2,254}$"

	// Format of default Compute service accounts created by Google
	// ${PROJECT_ID}-compute@developer.gserviceaccount.com where PROJECT_ID is an int64 (max 20 digits)
	ComputeServiceAccountNameRegex = "[0-9]{1,20}-compute@developer.gserviceaccount.com"

	// https://cloud.google.com/iam/docs/understanding-custom-roles#naming_the_role
	IAMCustomRoleIDRegex = "^[a-zA-Z0-9_\\.]{3,64}$"

	// https://cloud.google.com/managed-microsoft-ad/reference/rest/v1/projects.locations.global.domains/create#query-parameters
	ADDomainNameRegex = "^[a-z][a-z0-9-]{0,14}\\.[a-z0-9-\\.]*[a-z]+[a-z0-9]*$"
)

Variables

View Source
var (
	// Service account name must have a length between 6 and 30.
	// The first and last characters have different restrictions, than
	// the middle characters. The middle characters length must be between
	// 4 and 28 since the first and last character are excluded.
	ServiceAccountNameRegex = fmt.Sprintf(RFC1035NameTemplate, 4, 28)

	ServiceAccountLinkRegexPrefix = "projects/" + ProjectRegexWildCard + "/serviceAccounts/"
	PossibleServiceAccountNames   = []string{
		ServiceDefaultAccountNameRegex,
		ComputeServiceAccountNameRegex,
		CreatedServiceAccountNameRegex,
	}
	ServiceAccountLinkRegex = ServiceAccountLinkRegexPrefix + "(" + strings.Join(PossibleServiceAccountNames, "|") + ")"

	ServiceAccountKeyNameRegex = ServiceAccountLinkRegexPrefix + "(.+)/keys/(.+)"

	// Format of service accounts created through the API
	CreatedServiceAccountNameRegex = fmt.Sprintf(RFC1035NameTemplate, 4, 28) + "@" + ProjectNameInDNSFormRegex + "\\.iam\\.gserviceaccount\\.com$"

	// Format of service-created service account
	// examples are:
	// 		$PROJECTID@cloudbuild.gserviceaccount.com
	// 		$PROJECTID@cloudservices.gserviceaccount.com
	// 		$PROJECTID@appspot.gserviceaccount.com
	ServiceDefaultAccountNameRegex = ProjectRegex + "@[a-z]+.gserviceaccount.com$"

	ProjectNameInDNSFormRegex = "[-a-z0-9\\.]{1,63}"
	ProjectNameRegex          = "^[A-Za-z0-9-'\"\\s!]{4,30}$"

	// Valid range for Cloud Router ASN values as per RFC6996
	// https://tools.ietf.org/html/rfc6996
	// Must be explicitly int64 to avoid overflow when building Terraform for 32bit architectures
	Rfc6996Asn16BitMin  = int64(64512)
	Rfc6996Asn16BitMax  = int64(65534)
	Rfc6996Asn32BitMin  = int64(4200000000)
	Rfc6996Asn32BitMax  = int64(4294967294)
	GcpRouterPartnerAsn = int64(16550)
)
View Source
var Rfc1918Networks = []string{
	"10.0.0.0/8",
	"172.16.0.0/12",
	"192.168.0.0/16",
}

Functions

func PathOrContents

func PathOrContents(poc string) (string, bool, error)

If the argument is a path, pathOrContents loads it and returns the contents, otherwise the argument is assumed to be the desired contents and is simply returned.

The boolean second return value can be called `wasPath` - it indicates if a path was detected and a file loaded.

func StringNotInSlice

func StringNotInSlice(invalid []string, ignoreCase bool) schema.SchemaValidateFunc

StringNotInSlice returns a SchemaValidateFunc which tests if the provided value is of type string and that it matches none of the element in the invalid slice. if ignorecase is true, case is ignored.

func TestStringValidation

func TestStringValidation(testCase StringValidationTestCase, validationFunc schema.SchemaValidateFunc) []error

func TestStringValidationCases

func TestStringValidationCases(cases []StringValidationTestCase, validationFunc schema.SchemaValidateFunc) []error

func ValidateADDomainName

func ValidateADDomainName() schema.SchemaValidateFunc

func ValidateBase64String

func ValidateBase64String(i interface{}, val string) ([]string, []error)

func ValidateDSProjectID

func ValidateDSProjectID() schema.SchemaValidateFunc

func ValidateDuration

func ValidateDuration() schema.SchemaValidateFunc

func ValidateEnum

func ValidateEnum(values []string) schema.SchemaValidateFunc

func ValidateGCEName

func ValidateGCEName(v interface{}, k string) (ws []string, errors []error)

validateGCEName ensures that a field matches the requirements for Compute Engine resource names https://cloud.google.com/compute/docs/naming-resources#resource-name-format

func ValidateHourlyOnly

func ValidateHourlyOnly(val interface{}, key string) (warns []string, errs []error)

Ensure that hourly timestamp strings "HH:MM" have the minutes zeroed out for hourly only inputs

func ValidateIAMCustomRoleID

func ValidateIAMCustomRoleID(v interface{}, k string) (warnings []string, errors []error)

func ValidateIpAddress

func ValidateIpAddress(i interface{}, val string) ([]string, []error)

func ValidateIpCidrRange

func ValidateIpCidrRange(v interface{}, k string) (warnings []string, errors []error)

func ValidateNonNegativeDuration

func ValidateNonNegativeDuration() schema.SchemaValidateFunc

func ValidateProjectID

func ValidateProjectID() schema.SchemaValidateFunc

func ValidateProjectName

func ValidateProjectName() schema.SchemaValidateFunc

func ValidateRFC1035Name

func ValidateRFC1035Name(min, max int) schema.SchemaValidateFunc

func ValidateRFC1918Network

func ValidateRFC1918Network(min, max int) schema.SchemaValidateFunc

func ValidateRFC3339Date

func ValidateRFC3339Date(v interface{}, k string) (warnings []string, errors []error)

func ValidateRFC3339Time

func ValidateRFC3339Time(v interface{}, k string) (warnings []string, errors []error)

func ValidateRFC6996Asn

func ValidateRFC6996Asn(v interface{}, k string) (ws []string, errors []error)

Ensure that the BGP ASN value of Cloud Router is a valid value as per RFC6996 or a value of 16550

func ValidateRegexp

func ValidateRegexp(re string) schema.SchemaValidateFunc

Types

type StringValidationTestCase

type StringValidationTestCase struct {
	TestName    string
	Value       string
	ExpectError bool
}

Jump to

Keyboard shortcuts

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