github.com/opentofu/opentofu@v1.7.1/internal/encryption/keyprovider/id.go (about)

     1  // Copyright (c) The OpenTofu Authors
     2  // SPDX-License-Identifier: MPL-2.0
     3  // Copyright (c) 2023 HashiCorp, Inc.
     4  // SPDX-License-Identifier: MPL-2.0
     5  
     6  package keyprovider
     7  
     8  import "fmt"
     9  
    10  // ID is a type alias to make passing the wrong ID into a key provider harder.
    11  type ID string
    12  
    13  // Validate validates the key provider ID for correctness.
    14  func (id ID) Validate() error {
    15  	if id == "" {
    16  		return fmt.Errorf("empty key provider ID (key provider IDs must match %s)", idRe.String())
    17  	}
    18  	if !idRe.MatchString(string(id)) {
    19  		return fmt.Errorf("invalid key provider ID: %s (must match %s)", id, idRe.String())
    20  	}
    21  	return nil
    22  }