directshares

package
v1.58.6 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const SchemaVersion = 3

Variables

View Source
var Validate = func(fn ...schema.SchemaValidateDiagFunc) schema.SchemaValidateDiagFunc {
	return func(i any, p cty.Path) diag.Diagnostics {
		var diags diag.Diagnostics
		for _, validateFunc := range fn {
			diags = append(diags, validateFunc(i, p)...)
		}
		return diags
	}
}
View Source
var ValidateMax = func(max int) schema.SchemaValidateDiagFunc {
	return func(i any, p cty.Path) diag.Diagnostics {
		var diags diag.Diagnostics
		var iv int
		switch v := i.(type) {
		case int:
			iv = v
		case string:
			var err error
			v = strings.TrimSpace(v)
			if strings.HasPrefix(v, "{{") && strings.HasSuffix(v, "}}") {
				return diags
			}
			iv, err = strconv.Atoi(v)
			if err != nil {
				diags = append(diags, diag.Diagnostic{Severity: diag.Error, Summary: fmt.Sprintf("%s is not a number", i.(string))})
				return diags
			}
		}
		if iv > max {
			diags = append(diags, diag.Diagnostic{Severity: diag.Error, Summary: fmt.Sprintf("%v must not be greater than %d", i, max)})
		}
		return diags
	}
}
View Source
var ValidateMaxLength = func(maxLength int) schema.SchemaValidateDiagFunc {
	return func(i any, p cty.Path) diag.Diagnostics {
		var diags diag.Diagnostics
		if len(i.(string)) > maxLength {
			diag := diag.Diagnostic{
				Severity: diag.Error,
				Summary:  fmt.Sprintf("%s exceeds the maximum length of %d characters", i.(string), maxLength),
			}
			diags = append(diags, diag)
		}
		return diags
	}
}
View Source
var ValidateMin = func(min int) schema.SchemaValidateDiagFunc {
	return func(i any, p cty.Path) diag.Diagnostics {
		var diags diag.Diagnostics
		var iv int
		switch v := i.(type) {
		case int:
			iv = v
		case string:
			var err error
			v = strings.TrimSpace(v)
			if strings.HasPrefix(v, "{{") && strings.HasSuffix(v, "}}") {
				return diags
			}
			iv, err = strconv.Atoi(v)
			if err != nil {
				diags = append(diags, diag.Diagnostic{Severity: diag.Error, Summary: fmt.Sprintf("%s is not a number", i.(string))})
				return diags
			}
		}
		if iv < min {
			diags = append(diags, diag.Diagnostic{Severity: diag.Error, Summary: fmt.Sprintf("%v must not be less than %d", i, min)})
		}
		return diags
	}
}
View Source
var ValidateMinLength = func(min int) schema.SchemaValidateDiagFunc {
	return func(i any, p cty.Path) diag.Diagnostics {
		var diags diag.Diagnostics
		if len(i.(string)) < min {
			diag := diag.Diagnostic{
				Severity: diag.Error,
				Summary:  fmt.Sprintf("%s must be at least %d characters long", i.(string), min),
			}
			diags = append(diags, diag)
		}
		return diags
	}
}
View Source
var ValidateRange = func(min int, max int) schema.SchemaValidateDiagFunc {
	return func(i any, p cty.Path) diag.Diagnostics {
		var diags diag.Diagnostics
		var iv int
		switch v := i.(type) {
		case int:
			iv = v
		case string:
			var err error
			v = strings.TrimSpace(v)
			if strings.HasPrefix(v, "{{") && strings.HasSuffix(v, "}}") {
				return diags
			}
			iv, err = strconv.Atoi(v)
			if err != nil {
				diags = append(diags, diag.Diagnostic{Severity: diag.Error, Summary: fmt.Sprintf("%s is not a number", i.(string))})
				return diags
			}
		}
		if iv < min || iv > max {
			diags = append(diags, diag.Diagnostic{Severity: diag.Error, Summary: fmt.Sprintf("%v is not in range %d and %d", i, min, max)})
		}
		return diags
	}
}
View Source
var ValidateRegex = func(r *regexp.Regexp, errorMessage string) schema.SchemaValidateDiagFunc {
	return func(i any, p cty.Path) diag.Diagnostics {
		var diags diag.Diagnostics
		if !r.MatchString(i.(string)) {
			diag := diag.Diagnostic{
				Severity: diag.Error,
				Summary:  fmt.Sprintf("%s contains invalid characters", i.(string)),
				Detail:   errorMessage,
			}
			diags = append(diags, diag)
		}
		return diags
	}
}
View Source
var ValidateTypePossibleValues = func(valuesList []string) schema.SchemaValidateDiagFunc {
	return func(i any, p cty.Path) diag.Diagnostics {
		var diags diag.Diagnostics
		if !isInList(i.(string), valuesList) {
			diag := diag.Diagnostic{
				Severity: diag.Error,
				Summary:  fmt.Sprintf("%s is not on the list of possible values: %s", i.(string), valuesList),
			}
			diags = append(diags, diag)
		}
		return diags
	}
}
View Source
var ValidateUUID = func(i any, p cty.Path) diag.Diagnostics {
	var diags diag.Diagnostics
	if _, err := uuid.Parse(i.(string)); err != nil {
		diag := diag.Diagnostic{
			Severity: diag.Error,
			Summary:  "The value is expected to be a UUID",
			Detail:   fmt.Sprintf("%v is not a UUID", i),
		}
		diags = append(diags, diag)
	}
	return diags
}

Functions

This section is empty.

Types

type DirectShare

type DirectShare struct {
	ID            string     `json:"id"`
	DocumentId    string     `json:"document_id"`
	Access        string     `json:"access"`
	Recipients    Recipients `json:"recipients"`
	SchemaVersion int        `json:"schemaVersion,omitempty"`
}

func (*DirectShare) MarshalHCL

func (me *DirectShare) MarshalHCL(properties hcl.Properties) error

func (*DirectShare) MarshalJSON

func (me *DirectShare) MarshalJSON() ([]byte, error)

func (*DirectShare) Schema

func (me *DirectShare) Schema() map[string]*schema.Schema

func (*DirectShare) UnmarshalHCL

func (me *DirectShare) UnmarshalHCL(decoder hcl.Decoder) error

type Recipient

type Recipient struct {
	Id   string `json:"id"`
	Type string `json:"type"`
}

func (*Recipient) MarshalHCL

func (me *Recipient) MarshalHCL(properties hcl.Properties) error

func (*Recipient) Schema

func (me *Recipient) Schema() map[string]*schema.Schema

func (*Recipient) UnmarshalHCL

func (me *Recipient) UnmarshalHCL(decoder hcl.Decoder) error

type Recipients

type Recipients []*Recipient

func (*Recipients) MarshalHCL

func (me *Recipients) MarshalHCL(properties hcl.Properties) error

func (*Recipients) Schema

func (me *Recipients) Schema() map[string]*schema.Schema

func (*Recipients) UnmarshalHCL

func (me *Recipients) UnmarshalHCL(decoder hcl.Decoder) error

Jump to

Keyboard shortcuts

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