diff --git a/api/auth_token.go b/api/auth_token.go index b75e839acecf..52be1e7852b9 100644 --- a/api/auth_token.go +++ b/api/auth_token.go @@ -2,6 +2,7 @@ package api import ( "context" + "net/http" ) // TokenAuth is used to perform token backend operations on Vault @@ -22,7 +23,7 @@ func (c *TokenAuth) CreateWithContext(ctx context.Context, opts *TokenCreateRequ ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("POST", "/v1/auth/token/create") + r := c.c.NewRequest(http.MethodPost, "/v1/auth/token/create") if err := r.SetJSONBody(opts); err != nil { return nil, err } @@ -44,7 +45,7 @@ func (c *TokenAuth) CreateOrphanWithContext(ctx context.Context, opts *TokenCrea ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("POST", "/v1/auth/token/create-orphan") + r := c.c.NewRequest(http.MethodPost, "/v1/auth/token/create-orphan") if err := r.SetJSONBody(opts); err != nil { return nil, err } @@ -66,7 +67,7 @@ func (c *TokenAuth) CreateWithRoleWithContext(ctx context.Context, opts *TokenCr ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("POST", "/v1/auth/token/create/"+roleName) + r := c.c.NewRequest(http.MethodPost, "/v1/auth/token/create/"+roleName) if err := r.SetJSONBody(opts); err != nil { return nil, err } @@ -88,7 +89,7 @@ func (c *TokenAuth) LookupWithContext(ctx context.Context, token string) (*Secre ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("POST", "/v1/auth/token/lookup") + r := c.c.NewRequest(http.MethodPost, "/v1/auth/token/lookup") if err := r.SetJSONBody(map[string]interface{}{ "token": token, }); err != nil { @@ -112,7 +113,7 @@ func (c *TokenAuth) LookupAccessorWithContext(ctx context.Context, accessor stri ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("POST", "/v1/auth/token/lookup-accessor") + r := c.c.NewRequest(http.MethodPost, "/v1/auth/token/lookup-accessor") if err := r.SetJSONBody(map[string]interface{}{ "accessor": accessor, }); err != nil { @@ -136,7 +137,7 @@ func (c *TokenAuth) LookupSelfWithContext(ctx context.Context) (*Secret, error) ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("GET", "/v1/auth/token/lookup-self") + r := c.c.NewRequest(http.MethodGet, "/v1/auth/token/lookup-self") resp, err := c.c.rawRequestWithContext(ctx, r) if err != nil { @@ -155,7 +156,7 @@ func (c *TokenAuth) RenewAccessorWithContext(ctx context.Context, accessor strin ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("POST", "/v1/auth/token/renew-accessor") + r := c.c.NewRequest(http.MethodPost, "/v1/auth/token/renew-accessor") if err := r.SetJSONBody(map[string]interface{}{ "accessor": accessor, "increment": increment, @@ -180,7 +181,7 @@ func (c *TokenAuth) RenewWithContext(ctx context.Context, token string, incremen ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("PUT", "/v1/auth/token/renew") + r := c.c.NewRequest(http.MethodPut, "/v1/auth/token/renew") if err := r.SetJSONBody(map[string]interface{}{ "token": token, "increment": increment, @@ -205,7 +206,7 @@ func (c *TokenAuth) RenewSelfWithContext(ctx context.Context, increment int) (*S ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("PUT", "/v1/auth/token/renew-self") + r := c.c.NewRequest(http.MethodPut, "/v1/auth/token/renew-self") body := map[string]interface{}{"increment": increment} if err := r.SetJSONBody(body); err != nil { @@ -232,7 +233,7 @@ func (c *TokenAuth) RenewTokenAsSelfWithContext(ctx context.Context, token strin ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("PUT", "/v1/auth/token/renew-self") + r := c.c.NewRequest(http.MethodPut, "/v1/auth/token/renew-self") r.ClientToken = token body := map[string]interface{}{"increment": increment} @@ -260,7 +261,7 @@ func (c *TokenAuth) RevokeAccessorWithContext(ctx context.Context, accessor stri ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("POST", "/v1/auth/token/revoke-accessor") + r := c.c.NewRequest(http.MethodPost, "/v1/auth/token/revoke-accessor") if err := r.SetJSONBody(map[string]interface{}{ "accessor": accessor, }); err != nil { @@ -287,7 +288,7 @@ func (c *TokenAuth) RevokeOrphanWithContext(ctx context.Context, token string) e ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("PUT", "/v1/auth/token/revoke-orphan") + r := c.c.NewRequest(http.MethodPut, "/v1/auth/token/revoke-orphan") if err := r.SetJSONBody(map[string]interface{}{ "token": token, }); err != nil { @@ -315,7 +316,7 @@ func (c *TokenAuth) RevokeSelfWithContext(ctx context.Context, token string) err ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("PUT", "/v1/auth/token/revoke-self") + r := c.c.NewRequest(http.MethodPut, "/v1/auth/token/revoke-self") resp, err := c.c.rawRequestWithContext(ctx, r) if err != nil { @@ -338,7 +339,7 @@ func (c *TokenAuth) RevokeTreeWithContext(ctx context.Context, token string) err ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("PUT", "/v1/auth/token/revoke") + r := c.c.NewRequest(http.MethodPut, "/v1/auth/token/revoke") if err := r.SetJSONBody(map[string]interface{}{ "token": token, }); err != nil { diff --git a/api/client_test.go b/api/client_test.go index 30c6cad9dec9..a8434b28c5bb 100644 --- a/api/client_test.go +++ b/api/client_test.go @@ -125,7 +125,7 @@ func TestClientHostHeader(t *testing.T) { // Set the token manually client.SetToken("foo") - resp, err := client.RawRequest(client.NewRequest("PUT", "/")) + resp, err := client.RawRequest(client.NewRequest(http.MethodPut, "/")) if err != nil { t.Fatal(err) } @@ -152,13 +152,13 @@ func TestClientBadToken(t *testing.T) { } client.SetToken("foo") - _, err = client.RawRequest(client.NewRequest("PUT", "/")) + _, err = client.RawRequest(client.NewRequest(http.MethodPut, "/")) if err != nil { t.Fatal(err) } client.SetToken("foo\u007f") - _, err = client.RawRequest(client.NewRequest("PUT", "/")) + _, err = client.RawRequest(client.NewRequest(http.MethodPut, "/")) if err == nil || !strings.Contains(err.Error(), "printable") { t.Fatalf("expected error due to bad token") } @@ -187,7 +187,7 @@ func TestClientRedirect(t *testing.T) { client.SetToken("foo") // Do a raw "/" request - resp, err := client.RawRequest(client.NewRequest("PUT", "/")) + resp, err := client.RawRequest(client.NewRequest(http.MethodPut, "/")) if err != nil { t.Fatalf("err: %s", err) } @@ -331,7 +331,7 @@ func TestClientEnvNamespace(t *testing.T) { t.Fatalf("err: %s", err) } - _, err = client.RawRequest(client.NewRequest("GET", "/")) + _, err = client.RawRequest(client.NewRequest(http.MethodGet, "/")) if err != nil { t.Fatalf("err: %s", err) } @@ -962,7 +962,7 @@ func TestClient_ReadYourWrites(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { testRequest := func(client *Client, val string) { - req := client.NewRequest("GET", "/"+val) + req := client.NewRequest(http.MethodGet, "/"+val) req.Headers.Set(HeaderIndex, val) resp, err := client.RawRequestWithContext(context.Background(), req) if err != nil { diff --git a/api/help.go b/api/help.go index bdc8eefc0e70..0988ebcd1fc9 100644 --- a/api/help.go +++ b/api/help.go @@ -3,6 +3,7 @@ package api import ( "context" "fmt" + "net/http" ) // Help wraps HelpWithContext using context.Background. @@ -15,7 +16,7 @@ func (c *Client) HelpWithContext(ctx context.Context, path string) (*Help, error ctx, cancelFunc := c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.NewRequest("GET", fmt.Sprintf("/v1/%s", path)) + r := c.NewRequest(http.MethodGet, fmt.Sprintf("/v1/%s", path)) r.Params.Add("help", "1") resp, err := c.rawRequestWithContext(ctx, r) diff --git a/api/logical.go b/api/logical.go index e352293082c0..39d61b96ab25 100644 --- a/api/logical.go +++ b/api/logical.go @@ -5,6 +5,7 @@ import ( "context" "fmt" "io" + "net/http" "net/url" "os" "strings" @@ -30,7 +31,7 @@ var ( return os.Getenv(EnvVaultWrapTTL) } - if (operation == "PUT" || operation == "POST") && path == "sys/wrapping/wrap" { + if (operation == http.MethodPut || operation == http.MethodPost) && path == "sys/wrapping/wrap" { return DefaultWrappingTTL } @@ -64,7 +65,7 @@ func (c *Logical) ReadWithDataWithContext(ctx context.Context, path string, data ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("GET", "/v1/"+path) + r := c.c.NewRequest(http.MethodGet, "/v1/"+path) var values url.Values for k, v := range data { @@ -116,7 +117,7 @@ func (c *Logical) ListWithContext(ctx context.Context, path string) (*Secret, er r := c.c.NewRequest("LIST", "/v1/"+path) // Set this for broader compatibility, but we use LIST above to be able to // handle the wrapping lookup function - r.Method = "GET" + r.Method = http.MethodGet r.Params.Set("list", "true") resp, err := c.c.rawRequestWithContext(ctx, r) @@ -149,7 +150,7 @@ func (c *Logical) Write(path string, data map[string]interface{}) (*Secret, erro } func (c *Logical) WriteWithContext(ctx context.Context, path string, data map[string]interface{}) (*Secret, error) { - r := c.c.NewRequest("PUT", "/v1/"+path) + r := c.c.NewRequest(http.MethodPut, "/v1/"+path) if err := r.SetJSONBody(data); err != nil { return nil, err } @@ -158,7 +159,7 @@ func (c *Logical) WriteWithContext(ctx context.Context, path string, data map[st } func (c *Logical) JSONMergePatch(ctx context.Context, path string, data map[string]interface{}) (*Secret, error) { - r := c.c.NewRequest("PATCH", "/v1/"+path) + r := c.c.NewRequest(http.MethodPatch, "/v1/"+path) r.Headers.Set("Content-Type", "application/merge-patch+json") if err := r.SetJSONBody(data); err != nil { return nil, err @@ -172,7 +173,7 @@ func (c *Logical) WriteBytes(path string, data []byte) (*Secret, error) { } func (c *Logical) WriteBytesWithContext(ctx context.Context, path string, data []byte) (*Secret, error) { - r := c.c.NewRequest("PUT", "/v1/"+path) + r := c.c.NewRequest(http.MethodPut, "/v1/"+path) r.BodyBytes = data return c.write(ctx, path, r) @@ -222,7 +223,7 @@ func (c *Logical) DeleteWithDataWithContext(ctx context.Context, path string, da ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("DELETE", "/v1/"+path) + r := c.c.NewRequest(http.MethodDelete, "/v1/"+path) var values url.Values for k, v := range data { @@ -282,7 +283,7 @@ func (c *Logical) UnwrapWithContext(ctx context.Context, wrappingToken string) ( } } - r := c.c.NewRequest("PUT", "/v1/sys/wrapping/unwrap") + r := c.c.NewRequest(http.MethodPut, "/v1/sys/wrapping/unwrap") if err := r.SetJSONBody(data); err != nil { return nil, err } diff --git a/api/output_string.go b/api/output_string.go index b30c06eeeddc..9129ea0c3f77 100644 --- a/api/output_string.go +++ b/api/output_string.go @@ -2,6 +2,7 @@ package api import ( "fmt" + "net/http" "strings" retryablehttp "github.com/hashicorp/go-retryablehttp" @@ -45,7 +46,7 @@ func (d *OutputStringError) parseRequest() { if d.TLSSkipVerify { d.parsedCurlString += "--insecure " } - if d.Request.Method != "GET" { + if d.Request.Method != http.MethodGet { d.parsedCurlString = fmt.Sprintf("%s-X %s ", d.parsedCurlString, d.Request.Method) } if d.ClientCACert != "" { diff --git a/api/ssh.go b/api/ssh.go index 465c26d8aa7b..b832e2748290 100644 --- a/api/ssh.go +++ b/api/ssh.go @@ -3,6 +3,7 @@ package api import ( "context" "fmt" + "net/http" ) // SSH is used to return a client to invoke operations on SSH backend. @@ -34,7 +35,7 @@ func (c *SSH) CredentialWithContext(ctx context.Context, role string, data map[s ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("PUT", fmt.Sprintf("/v1/%s/creds/%s", c.MountPoint, role)) + r := c.c.NewRequest(http.MethodPut, fmt.Sprintf("/v1/%s/creds/%s", c.MountPoint, role)) if err := r.SetJSONBody(data); err != nil { return nil, err } @@ -59,7 +60,7 @@ func (c *SSH) SignKeyWithContext(ctx context.Context, role string, data map[stri ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("PUT", fmt.Sprintf("/v1/%s/sign/%s", c.MountPoint, role)) + r := c.c.NewRequest(http.MethodPut, fmt.Sprintf("/v1/%s/sign/%s", c.MountPoint, role)) if err := r.SetJSONBody(data); err != nil { return nil, err } diff --git a/api/ssh_agent.go b/api/ssh_agent.go index 04e02b3f58c5..505519b04e7c 100644 --- a/api/ssh_agent.go +++ b/api/ssh_agent.go @@ -6,6 +6,7 @@ import ( "crypto/x509" "fmt" "io/ioutil" + "net/http" "os" "github.com/hashicorp/errwrap" @@ -218,7 +219,7 @@ func (c *SSHHelper) VerifyWithContext(ctx context.Context, otp string) (*SSHVeri "otp": otp, } verifyPath := fmt.Sprintf("/v1/%s/verify", c.MountPoint) - r := c.c.NewRequest("PUT", verifyPath) + r := c.c.NewRequest(http.MethodPut, verifyPath) if err := r.SetJSONBody(data); err != nil { return nil, err } diff --git a/api/sys_audit.go b/api/sys_audit.go index c2542de60534..7020256f4100 100644 --- a/api/sys_audit.go +++ b/api/sys_audit.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "net/http" "github.com/mitchellh/mapstructure" ) @@ -20,7 +21,7 @@ func (c *Sys) AuditHashWithContext(ctx context.Context, path string, input strin "input": input, } - r := c.c.NewRequest("PUT", fmt.Sprintf("/v1/sys/audit-hash/%s", path)) + r := c.c.NewRequest(http.MethodPut, fmt.Sprintf("/v1/sys/audit-hash/%s", path)) if err := r.SetJSONBody(body); err != nil { return "", err } @@ -59,7 +60,7 @@ func (c *Sys) ListAuditWithContext(ctx context.Context) (map[string]*Audit, erro ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("GET", "/v1/sys/audit") + r := c.c.NewRequest(http.MethodGet, "/v1/sys/audit") resp, err := c.c.rawRequestWithContext(ctx, r) if err != nil { @@ -102,7 +103,7 @@ func (c *Sys) EnableAuditWithOptionsWithContext(ctx context.Context, path string ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("PUT", fmt.Sprintf("/v1/sys/audit/%s", path)) + r := c.c.NewRequest(http.MethodPut, fmt.Sprintf("/v1/sys/audit/%s", path)) if err := r.SetJSONBody(options); err != nil { return err } @@ -124,7 +125,7 @@ func (c *Sys) DisableAuditWithContext(ctx context.Context, path string) error { ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("DELETE", fmt.Sprintf("/v1/sys/audit/%s", path)) + r := c.c.NewRequest(http.MethodDelete, fmt.Sprintf("/v1/sys/audit/%s", path)) resp, err := c.c.rawRequestWithContext(ctx, r) diff --git a/api/sys_auth.go b/api/sys_auth.go index dc348127b4e7..238bd5e468a0 100644 --- a/api/sys_auth.go +++ b/api/sys_auth.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "net/http" "github.com/mitchellh/mapstructure" ) @@ -16,7 +17,7 @@ func (c *Sys) ListAuthWithContext(ctx context.Context) (map[string]*AuthMount, e ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("GET", "/v1/sys/auth") + r := c.c.NewRequest(http.MethodGet, "/v1/sys/auth") resp, err := c.c.rawRequestWithContext(ctx, r) if err != nil { @@ -57,7 +58,7 @@ func (c *Sys) EnableAuthWithOptionsWithContext(ctx context.Context, path string, ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("POST", fmt.Sprintf("/v1/sys/auth/%s", path)) + r := c.c.NewRequest(http.MethodPost, fmt.Sprintf("/v1/sys/auth/%s", path)) if err := r.SetJSONBody(options); err != nil { return err } @@ -79,7 +80,7 @@ func (c *Sys) DisableAuthWithContext(ctx context.Context, path string) error { ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("DELETE", fmt.Sprintf("/v1/sys/auth/%s", path)) + r := c.c.NewRequest(http.MethodDelete, fmt.Sprintf("/v1/sys/auth/%s", path)) resp, err := c.c.rawRequestWithContext(ctx, r) if err == nil { diff --git a/api/sys_capabilities.go b/api/sys_capabilities.go index 328bf5abcb0b..af306a07f312 100644 --- a/api/sys_capabilities.go +++ b/api/sys_capabilities.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "net/http" "github.com/mitchellh/mapstructure" ) @@ -37,7 +38,7 @@ func (c *Sys) CapabilitiesWithContext(ctx context.Context, token, path string) ( reqPath = fmt.Sprintf("%s-self", reqPath) } - r := c.c.NewRequest("POST", reqPath) + r := c.c.NewRequest(http.MethodPost, reqPath) if err := r.SetJSONBody(body); err != nil { return nil, err } diff --git a/api/sys_config_cors.go b/api/sys_config_cors.go index d9aad606a196..1e2cda4f48cb 100644 --- a/api/sys_config_cors.go +++ b/api/sys_config_cors.go @@ -3,6 +3,7 @@ package api import ( "context" "errors" + "net/http" "github.com/mitchellh/mapstructure" ) @@ -15,7 +16,7 @@ func (c *Sys) CORSStatusWithContext(ctx context.Context) (*CORSResponse, error) ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("GET", "/v1/sys/config/cors") + r := c.c.NewRequest(http.MethodGet, "/v1/sys/config/cors") resp, err := c.c.rawRequestWithContext(ctx, r) if err != nil { @@ -48,7 +49,7 @@ func (c *Sys) ConfigureCORSWithContext(ctx context.Context, req *CORSRequest) er ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("PUT", "/v1/sys/config/cors") + r := c.c.NewRequest(http.MethodPut, "/v1/sys/config/cors") if err := r.SetJSONBody(req); err != nil { return err } @@ -68,7 +69,7 @@ func (c *Sys) DisableCORSWithContext(ctx context.Context) error { ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("DELETE", "/v1/sys/config/cors") + r := c.c.NewRequest(http.MethodDelete, "/v1/sys/config/cors") resp, err := c.c.rawRequestWithContext(ctx, r) if err == nil { diff --git a/api/sys_generate_root.go b/api/sys_generate_root.go index e23b491c743f..096cadb793d9 100644 --- a/api/sys_generate_root.go +++ b/api/sys_generate_root.go @@ -1,6 +1,9 @@ package api -import "context" +import ( + "context" + "net/http" +) func (c *Sys) GenerateRootStatus() (*GenerateRootStatusResponse, error) { return c.GenerateRootStatusWithContext(context.Background()) @@ -30,7 +33,7 @@ func (c *Sys) generateRootStatusCommonWithContext(ctx context.Context, path stri ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("GET", path) + r := c.c.NewRequest(http.MethodGet, path) resp, err := c.c.rawRequestWithContext(ctx, r) if err != nil { @@ -76,7 +79,7 @@ func (c *Sys) generateRootInitCommonWithContext(ctx context.Context, path, otp, "pgp_key": pgpKey, } - r := c.c.NewRequest("PUT", path) + r := c.c.NewRequest(http.MethodPut, path) if err := r.SetJSONBody(body); err != nil { return nil, err } @@ -120,7 +123,7 @@ func (c *Sys) generateRootCancelCommonWithContext(ctx context.Context, path stri ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("DELETE", path) + r := c.c.NewRequest(http.MethodDelete, path) resp, err := c.c.rawRequestWithContext(ctx, r) if err == nil { @@ -162,7 +165,7 @@ func (c *Sys) generateRootUpdateCommonWithContext(ctx context.Context, path, sha "nonce": nonce, } - r := c.c.NewRequest("PUT", path) + r := c.c.NewRequest(http.MethodPut, path) if err := r.SetJSONBody(body); err != nil { return nil, err } diff --git a/api/sys_hastatus.go b/api/sys_hastatus.go index fb12a51adba8..35bf40336651 100644 --- a/api/sys_hastatus.go +++ b/api/sys_hastatus.go @@ -2,6 +2,7 @@ package api import ( "context" + "net/http" "time" ) @@ -13,7 +14,7 @@ func (c *Sys) HAStatusWithContext(ctx context.Context) (*HAStatusResponse, error ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("GET", "/v1/sys/ha-status") + r := c.c.NewRequest(http.MethodGet, "/v1/sys/ha-status") resp, err := c.c.rawRequestWithContext(ctx, r) if err != nil { diff --git a/api/sys_health.go b/api/sys_health.go index a49c2db1f976..953c1c21eaa3 100644 --- a/api/sys_health.go +++ b/api/sys_health.go @@ -1,6 +1,9 @@ package api -import "context" +import ( + "context" + "net/http" +) func (c *Sys) Health() (*HealthResponse, error) { return c.HealthWithContext(context.Background()) @@ -10,7 +13,7 @@ func (c *Sys) HealthWithContext(ctx context.Context) (*HealthResponse, error) { ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("GET", "/v1/sys/health") + r := c.c.NewRequest(http.MethodGet, "/v1/sys/health") // If the code is 400 or above it will automatically turn into an error, // but the sys/health API defaults to returning 5xx when not sealed or // inited, so we force this code to be something else so we parse correctly diff --git a/api/sys_init.go b/api/sys_init.go index e373ffc5c7da..05dea86f6ab5 100644 --- a/api/sys_init.go +++ b/api/sys_init.go @@ -1,6 +1,9 @@ package api -import "context" +import ( + "context" + "net/http" +) func (c *Sys) InitStatus() (bool, error) { return c.InitStatusWithContext(context.Background()) @@ -10,7 +13,7 @@ func (c *Sys) InitStatusWithContext(ctx context.Context) (bool, error) { ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("GET", "/v1/sys/init") + r := c.c.NewRequest(http.MethodGet, "/v1/sys/init") resp, err := c.c.rawRequestWithContext(ctx, r) if err != nil { @@ -31,7 +34,7 @@ func (c *Sys) InitWithContext(ctx context.Context, opts *InitRequest) (*InitResp ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("PUT", "/v1/sys/init") + r := c.c.NewRequest(http.MethodPut, "/v1/sys/init") if err := r.SetJSONBody(opts); err != nil { return nil, err } diff --git a/api/sys_leader.go b/api/sys_leader.go index 824ede5a2d00..a74e206ebed4 100644 --- a/api/sys_leader.go +++ b/api/sys_leader.go @@ -2,6 +2,7 @@ package api import ( "context" + "net/http" "time" ) @@ -13,7 +14,7 @@ func (c *Sys) LeaderWithContext(ctx context.Context) (*LeaderResponse, error) { ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("GET", "/v1/sys/leader") + r := c.c.NewRequest(http.MethodGet, "/v1/sys/leader") resp, err := c.c.rawRequestWithContext(ctx, r) if err != nil { diff --git a/api/sys_leases.go b/api/sys_leases.go index 9e098b4b0a2e..c02402f5314c 100644 --- a/api/sys_leases.go +++ b/api/sys_leases.go @@ -3,6 +3,7 @@ package api import ( "context" "errors" + "net/http" ) func (c *Sys) Renew(id string, increment int) (*Secret, error) { @@ -13,7 +14,7 @@ func (c *Sys) RenewWithContext(ctx context.Context, id string, increment int) (* ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("PUT", "/v1/sys/leases/renew") + r := c.c.NewRequest(http.MethodPut, "/v1/sys/leases/renew") body := map[string]interface{}{ "increment": increment, @@ -40,7 +41,7 @@ func (c *Sys) LookupWithContext(ctx context.Context, id string) (*Secret, error) ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("PUT", "/v1/sys/leases/lookup") + r := c.c.NewRequest(http.MethodPut, "/v1/sys/leases/lookup") body := map[string]interface{}{ "lease_id": id, @@ -66,7 +67,7 @@ func (c *Sys) RevokeWithContext(ctx context.Context, id string) error { ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("PUT", "/v1/sys/leases/revoke") + r := c.c.NewRequest(http.MethodPut, "/v1/sys/leases/revoke") body := map[string]interface{}{ "lease_id": id, } @@ -89,7 +90,7 @@ func (c *Sys) RevokePrefixWithContext(ctx context.Context, id string) error { ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("PUT", "/v1/sys/leases/revoke-prefix/"+id) + r := c.c.NewRequest(http.MethodPut, "/v1/sys/leases/revoke-prefix/"+id) resp, err := c.c.rawRequestWithContext(ctx, r) if err == nil { @@ -106,7 +107,7 @@ func (c *Sys) RevokeForceWithContext(ctx context.Context, id string) error { ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("PUT", "/v1/sys/leases/revoke-force/"+id) + r := c.c.NewRequest(http.MethodPut, "/v1/sys/leases/revoke-force/"+id) resp, err := c.c.rawRequestWithContext(ctx, r) if err == nil { @@ -137,7 +138,7 @@ func (c *Sys) RevokeWithOptionsWithContext(ctx context.Context, opts *RevokeOpti } path += opts.LeaseID - r := c.c.NewRequest("PUT", path) + r := c.c.NewRequest(http.MethodPut, path) if !opts.Force { body := map[string]interface{}{ "sync": opts.Sync, diff --git a/api/sys_monitor.go b/api/sys_monitor.go index ec27f228559e..df27746728a3 100644 --- a/api/sys_monitor.go +++ b/api/sys_monitor.go @@ -4,12 +4,13 @@ import ( "bufio" "context" "fmt" + "net/http" ) // Monitor returns a channel that outputs strings containing the log messages // coming from the server. func (c *Sys) Monitor(ctx context.Context, logLevel string) (chan string, error) { - r := c.c.NewRequest("GET", "/v1/sys/monitor") + r := c.c.NewRequest(http.MethodGet, "/v1/sys/monitor") if logLevel == "" { r.Params.Add("log_level", "info") diff --git a/api/sys_mounts.go b/api/sys_mounts.go index 35321a2ce463..52f51139f77b 100644 --- a/api/sys_mounts.go +++ b/api/sys_mounts.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "net/http" "time" "github.com/mitchellh/mapstructure" @@ -17,7 +18,7 @@ func (c *Sys) ListMountsWithContext(ctx context.Context) (map[string]*MountOutpu ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("GET", "/v1/sys/mounts") + r := c.c.NewRequest(http.MethodGet, "/v1/sys/mounts") resp, err := c.c.rawRequestWithContext(ctx, r) if err != nil { @@ -50,7 +51,7 @@ func (c *Sys) MountWithContext(ctx context.Context, path string, mountInfo *Moun ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("POST", fmt.Sprintf("/v1/sys/mounts/%s", path)) + r := c.c.NewRequest(http.MethodPost, fmt.Sprintf("/v1/sys/mounts/%s", path)) if err := r.SetJSONBody(mountInfo); err != nil { return err } @@ -72,7 +73,7 @@ func (c *Sys) UnmountWithContext(ctx context.Context, path string) error { ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("DELETE", fmt.Sprintf("/v1/sys/mounts/%s", path)) + r := c.c.NewRequest(http.MethodDelete, fmt.Sprintf("/v1/sys/mounts/%s", path)) resp, err := c.c.rawRequestWithContext(ctx, r) if err == nil { @@ -124,7 +125,7 @@ func (c *Sys) StartRemountWithContext(ctx context.Context, from, to string) (*Mo "to": to, } - r := c.c.NewRequest("POST", "/v1/sys/remount") + r := c.c.NewRequest(http.MethodPost, "/v1/sys/remount") if err := r.SetJSONBody(body); err != nil { return nil, err } @@ -161,7 +162,7 @@ func (c *Sys) RemountStatusWithContext(ctx context.Context, migrationID string) ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("GET", fmt.Sprintf("/v1/sys/remount/status/%s", migrationID)) + r := c.c.NewRequest(http.MethodGet, fmt.Sprintf("/v1/sys/remount/status/%s", migrationID)) resp, err := c.c.rawRequestWithContext(ctx, r) if err != nil { @@ -193,7 +194,7 @@ func (c *Sys) TuneMountWithContext(ctx context.Context, path string, config Moun ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("POST", fmt.Sprintf("/v1/sys/mounts/%s/tune", path)) + r := c.c.NewRequest(http.MethodPost, fmt.Sprintf("/v1/sys/mounts/%s/tune", path)) if err := r.SetJSONBody(config); err != nil { return err } @@ -213,7 +214,7 @@ func (c *Sys) MountConfigWithContext(ctx context.Context, path string) (*MountCo ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("GET", fmt.Sprintf("/v1/sys/mounts/%s/tune", path)) + r := c.c.NewRequest(http.MethodGet, fmt.Sprintf("/v1/sys/mounts/%s/tune", path)) resp, err := c.c.rawRequestWithContext(ctx, r) if err != nil { diff --git a/api/sys_plugins.go b/api/sys_plugins.go index 8305f51d7d62..920af4c3cbab 100644 --- a/api/sys_plugins.go +++ b/api/sys_plugins.go @@ -44,7 +44,7 @@ func (c *Sys) ListPluginsWithContext(ctx context.Context, i *ListPluginsInput) ( method := "" if i.Type == consts.PluginTypeUnknown { path = "/v1/sys/plugins/catalog" - method = "GET" + method = http.MethodGet } else { path = fmt.Sprintf("/v1/sys/plugins/catalog/%s", i.Type) method = "LIST" @@ -54,7 +54,7 @@ func (c *Sys) ListPluginsWithContext(ctx context.Context, i *ListPluginsInput) ( if method == "LIST" { // Set this for broader compatibility, but we use LIST above to be able // to handle the wrapping lookup function - req.Method = "GET" + req.Method = http.MethodGet req.Params.Set("list", "true") } diff --git a/api/sys_policy.go b/api/sys_policy.go index aaa80d758d1a..4a4f91b08c71 100644 --- a/api/sys_policy.go +++ b/api/sys_policy.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "net/http" "github.com/mitchellh/mapstructure" ) @@ -19,7 +20,7 @@ func (c *Sys) ListPoliciesWithContext(ctx context.Context) ([]string, error) { r := c.c.NewRequest("LIST", "/v1/sys/policies/acl") // Set this for broader compatibility, but we use LIST above to be able to // handle the wrapping lookup function - r.Method = "GET" + r.Method = http.MethodGet r.Params.Set("list", "true") resp, err := c.c.rawRequestWithContext(ctx, r) @@ -53,7 +54,7 @@ func (c *Sys) GetPolicyWithContext(ctx context.Context, name string) (string, er ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("GET", fmt.Sprintf("/v1/sys/policies/acl/%s", name)) + r := c.c.NewRequest(http.MethodGet, fmt.Sprintf("/v1/sys/policies/acl/%s", name)) resp, err := c.c.rawRequestWithContext(ctx, r) if resp != nil { @@ -93,7 +94,7 @@ func (c *Sys) PutPolicyWithContext(ctx context.Context, name, rules string) erro "policy": rules, } - r := c.c.NewRequest("PUT", fmt.Sprintf("/v1/sys/policies/acl/%s", name)) + r := c.c.NewRequest(http.MethodPut, fmt.Sprintf("/v1/sys/policies/acl/%s", name)) if err := r.SetJSONBody(body); err != nil { return err } @@ -115,7 +116,7 @@ func (c *Sys) DeletePolicyWithContext(ctx context.Context, name string) error { ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("DELETE", fmt.Sprintf("/v1/sys/policies/acl/%s", name)) + r := c.c.NewRequest(http.MethodDelete, fmt.Sprintf("/v1/sys/policies/acl/%s", name)) resp, err := c.c.rawRequestWithContext(ctx, r) if err == nil { diff --git a/api/sys_raft.go b/api/sys_raft.go index c512284b3f7d..df10bf672e05 100644 --- a/api/sys_raft.go +++ b/api/sys_raft.go @@ -119,7 +119,7 @@ func (c *Sys) RaftJoinWithContext(ctx context.Context, opts *RaftJoinRequest) (* ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("POST", "/v1/sys/storage/raft/join") + r := c.c.NewRequest(http.MethodPost, "/v1/sys/storage/raft/join") if err := r.SetJSONBody(opts); err != nil { return nil, err @@ -144,7 +144,7 @@ func (c *Sys) RaftSnapshot(snapWriter io.Writer) error { // RaftSnapshotWithContext invokes the API that takes the snapshot of the raft cluster and // writes it to the supplied io.Writer. func (c *Sys) RaftSnapshotWithContext(ctx context.Context, snapWriter io.Writer) error { - r := c.c.NewRequest("GET", "/v1/sys/storage/raft/snapshot") + r := c.c.NewRequest(http.MethodGet, "/v1/sys/storage/raft/snapshot") r.URL.RawQuery = r.Params.Encode() resp, err := c.c.httpRequestWithContext(ctx, r) @@ -245,7 +245,7 @@ func (c *Sys) RaftAutopilotStateWithContext(ctx context.Context) (*AutopilotStat ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("GET", "/v1/sys/storage/raft/autopilot/state") + r := c.c.NewRequest(http.MethodGet, "/v1/sys/storage/raft/autopilot/state") resp, err := c.c.rawRequestWithContext(ctx, r) if resp != nil { @@ -285,7 +285,7 @@ func (c *Sys) RaftAutopilotConfigurationWithContext(ctx context.Context) (*Autop ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("GET", "/v1/sys/storage/raft/autopilot/configuration") + r := c.c.NewRequest(http.MethodGet, "/v1/sys/storage/raft/autopilot/configuration") resp, err := c.c.rawRequestWithContext(ctx, r) if resp != nil { @@ -333,7 +333,7 @@ func (c *Sys) PutRaftAutopilotConfigurationWithContext(ctx context.Context, opts ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("POST", "/v1/sys/storage/raft/autopilot/configuration") + r := c.c.NewRequest(http.MethodPost, "/v1/sys/storage/raft/autopilot/configuration") if err := r.SetJSONBody(opts); err != nil { return err diff --git a/api/sys_rekey.go b/api/sys_rekey.go index 06bb3047f1bc..2ac8a4743bcf 100644 --- a/api/sys_rekey.go +++ b/api/sys_rekey.go @@ -3,6 +3,7 @@ package api import ( "context" "errors" + "net/http" "github.com/mitchellh/mapstructure" ) @@ -15,7 +16,7 @@ func (c *Sys) RekeyStatusWithContext(ctx context.Context) (*RekeyStatusResponse, ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("GET", "/v1/sys/rekey/init") + r := c.c.NewRequest(http.MethodGet, "/v1/sys/rekey/init") resp, err := c.c.rawRequestWithContext(ctx, r) if err != nil { @@ -36,7 +37,7 @@ func (c *Sys) RekeyRecoveryKeyStatusWithContext(ctx context.Context) (*RekeyStat ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("GET", "/v1/sys/rekey-recovery-key/init") + r := c.c.NewRequest(http.MethodGet, "/v1/sys/rekey-recovery-key/init") resp, err := c.c.rawRequestWithContext(ctx, r) if err != nil { @@ -57,7 +58,7 @@ func (c *Sys) RekeyVerificationStatusWithContext(ctx context.Context) (*RekeyVer ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("GET", "/v1/sys/rekey/verify") + r := c.c.NewRequest(http.MethodGet, "/v1/sys/rekey/verify") resp, err := c.c.rawRequestWithContext(ctx, r) if err != nil { @@ -78,7 +79,7 @@ func (c *Sys) RekeyRecoveryKeyVerificationStatusWithContext(ctx context.Context) ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("GET", "/v1/sys/rekey-recovery-key/verify") + r := c.c.NewRequest(http.MethodGet, "/v1/sys/rekey-recovery-key/verify") resp, err := c.c.rawRequestWithContext(ctx, r) if err != nil { @@ -99,7 +100,7 @@ func (c *Sys) RekeyInitWithContext(ctx context.Context, config *RekeyInitRequest ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("PUT", "/v1/sys/rekey/init") + r := c.c.NewRequest(http.MethodPut, "/v1/sys/rekey/init") if err := r.SetJSONBody(config); err != nil { return nil, err } @@ -123,7 +124,7 @@ func (c *Sys) RekeyRecoveryKeyInitWithContext(ctx context.Context, config *Rekey ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("PUT", "/v1/sys/rekey-recovery-key/init") + r := c.c.NewRequest(http.MethodPut, "/v1/sys/rekey-recovery-key/init") if err := r.SetJSONBody(config); err != nil { return nil, err } @@ -147,7 +148,7 @@ func (c *Sys) RekeyCancelWithContext(ctx context.Context) error { ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("DELETE", "/v1/sys/rekey/init") + r := c.c.NewRequest(http.MethodDelete, "/v1/sys/rekey/init") resp, err := c.c.rawRequestWithContext(ctx, r) if err == nil { @@ -164,7 +165,7 @@ func (c *Sys) RekeyRecoveryKeyCancelWithContext(ctx context.Context) error { ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("DELETE", "/v1/sys/rekey-recovery-key/init") + r := c.c.NewRequest(http.MethodDelete, "/v1/sys/rekey-recovery-key/init") resp, err := c.c.rawRequestWithContext(ctx, r) if err == nil { @@ -181,7 +182,7 @@ func (c *Sys) RekeyVerificationCancelWithContext(ctx context.Context) error { ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("DELETE", "/v1/sys/rekey/verify") + r := c.c.NewRequest(http.MethodDelete, "/v1/sys/rekey/verify") resp, err := c.c.rawRequestWithContext(ctx, r) if err == nil { @@ -198,7 +199,7 @@ func (c *Sys) RekeyRecoveryKeyVerificationCancelWithContext(ctx context.Context) ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("DELETE", "/v1/sys/rekey-recovery-key/verify") + r := c.c.NewRequest(http.MethodDelete, "/v1/sys/rekey-recovery-key/verify") resp, err := c.c.rawRequestWithContext(ctx, r) if err == nil { @@ -220,7 +221,7 @@ func (c *Sys) RekeyUpdateWithContext(ctx context.Context, shard, nonce string) ( "nonce": nonce, } - r := c.c.NewRequest("PUT", "/v1/sys/rekey/update") + r := c.c.NewRequest(http.MethodPut, "/v1/sys/rekey/update") if err := r.SetJSONBody(body); err != nil { return nil, err } @@ -249,7 +250,7 @@ func (c *Sys) RekeyRecoveryKeyUpdateWithContext(ctx context.Context, shard, nonc "nonce": nonce, } - r := c.c.NewRequest("PUT", "/v1/sys/rekey-recovery-key/update") + r := c.c.NewRequest(http.MethodPut, "/v1/sys/rekey-recovery-key/update") if err := r.SetJSONBody(body); err != nil { return nil, err } @@ -273,7 +274,7 @@ func (c *Sys) RekeyRetrieveBackupWithContext(ctx context.Context) (*RekeyRetriev ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("GET", "/v1/sys/rekey/backup") + r := c.c.NewRequest(http.MethodGet, "/v1/sys/rekey/backup") resp, err := c.c.rawRequestWithContext(ctx, r) if err != nil { @@ -306,7 +307,7 @@ func (c *Sys) RekeyRetrieveRecoveryBackupWithContext(ctx context.Context) (*Reke ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("GET", "/v1/sys/rekey/recovery-key-backup") + r := c.c.NewRequest(http.MethodGet, "/v1/sys/rekey/recovery-key-backup") resp, err := c.c.rawRequestWithContext(ctx, r) if err != nil { @@ -339,7 +340,7 @@ func (c *Sys) RekeyDeleteBackupWithContext(ctx context.Context) error { ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("DELETE", "/v1/sys/rekey/backup") + r := c.c.NewRequest(http.MethodDelete, "/v1/sys/rekey/backup") resp, err := c.c.rawRequestWithContext(ctx, r) if err == nil { @@ -357,7 +358,7 @@ func (c *Sys) RekeyDeleteRecoveryBackupWithContext(ctx context.Context) error { ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("DELETE", "/v1/sys/rekey/recovery-key-backup") + r := c.c.NewRequest(http.MethodDelete, "/v1/sys/rekey/recovery-key-backup") resp, err := c.c.rawRequestWithContext(ctx, r) if err == nil { @@ -380,7 +381,7 @@ func (c *Sys) RekeyVerificationUpdateWithContext(ctx context.Context, shard, non "nonce": nonce, } - r := c.c.NewRequest("PUT", "/v1/sys/rekey/verify") + r := c.c.NewRequest(http.MethodPut, "/v1/sys/rekey/verify") if err := r.SetJSONBody(body); err != nil { return nil, err } @@ -409,7 +410,7 @@ func (c *Sys) RekeyRecoveryKeyVerificationUpdateWithContext(ctx context.Context, "nonce": nonce, } - r := c.c.NewRequest("PUT", "/v1/sys/rekey-recovery-key/verify") + r := c.c.NewRequest(http.MethodPut, "/v1/sys/rekey-recovery-key/verify") if err := r.SetJSONBody(body); err != nil { return nil, err } diff --git a/api/sys_rotate.go b/api/sys_rotate.go index dc0140f0c9d9..fa86886c35b8 100644 --- a/api/sys_rotate.go +++ b/api/sys_rotate.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "errors" + "net/http" "time" ) @@ -15,7 +16,7 @@ func (c *Sys) RotateWithContext(ctx context.Context) error { ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("POST", "/v1/sys/rotate") + r := c.c.NewRequest(http.MethodPost, "/v1/sys/rotate") resp, err := c.c.rawRequestWithContext(ctx, r) if err == nil { @@ -32,7 +33,7 @@ func (c *Sys) KeyStatusWithContext(ctx context.Context) (*KeyStatus, error) { ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("GET", "/v1/sys/key-status") + r := c.c.NewRequest(http.MethodGet, "/v1/sys/key-status") resp, err := c.c.rawRequestWithContext(ctx, r) if err != nil { diff --git a/api/sys_seal.go b/api/sys_seal.go index f57e19ea1b38..dcd8d32a5b26 100644 --- a/api/sys_seal.go +++ b/api/sys_seal.go @@ -1,13 +1,16 @@ package api -import "context" +import ( + "context" + "net/http" +) func (c *Sys) SealStatus() (*SealStatusResponse, error) { return c.SealStatusWithContext(context.Background()) } func (c *Sys) SealStatusWithContext(ctx context.Context) (*SealStatusResponse, error) { - r := c.c.NewRequest("GET", "/v1/sys/seal-status") + r := c.c.NewRequest(http.MethodGet, "/v1/sys/seal-status") return sealStatusRequestWithContext(ctx, c, r) } @@ -19,7 +22,7 @@ func (c *Sys) SealWithContext(ctx context.Context) error { ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("PUT", "/v1/sys/seal") + r := c.c.NewRequest(http.MethodPut, "/v1/sys/seal") resp, err := c.c.rawRequestWithContext(ctx, r) if err != nil { @@ -37,7 +40,7 @@ func (c *Sys) ResetUnsealProcess() (*SealStatusResponse, error) { func (c *Sys) ResetUnsealProcessWithContext(ctx context.Context) (*SealStatusResponse, error) { body := map[string]interface{}{"reset": true} - r := c.c.NewRequest("PUT", "/v1/sys/unseal") + r := c.c.NewRequest(http.MethodPut, "/v1/sys/unseal") if err := r.SetJSONBody(body); err != nil { return nil, err } @@ -52,7 +55,7 @@ func (c *Sys) Unseal(shard string) (*SealStatusResponse, error) { func (c *Sys) UnsealWithContext(ctx context.Context, shard string) (*SealStatusResponse, error) { body := map[string]interface{}{"key": shard} - r := c.c.NewRequest("PUT", "/v1/sys/unseal") + r := c.c.NewRequest(http.MethodPut, "/v1/sys/unseal") if err := r.SetJSONBody(body); err != nil { return nil, err } @@ -65,7 +68,7 @@ func (c *Sys) UnsealWithOptions(opts *UnsealOpts) (*SealStatusResponse, error) { } func (c *Sys) UnsealWithOptionsWithContext(ctx context.Context, opts *UnsealOpts) (*SealStatusResponse, error) { - r := c.c.NewRequest("PUT", "/v1/sys/unseal") + r := c.c.NewRequest(http.MethodPut, "/v1/sys/unseal") if err := r.SetJSONBody(opts); err != nil { return nil, err diff --git a/api/sys_stepdown.go b/api/sys_stepdown.go index 2ef681e9fedf..833f31a6f760 100644 --- a/api/sys_stepdown.go +++ b/api/sys_stepdown.go @@ -1,6 +1,9 @@ package api -import "context" +import ( + "context" + "net/http" +) func (c *Sys) StepDown() error { return c.StepDownWithContext(context.Background()) @@ -10,7 +13,7 @@ func (c *Sys) StepDownWithContext(ctx context.Context) error { ctx, cancelFunc := c.c.withConfiguredTimeout(ctx) defer cancelFunc() - r := c.c.NewRequest("PUT", "/v1/sys/step-down") + r := c.c.NewRequest(http.MethodPut, "/v1/sys/step-down") resp, err := c.c.rawRequestWithContext(ctx, r) if resp != nil && resp.Body != nil {