Skip to content

Commit

Permalink
SEC-090: Automated trusted workflow pinning (2024-08-19) (#1367)
Browse files Browse the repository at this point in the history
* Result of tsccr-helper -log-level=info gha update -latest .

* Resolve linter errors and warnings

---------

Co-authored-by: hashicorp-tsccr[bot] <hashicorp-tsccr[bot]@users.noreply.github.com>
Co-authored-by: Selena Goods <[email protected]>
  • Loading branch information
3 people authored Aug 20, 2024
1 parent 580b45a commit 651ff33
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
- run: go mod download
- run: go test -coverprofile=coverage.out ./...
- run: go tool cover -html=coverage.out -o coverage.html
- uses: actions/upload-artifact@89ef406dd8d7e03cfd12d9e0a4a378f454709029 # v4.3.5
- uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a # v4.3.6
with:
name: go-${{ matrix.go-version }}-coverage
path: coverage.html
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ linters:
- unconvert
- unparam
- unused
- vet
- govet

run:
# Prevent false positive timeouts in CI
Expand Down
6 changes: 3 additions & 3 deletions helper/acctest/random.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ func RandomWithPrefix(name string) string {
return fmt.Sprintf("%s-%d", name, RandInt())
}

// RandIntRange returns a random integer between min (inclusive) and max (exclusive)
func RandIntRange(min int, max int) int {
return rand.Intn(max-min) + min
// RandIntRange returns a random integer between minVal (inclusive) and maxVal (exclusive)
func RandIntRange(minVal int, maxVal int) int {
return rand.Intn(maxVal-minVal) + minVal
}

// RandString generates a random alphanumeric string of the length specified
Expand Down
2 changes: 1 addition & 1 deletion helper/schema/shims_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func testApplyDiff(t *testing.T,
}

if !cmp.Equal(expectedState, newState, equateEmpty, typeComparer, valueComparer) {
t.Fatalf(cmp.Diff(expectedState, newState, equateEmpty, typeComparer, valueComparer))
t.Fatal(cmp.Diff(expectedState, newState, equateEmpty, typeComparer, valueComparer))
}
}

Expand Down
24 changes: 12 additions & 12 deletions helper/validation/float.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ import (
)

// FloatBetween returns a SchemaValidateFunc which tests if the provided value
// is of type float64 and is between min and max (inclusive).
func FloatBetween(min, max float64) schema.SchemaValidateFunc {
// is of type float64 and is between minVal and maxVal (inclusive).
func FloatBetween(minVal, maxVal float64) schema.SchemaValidateFunc {
return func(i interface{}, k string) (s []string, es []error) {
v, ok := i.(float64)
if !ok {
es = append(es, fmt.Errorf("expected type of %s to be float64", k))
return
}

if v < min || v > max {
es = append(es, fmt.Errorf("expected %s to be in the range (%f - %f), got %f", k, min, max, v))
if v < minVal || v > maxVal {
es = append(es, fmt.Errorf("expected %s to be in the range (%f - %f), got %f", k, minVal, maxVal, v))
return
}

Expand All @@ -29,17 +29,17 @@ func FloatBetween(min, max float64) schema.SchemaValidateFunc {
}

// FloatAtLeast returns a SchemaValidateFunc which tests if the provided value
// is of type float and is at least min (inclusive)
func FloatAtLeast(min float64) schema.SchemaValidateFunc {
// is of type float and is at least minVal (inclusive)
func FloatAtLeast(minVal float64) schema.SchemaValidateFunc {
return func(i interface{}, k string) (s []string, es []error) {
v, ok := i.(float64)
if !ok {
es = append(es, fmt.Errorf("expected type of %s to be float", k))
return
}

if v < min {
es = append(es, fmt.Errorf("expected %s to be at least (%f), got %f", k, min, v))
if v < minVal {
es = append(es, fmt.Errorf("expected %s to be at least (%f), got %f", k, minVal, v))
return
}

Expand All @@ -48,17 +48,17 @@ func FloatAtLeast(min float64) schema.SchemaValidateFunc {
}

// FloatAtMost returns a SchemaValidateFunc which tests if the provided value
// is of type float and is at most max (inclusive)
func FloatAtMost(max float64) schema.SchemaValidateFunc {
// is of type float and is at most maxVal (inclusive)
func FloatAtMost(maxVal float64) schema.SchemaValidateFunc {
return func(i interface{}, k string) (s []string, es []error) {
v, ok := i.(float64)
if !ok {
es = append(es, fmt.Errorf("expected type of %s to be float", k))
return
}

if v > max {
es = append(es, fmt.Errorf("expected %s to be at most (%f), got %f", k, max, v))
if v > maxVal {
es = append(es, fmt.Errorf("expected %s to be at most (%f), got %f", k, maxVal, v))
return
}

Expand Down
24 changes: 12 additions & 12 deletions helper/validation/int.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ import (
)

// IntBetween returns a SchemaValidateFunc which tests if the provided value
// is of type int and is between min and max (inclusive)
func IntBetween(min, max int) schema.SchemaValidateFunc {
// is of type int and is between minVal and maxVal (inclusive)
func IntBetween(minVal, maxVal int) schema.SchemaValidateFunc {
return func(i interface{}, k string) (warnings []string, errors []error) {
v, ok := i.(int)
if !ok {
errors = append(errors, fmt.Errorf("expected type of %s to be integer", k))
return warnings, errors
}

if v < min || v > max {
errors = append(errors, fmt.Errorf("expected %s to be in the range (%d - %d), got %d", k, min, max, v))
if v < minVal || v > maxVal {
errors = append(errors, fmt.Errorf("expected %s to be in the range (%d - %d), got %d", k, minVal, maxVal, v))
return warnings, errors
}

Expand All @@ -30,17 +30,17 @@ func IntBetween(min, max int) schema.SchemaValidateFunc {
}

// IntAtLeast returns a SchemaValidateFunc which tests if the provided value
// is of type int and is at least min (inclusive)
func IntAtLeast(min int) schema.SchemaValidateFunc {
// is of type int and is at least minVal (inclusive)
func IntAtLeast(minVal int) schema.SchemaValidateFunc {
return func(i interface{}, k string) (warnings []string, errors []error) {
v, ok := i.(int)
if !ok {
errors = append(errors, fmt.Errorf("expected type of %s to be integer", k))
return warnings, errors
}

if v < min {
errors = append(errors, fmt.Errorf("expected %s to be at least (%d), got %d", k, min, v))
if v < minVal {
errors = append(errors, fmt.Errorf("expected %s to be at least (%d), got %d", k, minVal, v))
return warnings, errors
}

Expand All @@ -49,17 +49,17 @@ func IntAtLeast(min int) schema.SchemaValidateFunc {
}

// IntAtMost returns a SchemaValidateFunc which tests if the provided value
// is of type int and is at most max (inclusive)
func IntAtMost(max int) schema.SchemaValidateFunc {
// is of type int and is at most maxVal (inclusive)
func IntAtMost(maxVal int) schema.SchemaValidateFunc {
return func(i interface{}, k string) (warnings []string, errors []error) {
v, ok := i.(int)
if !ok {
errors = append(errors, fmt.Errorf("expected type of %s to be integer", k))
return warnings, errors
}

if v > max {
errors = append(errors, fmt.Errorf("expected %s to be at most (%d), got %d", k, max, v))
if v > maxVal {
errors = append(errors, fmt.Errorf("expected %s to be at most (%d), got %d", k, maxVal, v))
return warnings, errors
}

Expand Down
17 changes: 9 additions & 8 deletions helper/validation/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,24 @@ import (
"sort"

"github.com/hashicorp/go-cty/cty"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

// MapKeyLenBetween returns a SchemaValidateDiagFunc which tests if the provided value
// is of type map and the length of all keys are between min and max (inclusive)
func MapKeyLenBetween(min, max int) schema.SchemaValidateDiagFunc {
// is of type map and the length of all keys are between minVal and maxVal (inclusive)
func MapKeyLenBetween(minVal, maxVal int) schema.SchemaValidateDiagFunc {
return func(v interface{}, path cty.Path) diag.Diagnostics {
var diags diag.Diagnostics

for _, key := range sortedKeys(v.(map[string]interface{})) {
keyLen := len(key)
if keyLen < min || keyLen > max {
if keyLen < minVal || keyLen > maxVal {
diags = append(diags, diag.Diagnostic{
Severity: diag.Error,
Summary: "Bad map key length",
Detail: fmt.Sprintf("Map key lengths should be in the range (%d - %d): %s (length = %d)", min, max, key, keyLen),
Detail: fmt.Sprintf("Map key lengths should be in the range (%d - %d): %s (length = %d)", minVal, maxVal, key, keyLen),
AttributePath: append(path, cty.IndexStep{Key: cty.StringVal(key)}),
})
}
Expand All @@ -36,8 +37,8 @@ func MapKeyLenBetween(min, max int) schema.SchemaValidateDiagFunc {
}

// MapValueLenBetween returns a SchemaValidateDiagFunc which tests if the provided value
// is of type map and the length of all values are between min and max (inclusive)
func MapValueLenBetween(min, max int) schema.SchemaValidateDiagFunc {
// is of type map and the length of all values are between minVal and maxVal (inclusive)
func MapValueLenBetween(minVal, maxVal int) schema.SchemaValidateDiagFunc {
return func(v interface{}, path cty.Path) diag.Diagnostics {
var diags diag.Diagnostics

Expand All @@ -57,11 +58,11 @@ func MapValueLenBetween(min, max int) schema.SchemaValidateDiagFunc {
}

valLen := len(val.(string))
if valLen < min || valLen > max {
if valLen < minVal || valLen > maxVal {
diags = append(diags, diag.Diagnostic{
Severity: diag.Error,
Summary: "Bad map value length",
Detail: fmt.Sprintf("Map value lengths should be in the range (%d - %d): %s => %v (length = %d)", min, max, key, val, valLen),
Detail: fmt.Sprintf("Map value lengths should be in the range (%d - %d): %s => %v (length = %d)", minVal, maxVal, key, val, valLen),
AttributePath: append(path, cty.IndexStep{Key: cty.StringVal(key)}),
})
}
Expand Down
8 changes: 4 additions & 4 deletions helper/validation/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ func IsCIDR(i interface{}, k string) (warnings []string, errors []error) {
}

// IsCIDRNetwork returns a SchemaValidateFunc which tests if the provided value
// is of type string, is in valid Value network notation, and has significant bits between min and max (inclusive)
func IsCIDRNetwork(min, max int) schema.SchemaValidateFunc {
// is of type string, is in valid Value network notation, and has significant bits between minVal and maxVal (inclusive)
func IsCIDRNetwork(minVal, maxVal int) schema.SchemaValidateFunc {
return func(i interface{}, k string) (warnings []string, errors []error) {
v, ok := i.(string)
if !ok {
Expand All @@ -120,8 +120,8 @@ func IsCIDRNetwork(min, max int) schema.SchemaValidateFunc {
}

sigbits, _ := ipnet.Mask.Size()
if sigbits < min || sigbits > max {
errors = append(errors, fmt.Errorf("expected %q to contain a network Value with between %d and %d significant bits, got: %d", k, min, max, sigbits))
if sigbits < minVal || sigbits > maxVal {
errors = append(errors, fmt.Errorf("expected %q to contain a network Value with between %d and %d significant bits, got: %d", k, minVal, maxVal, sigbits))
}

return warnings, errors
Expand Down
8 changes: 4 additions & 4 deletions helper/validation/strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,17 @@ func StringIsWhiteSpace(i interface{}, k string) ([]string, []error) {
}

// StringLenBetween returns a SchemaValidateFunc which tests if the provided value
// is of type string and has length between min and max (inclusive)
func StringLenBetween(min, max int) schema.SchemaValidateFunc {
// is of type string and has length between minVal and maxVal (inclusive)
func StringLenBetween(minVal, maxVal int) schema.SchemaValidateFunc {
return func(i interface{}, k string) (warnings []string, errors []error) {
v, ok := i.(string)
if !ok {
errors = append(errors, fmt.Errorf("expected type of %s to be string", k))
return warnings, errors
}

if len(v) < min || len(v) > max {
errors = append(errors, fmt.Errorf("expected length of %s to be in the range (%d - %d), got %s", k, min, max, v))
if len(v) < minVal || len(v) > maxVal {
errors = append(errors, fmt.Errorf("expected length of %s to be in the range (%d - %d), got %s", k, minVal, maxVal, v))
}

return warnings, errors
Expand Down

0 comments on commit 651ff33

Please sign in to comment.