Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate input against Org / Space Name Spec #92

Open
ehaselwanter opened this issue May 6, 2024 · 5 comments
Open

Validate input against Org / Space Name Spec #92

ehaselwanter opened this issue May 6, 2024 · 5 comments

Comments

@ehaselwanter
Copy link

The space Ressource needs some input validation to meet the platform requirements

To Reproduce

│ Error: Client Error
│
│   with mondoo_space.spaces["macos_clients"],
│   on mondoo.tf line 3, in resource "mondoo_space" "spaces":
│    3: resource "mondoo_space" "spaces" {
│
│ Unable to create space, got error: rpc error: code = InvalidArgument desc =
│ space name is not valid

with

# mondoo_space.spaces["macos_clients"] will be created
  + resource "mondoo_space" "spaces" {
  + id     = (known after apply)
  + mrn    = (known after apply)
  + name   = "Zaatars solutions MacOS clients"
  + org_id = "whatever-613383"
}

Expected behavior

validate against:

Org / Space Name: name: letters, numbers, single quotes, hyphens, spaces or exclamation points, more then 4 chars
Regex: ^([a-zA-Z \-'_]|\d){2,30}$

@chris-rock
Copy link
Member

The solution is described in https://developer.hashicorp.com/terraform/plugin/framework/validation, we need to implement an attribute validation:

// Typically within the schema.Schema returned by Schema() for a provider,
// resource, or data source.
schema.StringAttribute{
    // ... other Attribute configuration ...

    Validators: []validator.String{
        // These are example validators from terraform-plugin-framework-validators
        stringvalidator.LengthBetween(10, 256),
        stringvalidator.RegexMatches(
            regexp.MustCompile(`^[a-z0-9]+$`),
            "must contain only lowercase alphanumeric characters",
        ),
    },
}

@chris-rock
Copy link
Member

We should use the following regex:

IDs: ^[a-z]([\d-_]|[a-z]){4,33}[a-z\d]$
Name: ^([a-zA-Z \-'_]|\d){2,30}$

@mati007thm
Copy link
Contributor

@chris-rock
According to the picture, the validation should be ^[a-z]([\d-_]|[a-z]){6,35}[a-z\d]$ or am I misunderstanding something?
image


Another question that we are unsure of, if there should be a validation of other fields (e.g. Name of an integration), since no validation applies in the UI?
image

@Pauti
Copy link
Contributor

Pauti commented Jun 21, 2024

#114

@Pauti
Copy link
Contributor

Pauti commented Jun 26, 2024

For instance, we tried to exceed 256 characters in the name string, which resulted in the error: Unable to create Domain integration, got error: client: validator failed for field "IntegrationsManager.name": value is greater than the required length at runtime (In the UI and with Terraform). However, there was no limitation on special characters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants