business_calendars

package
v1.54.1 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

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 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 Holiday

type Holiday struct {
	Title string `json:"title"`
	Date  string `json:"date" format:"date"`
}

func (*Holiday) MarshalHCL

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

func (*Holiday) Schema

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

func (*Holiday) UnmarshalHCL

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

type Holidays

type Holidays []*Holiday

func (Holidays) MarshalHCL

func (me Holidays) MarshalHCL(properties hcl.Properties) error

func (*Holidays) Schema

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

func (*Holidays) UnmarshalHCL

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

type Settings

type Settings struct {
	Title       string   `json:"title" maxlength:"200" minlength:"1"`         // The title / name of the Business Calendar
	Description string   `json:"description,omitempty"`                       // An optional description for the Business Calendar
	WeekStart   *int     `json:"weekstart,omitempty" minimum:"1" maximum:"7"` // Specifies the day of the week that's considered to be the first day in the week. `1` for Monday, `7` for Sunday
	WeekDays    []int    `json:"weekdays"`                                    // The days to be considered week days in this calendar. `1' = `Monday`, `2` = `Tuesday`, `3` = `Wednesday`, `4` = `Thursday`, `5` = `Friday`, `6` = `Saturday`, `7` = `Sunday`
	Holidays    Holidays `json:"holidays,omitempty"`                          // A list of holidays valid in this calendar
	ValidFrom   *string  `json:"validFrom,omitempty" format:"date"`           // The date from when on this calendar is valid from
	ValidTo     *string  `json:"validTo,omitempty" format:"date"`             // The date until when on this calendar is valid to

}

func (*Settings) MarshalHCL

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

func (*Settings) Name

func (me *Settings) Name() string

func (*Settings) Schema

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

func (*Settings) UnmarshalHCL

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

Jump to

Keyboard shortcuts

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