github.com/opentofu/opentofu@v1.7.1/internal/encryption/method/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 method
     7  
     8  import (
     9  	"fmt"
    10  )
    11  
    12  // ID is a type alias to make passing the wrong ID into a method ID harder.
    13  type ID string
    14  
    15  // Validate validates the key provider ID for correctness.
    16  func (i ID) Validate() error {
    17  	if i == "" {
    18  		return fmt.Errorf("empty key provider ID (key provider IDs must match %s)", idRe.String())
    19  	}
    20  	if !idRe.MatchString(string(i)) {
    21  		return fmt.Errorf("invalid key provider ID: %s (must match %s)", i, idRe.String())
    22  	}
    23  	return nil
    24  }