Add HCP subcommand -- integrate with HCP library (#23897)

* Add HCP engine token logic

* Update documentation

* Fix content check

* Add changelog entry

* Update changelog/23897.txt

Co-authored-by: Nick Cabatoff <ncabatoff@hashicorp.com>

* Update api/client.go

Co-authored-by: Chris Capurso <1036769+ccapurso@users.noreply.github.com>

* Add error when HCP commands failed to be initialize

* Add tests for initHCPcommand function

* Update lib dependency

* Update website/content/docs/commands/hcp.mdx

Co-authored-by: Sarah Chavis <62406755+schavis@users.noreply.github.com>

* Update website/content/docs/commands/hcp.mdx

Co-authored-by: Sarah Chavis <62406755+schavis@users.noreply.github.com>

* Update website/content/docs/commands/hcp.mdx

Co-authored-by: Sarah Chavis <62406755+schavis@users.noreply.github.com>

* Update website/content/docs/commands/hcp.mdx

Co-authored-by: Sarah Chavis <62406755+schavis@users.noreply.github.com>

* Update website/content/docs/commands/hcp.mdx

Co-authored-by: Sarah Chavis <62406755+schavis@users.noreply.github.com>

* Update website/content/docs/commands/hcp.mdx

Co-authored-by: Sarah Chavis <62406755+schavis@users.noreply.github.com>

* Update website/content/docs/commands/hcp.mdx

Co-authored-by: Sarah Chavis <62406755+schavis@users.noreply.github.com>

* Fix docs nav data

* Improve docs sections

* Update hcp lib dependency

* Fix content formatting

* Update lib dependency

* Fix HCPtokenhelper problem

* Fix HCPtokenhelper problem

* Remove HCP env variables

* Remove hcp helper token

* Add error treatment for no valid credential source

* Update website/content/docs/commands/hcp/index.mdx

Co-authored-by: Yoko Hyakuna <yoko@hashicorp.com>

* Update website/content/docs/commands/hcp/disconnect.mdx

Co-authored-by: Yoko Hyakuna <yoko@hashicorp.com>

* Update website/content/docs/commands/hcp/connect.mdx

Co-authored-by: Yoko Hyakuna <yoko@hashicorp.com>

* Update website/content/docs/commands/hcp/disconnect.mdx

Co-authored-by: Yoko Hyakuna <yoko@hashicorp.com>

* Update website/content/docs/commands/hcp/index.mdx

Co-authored-by: Sarah Chavis <62406755+schavis@users.noreply.github.com>

* Update website/content/docs/commands/hcp/connect.mdx

Co-authored-by: Sarah Chavis <62406755+schavis@users.noreply.github.com>

* Modify hcp tests

---------

Co-authored-by: Nick Cabatoff <ncabatoff@hashicorp.com>
Co-authored-by: Chris Capurso <1036769+ccapurso@users.noreply.github.com>
Co-authored-by: Sarah Chavis <62406755+schavis@users.noreply.github.com>
Co-authored-by: Yoko Hyakuna <yoko@hashicorp.com>
This commit is contained in:
Bianca Moreira
2024-01-09 15:29:30 +01:00
committed by GitHub
parent d27c06d3a1
commit e0216cab5b
16 changed files with 415 additions and 217 deletions

View File

@@ -82,6 +82,8 @@ const (
const (
EnvVaultAgentAddress = "VAULT_AGENT_ADDR"
EnvVaultInsecure = "VAULT_SKIP_VERIFY"
DefaultAddress = "https://127.0.0.1:8200"
)
// WrappingLookupFunc is a function that, given an HTTP verb and a path,
@@ -248,7 +250,7 @@ type TLSConfig struct {
// If an error is encountered, the Error field on the returned *Config will be populated with the specific error.
func DefaultConfig() *Config {
config := &Config{
Address: "https://127.0.0.1:8200",
Address: DefaultAddress,
HttpClient: cleanhttp.DefaultPooledClient(),
Timeout: time.Second * 60,
MinRetryWait: time.Millisecond * 1000,
@@ -589,6 +591,7 @@ type Client struct {
requestCallbacks []RequestCallback
responseCallbacks []ResponseCallback
replicationStateStore *replicationStateStore
hcpCookie *http.Cookie
}
// NewClient returns a new client for the given configuration.
@@ -1025,6 +1028,33 @@ func (c *Client) SetToken(v string) {
c.token = v
}
// HCPCookie returns the HCP cookie being used by this client. It will
// return an empty cookie when no cookie is set.
func (c *Client) HCPCookie() string {
c.modifyLock.RLock()
defer c.modifyLock.RUnlock()
if c.hcpCookie == nil {
return ""
}
return c.hcpCookie.String()
}
// SetHCPCookie sets the hcp cookie directly. This won't perform any auth
// verification, it simply sets the token properly for future requests.
func (c *Client) SetHCPCookie(v *http.Cookie) error {
c.modifyLock.Lock()
defer c.modifyLock.Unlock()
if err := v.Valid(); err != nil {
return err
}
c.hcpCookie = v
return nil
}
// ClearToken deletes the token if it is set or does nothing otherwise.
func (c *Client) ClearToken() {
c.modifyLock.Lock()
@@ -1299,6 +1329,8 @@ func (c *Client) NewRequest(method, requestPath string) *Request {
Params: make(map[string][]string),
}
req.HCPCookie = c.hcpCookie
var lookupPath string
switch {
case strings.HasPrefix(requestPath, "/v1/"):