-
Notifications
You must be signed in to change notification settings - Fork 548
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into VAULT-24263/add-project-id-param-gcp
- Loading branch information
Showing
55 changed files
with
927 additions
and
298 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: golangci-lint | ||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
|
||
permissions: | ||
contents: read | ||
# Required to use the `only-new-issues` option below | ||
pull-requests: read | ||
|
||
jobs: | ||
golangci: | ||
name: lint | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 | ||
- uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1 | ||
with: | ||
go-version-file: '.go-version' | ||
cache: false | ||
- name: golangci-lint | ||
uses: golangci/golangci-lint-action@3cfe3a4abbb849e10058ce4af15d205b6da42804 | ||
with: | ||
version: latest | ||
args: --timeout 10m --verbose | ||
# show only new issues if it's a pull request | ||
only-new-issues: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1.21.3 | ||
1.21.6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package mountutil | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/hashicorp/terraform-provider-vault/internal/consts" | ||
"github.com/hashicorp/vault/api" | ||
) | ||
|
||
// Error strings that are returned by the Vault API. | ||
const ( | ||
ErrVaultSecretMountNotFound = "No secret engine mount at" | ||
ErrVaultAuthMountNotFound = "No auth engine at" | ||
) | ||
|
||
// Error strings that are used internally by TFVP | ||
var ( | ||
// ErrMountNotFound is used to signal to resources that a secret or auth | ||
// mount does not exist and should be removed from state. | ||
ErrMountNotFound = errors.New("mount not found") | ||
) | ||
|
||
// GetMount will fetch the secret mount at the given path. | ||
func GetMount(ctx context.Context, client *api.Client, path string) (*api.MountOutput, error) { | ||
mount, err := client.Sys().GetMountWithContext(ctx, path) | ||
// Hardcoding the error string check is not ideal, but Vault does not | ||
// return 404 in this case | ||
if err != nil && strings.Contains(err.Error(), ErrVaultSecretMountNotFound) { | ||
return nil, fmt.Errorf("%w: %s", ErrMountNotFound, err) | ||
} | ||
// some other error occured, like 403, etc. | ||
if err != nil { | ||
return nil, fmt.Errorf("error reading from Vault: %s", err) | ||
} | ||
// no error but no mount either, so return not found | ||
if mount == nil { | ||
return nil, fmt.Errorf("%w: %s", ErrMountNotFound, err) | ||
} | ||
return mount, nil | ||
} | ||
|
||
// GetAuthMount will fetch the auth mount at the given path. | ||
func GetAuthMount(ctx context.Context, client *api.Client, path string) (*api.MountOutput, error) { | ||
mount, err := client.Sys().GetAuthWithContext(ctx, path) | ||
// Hardcoding the error string check is not ideal, but Vault does not | ||
// return 404 in this case | ||
if err != nil && strings.Contains(err.Error(), ErrVaultAuthMountNotFound) { | ||
return nil, fmt.Errorf("%w: %s", ErrMountNotFound, err) | ||
} | ||
// some other error occured, like 403, etc. | ||
if err != nil { | ||
return nil, fmt.Errorf("error reading from Vault: %s", err) | ||
} | ||
// no error but no mount either, so return not found | ||
if mount == nil { | ||
return nil, fmt.Errorf("%w: %s", ErrMountNotFound, err) | ||
} | ||
return mount, nil | ||
} | ||
|
||
// NormalizeMountPath to be in a form valid for accessing values from api.MountOutput | ||
func NormalizeMountPath(path string) string { | ||
return TrimSlashes(path) + consts.PathDelim | ||
} | ||
|
||
// TrimSlashes from path. | ||
func TrimSlashes(path string) string { | ||
return strings.Trim(path, consts.PathDelim) | ||
} | ||
|
||
// CheckMountEnabledWithContext in Vault | ||
func CheckMountEnabledWithContext(ctx context.Context, client *api.Client, path string) (bool, error) { | ||
_, err := GetMount(ctx, client, path) | ||
if errors.Is(err, ErrMountNotFound) { | ||
return false, err | ||
} | ||
|
||
if err != nil { | ||
return false, err | ||
} | ||
|
||
return true, nil | ||
} | ||
|
||
// CheckMountEnabled in Vault | ||
func CheckMountEnabled(client *api.Client, path string) (bool, error) { | ||
return CheckMountEnabledWithContext(context.Background(), client, path) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.