Commit Graph

70 Commits

Author SHA1 Message Date
Seth Hoenig
e2ab16847d deps: adjust to gzip handler zero length response body
After swapping gzip handler to use the gorilla library, we
must account for a quirk in how zero/minimal length response
bodies are delivered.

The previous gzip handler was configured to compress all responses
regardless of size - even if the data was zero length or below the
network MTU. This behavior changed in [v1.1.0](c551b6c3b4 (diff-de723e6602cc2f16f7a9d85fd89d69954edc12a49134dab8901b10ee06d1879d))
which is why we could not upgrade.

The Nomad HTTP Client mutates the http.Response.Body object, making
a strong assumption that if the Content-Encoding header is set to "gzip",
the response will be readable via gzip decoder. This is no longer true
for the nytimes gzip handler, and is also not true for the gorilla gzip
handler.

It seems in practice this only makes a difference on the /v1/operator/license
endpoint which returns an empty response in OSS Nomad.

The fix here is to simply not wrap the response body reader if we
encounter an io.EOF while creating the gzip reader - indicating there
is no data to decode.
2022-01-19 11:52:19 -06:00
Tim Gross
972708aaed evaluations list pagination and filtering (#11648)
API queries can request pagination using the `NextToken` and `PerPage`
fields of `QueryOptions`, when supported by the underlying API.

Add a `NextToken` field to the `structs.QueryMeta` so that we have a
common field across RPCs to tell the caller where to resume paging
from on their next API call. Include this field on the `api.QueryMeta`
as well so that it's available for future versions of List HTTP APIs
that wrap the response with `QueryMeta` rather than returning a simple
list of structs. In the meantime callers can get the `X-Nomad-NextToken`.

Add pagination to the `Eval.List` RPC by checking for pagination token
and page size in `QueryOptions`. This will allow resuming from the
last ID seen so long as the query parameters and the state store
itself are unchanged between requests.

Add filtering by job ID or evaluation status over the results we get
out of the state store.

Parse the query parameters of the `Eval.List` API into the arguments
expected for filtering in the RPC call.
2021-12-10 13:43:03 -05:00
Mahmood Ali
d3835a1656 api: revert to defaulting to http/1 (#10958)
* api: revert to defaulting to http/1

PR #10778 incidentally changed the api http client to connect with
HTTP/2 first. However, the websocket libraries used in `alloc exec`
features don't handle http/2 well, and don't downgrade to http/1
gracefully.

Given that the switch is incidental, and not requested by users.
Furthermore, api consumers can opt-in to forcing http/2 by setting
custom http clients.

Fixes #10922
2021-07-28 11:21:53 -04:00
Alex Munda
2bd2f586f4 Set/parse idempotency_token query param 2021-07-07 16:26:55 -05:00
Alex Munda
63d8e92e90 Move idempotency token to write options. Remove DispatchIdempotent 2021-06-30 15:10:48 -05:00
Chris Baker
6064867251 sdk: header map copy to avoid race condition in #10301 2021-04-06 18:06:27 +00:00
Yoan Blanc
a814f0253f chore: bump golangci-lint from v1.24 to v1.39
Signed-off-by: Yoan Blanc <yoan@dosimple.ch>
2021-04-03 09:50:23 +02:00
Tim Gross
d7e80380de CSI: HTTP handlers for create/delete/list 2021-03-31 16:37:09 -04:00
Conor Mongey
79a4895ad7 Revert "Headers -> Header"
This reverts commit 71396fa721945e55f51bc90ed02522936450209b.
2021-01-06 17:12:22 +00:00
Conor Mongey
214f4ad4d3 Only override headers if they're set 2021-01-06 17:12:21 +00:00
Conor Mongey
b2724ba64d Ensure set headers have lower precedence than basic auth headers 2021-01-06 17:12:21 +00:00
Conor Mongey
c7cc71e2e0 Headers -> Header 2021-01-06 17:12:21 +00:00
Conor Mongey
679864ea05 Prefer http.Header over map[string]string to allow for multi-valued headers 2021-01-06 17:12:20 +00:00
Conor Mongey
3aadee8674 Allow setting of headers in api client 2021-01-06 17:03:58 +00:00
Benjamin Buzbee
648140a727 Add API support for cancelation contexts passed via QueryOptions and WriteOptions (#8836)
Copy Consul API's format: QueryOptions.WithContext(context) will now return
a new QueryOption whose HTTP requests will be canceled with the context
provided (and similar for WriteOptions)
2020-09-09 16:22:07 -04:00
Mahmood Ali
85db7187fb cli: jobs allow querying jobs in all namespaces 2020-06-17 16:31:01 -04:00
Mahmood Ali
1f6cb154b9 clarify ccomments, esp related to leadership code 2020-06-09 12:01:31 -04:00
Mahmood Ali
867147c90e api: add snapshot restore 2020-06-07 15:47:07 -04:00
James Rasell
d890ddbfd9 api: check response content length before decoding.
The API decodeBody function will now check the content length
before attempting to decode. If the length is zero, and the out
interface is nil then it is safe to assume the API call is not
returning any data to the user. This allows us to better handle
passing nil to API calls in a single place.
2020-02-20 10:07:44 +01:00
Michel Vocks
8439654c0c Add raw field for ClientCert and ClientKey 2019-12-16 14:30:00 +01:00
Michel Vocks
3d9701f6f1 Add option to set certificate in-memory via SDK 2019-12-16 10:59:27 +01:00
Michael Schurter
9d571322d3 Merge pull request #6370 from pmcatominey/tls-server-name
command: add -tls-server-name flag
2019-11-20 08:44:54 -08:00
Drew Bailey
03a4f59a05 Remove response body from websocket error
If a websocket connection errors we currently return the error with a
copy of the response body. The response body from the websocket can
often times be completely illegible so remove it from the error string.

make alloc id empty for more reliable failure

un-gzip if content encoding header present
2019-11-08 09:28:02 -05:00
Ben Barnard
a56b880570 Escape job ID in API requests (#2411)
Jobs can be created with user-provided IDs containing any character
except spaces. The jobId needs to be escaped when used in a request
path, otherwise jobs created with names such as "why?" can't be managed
after they are created.
2019-11-07 08:35:39 -05:00
Peter McAtominey
533a2df8cc command: add -tls-server-name flag 2019-09-24 09:20:41 -07:00
Jasmine Dahilig
692cd9c19e job region defaults to client node region if 'global' or none provided (#6064) 2019-08-05 14:28:02 -07:00
Mahmood Ali
2972ce15d1 fix httpClient error handling
If err is nil, we should use the newly cloned httpClient.
2019-05-21 21:29:15 -04:00
Mahmood Ali
10ab705a2c remove "incidentally" exported internal function
`*Config.ConfigureTLS()` is invoked internally by `NewClient` and API
consumers should not invoke directly.

Now that http client is created in `api.NewClient`,
`*Config.ConfigureTLS` makes no sense.  API consumers that call it
explicitly can remove the invocation and preserve the behavior.
2019-05-20 11:58:43 -04:00
Mahmood Ali
cbc155582a api: allow configuring http client
Allow clients to configure httpClient, e.g. set a pooled/keep-alive
client.

When caller configures HttpClient explicitly, we aim to use as-is; e.g.
we assume it's configured with TLS already.  Expose `ConfigureTLS` to
aid api consumers with configuring their http client.

Also, removes `SetTimeout` call that I believe is internal only and has
odd side-effects when called on already created config.  Also deprecates
`config.ConfigureTLS` in preference to the new `ConfigureTLS`.
2019-05-17 16:26:58 -04:00
Mahmood Ali
6168cc59be add api support for nomad exec
Adds nomad exec support in our API, by hitting the websocket endpoint.

We introduce API structs that correspond to the drivers streaming exec structs.

For creating the websocket connection, we reuse the transport setting from api
http client.
2019-05-09 16:49:08 -04:00
Chris Baker
af0d0f919f cli: plumbed vault token from job revert command through API call 2019-04-10 10:34:10 -05:00
Alex Dadgar
95297c608c goimports 2019-01-22 15:44:31 -08:00
Josh Soref
bd0c48f155 spelling: configurations 2018-03-11 17:47:24 +00:00
Alex Dadgar
dab5dc70e1 allow setting timeout on any api config 2018-02-15 13:59:03 -08:00
Alex Dadgar
4f2725bb98 Enhance API pkg to utilize Server's Client Tunnel
This PR enhances the API package by having client only RPCs route
through the server when they are low cost and for filesystem access to
first attempt a direct connection to the node and then falling back to
a server routed request.
2018-02-15 13:59:03 -08:00
Michael Schurter
fae8e7f699 SecretID -> AuthToken 2017-10-12 15:16:33 -07:00
Alex Dadgar
2c4c6b6ff6 Nomad UI Command 2017-10-09 23:01:55 -07:00
Alex Dadgar
de870afdd5 sync acls 2017-09-13 11:38:29 -07:00
Alex Dadgar
ac1539d5d9 Sync namespace changes 2017-09-07 17:04:21 -07:00
Armon Dadgar
425f0514a6 api: Fixing double region merge conflict 2017-09-04 13:20:51 -07:00
Armon Dadgar
d3a3575898 api: Adding support for ACL tokens 2017-09-04 13:09:34 -07:00
Armon Dadgar
e24fa79aab agent: thread ACLs for Job Register 2017-09-04 13:05:53 -07:00
Alex Dadgar
d759dc8100 Address feedback 2017-08-29 16:09:53 -07:00
Alex Dadgar
f5fb62c7cc Node Client doesn't share HTTP client 2017-08-29 14:22:11 -07:00
Alex Dadgar
4d3b75d867 Fix TLSServerName for Node API Client
This PR fixes the construction of the TLSServerName when connecting to a
node that has TLS enabled and adds tests for all possible permutations.

Fixes https://github.com/hashicorp/nomad/issues/3013
2017-08-29 11:11:19 -07:00
Michael Schurter
52857a6a9d Simplify region handling 2017-08-28 14:58:15 -07:00
Michael Schurter
2f30827205 Refactor GetNodeClient weirdness
- No need to for a pointer to a pointer
- Properly set and use QueryOptions.Region
2017-08-28 14:41:21 -07:00
Michael Schurter
1bb8a54ffb Fix TLS support in api pkg / cli
Fixes #3013

It's a little weird that Client now has a method for returning a
NewClient, but it's a convenient way to dedupe the logic to
connect-directly-to-a-node which is nontrivial and had sutble
differences between locations.
2017-08-28 11:46:28 -07:00
Alex Dadgar
4d97b302a0 Search respects QueryOptions and returns QueryMeta
@chelseakomlo heads up on this change
2017-08-27 22:17:51 -07:00
Ben Barnard
ce1fa4651a Remove duplicate check 2017-03-08 16:19:38 +01:00