-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dcf6297
commit 00ddf16
Showing
9 changed files
with
1,064 additions
and
31 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 |
---|---|---|
|
@@ -36,4 +36,9 @@ fmtcheck: | |
|
||
.PHONY: fmt | ||
fmt: | ||
gofumpt -l -w . | ||
gofumpt -l -w . | ||
|
||
mocks: | ||
go install github.com/vektra/mockery/[email protected] | ||
mockery --srcpkg github.com/hashicorp/hcp-sdk-go/clients/cloud-resource-manager/stable/2019-12-10/client/organization_service --name=ClientService | ||
mockery --srcpkg github.com/hashicorp/hcp-sdk-go/clients/cloud-resource-manager/stable/2019-12-10/client/project_service --name=ClientService |
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,48 @@ | ||
package hcpvaultengine | ||
|
||
import ( | ||
"github.com/hashicorp/vault/api" | ||
"golang.org/x/oauth2" | ||
) | ||
|
||
// TODO: reevaluate this cache strategy | ||
// Disk? Memory? Memdb? | ||
var cache *HCPVClusterCache | ||
|
||
type HCPVClusterCache struct { | ||
// Memory cache of the token source | ||
Source oauth2.TokenSource | ||
|
||
// Memory cache of the cluster address | ||
Address string | ||
|
||
// Memory cache of the cluster ID | ||
ID string | ||
} | ||
|
||
// ConfigureHCPProxy adds a client-side middleware, an implementation of http.RoundTripper on top of the base transport, | ||
// that will add a cookie to every request made from the CLI client. Additionally, it overrides the configuration's address | ||
// The address will be that of the proxy by default and the cookie will have the HCP access token data necessary to make requests to | ||
// the cluster through HCP. | ||
// | ||
// TODO: is there a better way to change the configuration without parametizing the Vault Config? | ||
func ConfigureHCPProxy(client *api.Client) error { | ||
if cache != nil { | ||
// TODO: reevaluate this. Which scheme? https? | ||
addr := "https://" + cache.Address | ||
err := client.SetAddress(addr) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// TODO: understand and reevaluate exactly what it means to get the token from the source or to get the TokenSource. | ||
token, err := cache.Source.Token() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
client.SetHCPToken(token) | ||
} | ||
|
||
return nil | ||
} |
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.