grpc 1.17.1 → 1.18.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of grpc might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Makefile +1228 -988
- data/etc/roots.pem +242 -30
- data/include/grpc/grpc.h +2 -1
- data/include/grpc/grpc_security_constants.h +3 -3
- data/include/grpc/impl/codegen/atm_gcc_sync.h +2 -0
- data/include/grpc/impl/codegen/atm_windows.h +2 -0
- data/include/grpc/impl/codegen/compression_types.h +2 -1
- data/include/grpc/impl/codegen/grpc_types.h +1 -1
- data/include/grpc/impl/codegen/port_platform.h +9 -0
- data/src/core/ext/filters/client_channel/client_channel.cc +163 -882
- data/src/core/ext/filters/client_channel/health/health_check_client.cc +2 -4
- data/src/core/ext/filters/client_channel/health/health_check_client.h +2 -3
- data/src/core/ext/filters/client_channel/lb_policy.cc +1 -1
- data/src/core/ext/filters/client_channel/lb_policy.h +8 -17
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +176 -216
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h +1 -1
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +20 -23
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +1 -1
- data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +49 -52
- data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +13 -35
- data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +31 -30
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +69 -225
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel.h +1 -1
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_secure.cc +20 -23
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.h +1 -1
- data/src/core/ext/filters/client_channel/lb_policy_factory.h +2 -84
- data/src/core/ext/filters/client_channel/request_routing.cc +936 -0
- data/src/core/ext/filters/client_channel/request_routing.h +177 -0
- data/src/core/ext/filters/client_channel/resolver.cc +1 -1
- data/src/core/ext/filters/client_channel/resolver.h +1 -1
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +37 -26
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.cc +30 -18
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +119 -100
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +8 -5
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +5 -4
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_posix.cc +2 -1
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +12 -14
- data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +5 -9
- data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +2 -1
- data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +1 -2
- data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +17 -17
- data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +45 -52
- data/src/core/ext/filters/client_channel/resolver_result_parsing.h +13 -17
- data/src/core/ext/filters/client_channel/server_address.cc +103 -0
- data/src/core/ext/filters/client_channel/server_address.h +108 -0
- data/src/core/ext/filters/client_channel/subchannel.cc +10 -8
- data/src/core/ext/filters/client_channel/subchannel.h +9 -6
- data/src/core/ext/filters/client_channel/subchannel_index.cc +20 -27
- data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +3 -2
- data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +8 -9
- data/src/core/ext/transport/chttp2/server/chttp2_server.cc +1 -1
- data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc +1 -1
- data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc +8 -11
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +24 -54
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +3 -1
- data/src/core/ext/transport/chttp2/transport/context_list.cc +67 -0
- data/src/core/ext/transport/chttp2/transport/context_list.h +53 -0
- data/src/core/ext/transport/chttp2/transport/internal.h +38 -11
- data/src/core/ext/transport/chttp2/transport/writing.cc +5 -0
- data/src/core/ext/transport/inproc/inproc_transport.cc +1 -1
- data/src/core/lib/channel/channelz.cc +19 -18
- data/src/core/lib/channel/channelz.h +7 -1
- data/src/core/lib/channel/channelz_registry.cc +3 -2
- data/src/core/lib/debug/trace.cc +3 -0
- data/src/core/lib/debug/trace.h +5 -3
- data/src/core/lib/gpr/sync_posix.cc +96 -4
- data/src/core/lib/gprpp/inlined_vector.h +25 -19
- data/src/core/lib/gprpp/memory.h +2 -11
- data/src/core/lib/gprpp/orphanable.h +18 -82
- data/src/core/lib/gprpp/ref_counted.h +75 -84
- data/src/core/lib/gprpp/ref_counted_ptr.h +22 -17
- data/src/core/lib/http/httpcli_security_connector.cc +101 -94
- data/src/core/lib/http/parser.h +5 -5
- data/src/core/lib/iomgr/buffer_list.cc +16 -5
- data/src/core/lib/iomgr/buffer_list.h +10 -3
- data/src/core/lib/iomgr/call_combiner.cc +50 -2
- data/src/core/lib/iomgr/call_combiner.h +29 -2
- data/src/core/lib/iomgr/dynamic_annotations.h +67 -0
- data/src/core/lib/iomgr/endpoint.cc +4 -0
- data/src/core/lib/iomgr/endpoint.h +3 -0
- data/src/core/lib/iomgr/endpoint_pair_posix.cc +2 -2
- data/src/core/lib/iomgr/ev_epoll1_linux.cc +4 -0
- data/src/core/lib/iomgr/ev_epollex_linux.cc +4 -0
- data/src/core/lib/iomgr/ev_poll_posix.cc +4 -0
- data/src/core/lib/iomgr/ev_posix.cc +15 -7
- data/src/core/lib/iomgr/ev_posix.h +10 -0
- data/src/core/lib/iomgr/exec_ctx.cc +13 -0
- data/src/core/lib/iomgr/fork_posix.cc +1 -1
- data/src/core/lib/iomgr/internal_errqueue.cc +36 -3
- data/src/core/lib/iomgr/internal_errqueue.h +7 -1
- data/src/core/lib/iomgr/iomgr.cc +7 -0
- data/src/core/lib/iomgr/iomgr.h +4 -0
- data/src/core/lib/iomgr/iomgr_custom.cc +3 -1
- data/src/core/lib/iomgr/iomgr_internal.cc +4 -0
- data/src/core/lib/iomgr/iomgr_internal.h +4 -0
- data/src/core/lib/iomgr/iomgr_posix.cc +6 -1
- data/src/core/lib/iomgr/iomgr_windows.cc +4 -1
- data/src/core/lib/iomgr/port.h +1 -2
- data/src/core/lib/iomgr/resource_quota.cc +1 -0
- data/src/core/lib/iomgr/sockaddr_utils.cc +1 -0
- data/src/core/lib/iomgr/tcp_custom.cc +4 -1
- data/src/core/lib/iomgr/tcp_posix.cc +95 -35
- data/src/core/lib/iomgr/tcp_windows.cc +4 -1
- data/src/core/lib/iomgr/timer_manager.cc +6 -0
- data/src/core/lib/security/context/security_context.cc +75 -108
- data/src/core/lib/security/context/security_context.h +59 -35
- data/src/core/lib/security/credentials/alts/alts_credentials.cc +36 -48
- data/src/core/lib/security/credentials/alts/alts_credentials.h +37 -10
- data/src/core/lib/security/credentials/composite/composite_credentials.cc +97 -157
- data/src/core/lib/security/credentials/composite/composite_credentials.h +60 -24
- data/src/core/lib/security/credentials/credentials.cc +18 -142
- data/src/core/lib/security/credentials/credentials.h +119 -95
- data/src/core/lib/security/credentials/fake/fake_credentials.cc +46 -71
- data/src/core/lib/security/credentials/fake/fake_credentials.h +23 -5
- data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +144 -51
- data/src/core/lib/security/credentials/google_default/google_default_credentials.h +28 -5
- data/src/core/lib/security/credentials/iam/iam_credentials.cc +27 -35
- data/src/core/lib/security/credentials/iam/iam_credentials.h +18 -4
- data/src/core/lib/security/credentials/jwt/jwt_credentials.cc +60 -69
- data/src/core/lib/security/credentials/jwt/jwt_credentials.h +29 -10
- data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +2 -0
- data/src/core/lib/security/credentials/local/local_credentials.cc +19 -32
- data/src/core/lib/security/credentials/local/local_credentials.h +32 -11
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +130 -149
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +74 -29
- data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +59 -77
- data/src/core/lib/security/credentials/plugin/plugin_credentials.h +40 -17
- data/src/core/lib/security/credentials/ssl/ssl_credentials.cc +66 -83
- data/src/core/lib/security/credentials/ssl/ssl_credentials.h +58 -15
- data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +152 -177
- data/src/core/lib/security/security_connector/alts/alts_security_connector.h +12 -10
- data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +210 -215
- data/src/core/lib/security/security_connector/fake/fake_security_connector.h +9 -6
- data/src/core/lib/security/security_connector/local/local_security_connector.cc +176 -169
- data/src/core/lib/security/security_connector/local/local_security_connector.h +10 -9
- data/src/core/lib/security/security_connector/security_connector.cc +41 -124
- data/src/core/lib/security/security_connector/security_connector.h +102 -105
- data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +348 -370
- data/src/core/lib/security/security_connector/ssl/ssl_security_connector.h +14 -12
- data/src/core/lib/security/security_connector/ssl_utils.cc +13 -9
- data/src/core/lib/security/security_connector/ssl_utils.h +3 -1
- data/src/core/lib/security/transport/client_auth_filter.cc +50 -50
- data/src/core/lib/security/transport/secure_endpoint.cc +7 -1
- data/src/core/lib/security/transport/security_handshaker.cc +82 -66
- data/src/core/lib/security/transport/server_auth_filter.cc +15 -13
- data/src/core/lib/surface/init.cc +1 -0
- data/src/core/lib/surface/server.cc +13 -11
- data/src/core/lib/surface/server.h +6 -6
- data/src/core/lib/surface/version.cc +2 -2
- data/src/core/lib/transport/metadata.cc +1 -0
- data/src/core/lib/transport/static_metadata.cc +228 -221
- data/src/core/lib/transport/static_metadata.h +75 -71
- data/src/core/lib/transport/transport.cc +2 -1
- data/src/core/lib/transport/transport.h +5 -1
- data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +9 -2
- data/src/core/tsi/ssl_transport_security.cc +35 -24
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +1 -1
- data/src/ruby/lib/grpc/generic/rpc_server.rb +61 -0
- data/src/ruby/lib/grpc/generic/service.rb +1 -1
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/src/ruby/pb/grpc/health/checker.rb +2 -3
- data/src/ruby/spec/generic/rpc_server_spec.rb +22 -0
- data/src/ruby/spec/support/services.rb +1 -0
- metadata +37 -32
- data/src/core/ext/filters/client_channel/lb_policy_factory.cc +0 -163
@@ -25,16 +25,37 @@
|
|
25
25
|
|
26
26
|
#include "src/core/lib/security/credentials/credentials.h"
|
27
27
|
|
28
|
-
/* Main
|
29
|
-
|
30
|
-
|
31
|
-
grpc_local_connect_type connect_type;
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
28
|
+
/* Main class for grpc local channel credential. */
|
29
|
+
class grpc_local_credentials final : public grpc_channel_credentials {
|
30
|
+
public:
|
31
|
+
explicit grpc_local_credentials(grpc_local_connect_type connect_type);
|
32
|
+
~grpc_local_credentials() override = default;
|
33
|
+
|
34
|
+
grpc_core::RefCountedPtr<grpc_channel_security_connector>
|
35
|
+
create_security_connector(
|
36
|
+
grpc_core::RefCountedPtr<grpc_call_credentials> request_metadata_creds,
|
37
|
+
const char* target_name, const grpc_channel_args* args,
|
38
|
+
grpc_channel_args** new_args) override;
|
39
|
+
|
40
|
+
grpc_local_connect_type connect_type() const { return connect_type_; }
|
41
|
+
|
42
|
+
private:
|
43
|
+
grpc_local_connect_type connect_type_;
|
44
|
+
};
|
45
|
+
|
46
|
+
/* Main class for grpc local server credential. */
|
47
|
+
class grpc_local_server_credentials final : public grpc_server_credentials {
|
48
|
+
public:
|
49
|
+
explicit grpc_local_server_credentials(grpc_local_connect_type connect_type);
|
50
|
+
~grpc_local_server_credentials() override = default;
|
51
|
+
|
52
|
+
grpc_core::RefCountedPtr<grpc_server_security_connector>
|
53
|
+
create_security_connector() override;
|
54
|
+
|
55
|
+
grpc_local_connect_type connect_type() const { return connect_type_; }
|
56
|
+
|
57
|
+
private:
|
58
|
+
grpc_local_connect_type connect_type_;
|
59
|
+
};
|
39
60
|
|
40
61
|
#endif /* GRPC_CORE_LIB_SECURITY_CREDENTIALS_LOCAL_LOCAL_CREDENTIALS_H */
|
@@ -22,6 +22,7 @@
|
|
22
22
|
|
23
23
|
#include <string.h>
|
24
24
|
|
25
|
+
#include "src/core/lib/gprpp/ref_counted_ptr.h"
|
25
26
|
#include "src/core/lib/security/util/json_util.h"
|
26
27
|
#include "src/core/lib/surface/api_trace.h"
|
27
28
|
|
@@ -105,13 +106,12 @@ void grpc_auth_refresh_token_destruct(grpc_auth_refresh_token* refresh_token) {
|
|
105
106
|
// Oauth2 Token Fetcher credentials.
|
106
107
|
//
|
107
108
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
grpc_httpcli_context_destroy(&c->httpcli_context);
|
109
|
+
grpc_oauth2_token_fetcher_credentials::
|
110
|
+
~grpc_oauth2_token_fetcher_credentials() {
|
111
|
+
GRPC_MDELEM_UNREF(access_token_md_);
|
112
|
+
gpr_mu_destroy(&mu_);
|
113
|
+
grpc_pollset_set_destroy(grpc_polling_entity_pollset_set(&pollent_));
|
114
|
+
grpc_httpcli_context_destroy(&httpcli_context_);
|
115
115
|
}
|
116
116
|
|
117
117
|
grpc_credentials_status
|
@@ -209,25 +209,29 @@ static void on_oauth2_token_fetcher_http_response(void* user_data,
|
|
209
209
|
grpc_credentials_metadata_request* r =
|
210
210
|
static_cast<grpc_credentials_metadata_request*>(user_data);
|
211
211
|
grpc_oauth2_token_fetcher_credentials* c =
|
212
|
-
reinterpret_cast<grpc_oauth2_token_fetcher_credentials*>(r->creds);
|
212
|
+
reinterpret_cast<grpc_oauth2_token_fetcher_credentials*>(r->creds.get());
|
213
|
+
c->on_http_response(r, error);
|
214
|
+
}
|
215
|
+
|
216
|
+
void grpc_oauth2_token_fetcher_credentials::on_http_response(
|
217
|
+
grpc_credentials_metadata_request* r, grpc_error* error) {
|
213
218
|
grpc_mdelem access_token_md = GRPC_MDNULL;
|
214
219
|
grpc_millis token_lifetime;
|
215
220
|
grpc_credentials_status status =
|
216
221
|
grpc_oauth2_token_fetcher_credentials_parse_server_response(
|
217
222
|
&r->response, &access_token_md, &token_lifetime);
|
218
223
|
// Update cache and grab list of pending requests.
|
219
|
-
gpr_mu_lock(&
|
220
|
-
|
221
|
-
|
222
|
-
|
224
|
+
gpr_mu_lock(&mu_);
|
225
|
+
token_fetch_pending_ = false;
|
226
|
+
access_token_md_ = GRPC_MDELEM_REF(access_token_md);
|
227
|
+
token_expiration_ =
|
223
228
|
status == GRPC_CREDENTIALS_OK
|
224
229
|
? gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC),
|
225
230
|
gpr_time_from_millis(token_lifetime, GPR_TIMESPAN))
|
226
231
|
: gpr_inf_past(GPR_CLOCK_MONOTONIC);
|
227
|
-
grpc_oauth2_pending_get_request_metadata* pending_request =
|
228
|
-
|
229
|
-
|
230
|
-
gpr_mu_unlock(&c->mu);
|
232
|
+
grpc_oauth2_pending_get_request_metadata* pending_request = pending_requests_;
|
233
|
+
pending_requests_ = nullptr;
|
234
|
+
gpr_mu_unlock(&mu_);
|
231
235
|
// Invoke callbacks for all pending requests.
|
232
236
|
while (pending_request != nullptr) {
|
233
237
|
if (status == GRPC_CREDENTIALS_OK) {
|
@@ -239,42 +243,40 @@ static void on_oauth2_token_fetcher_http_response(void* user_data,
|
|
239
243
|
}
|
240
244
|
GRPC_CLOSURE_SCHED(pending_request->on_request_metadata, error);
|
241
245
|
grpc_polling_entity_del_from_pollset_set(
|
242
|
-
pending_request->pollent, grpc_polling_entity_pollset_set(&
|
246
|
+
pending_request->pollent, grpc_polling_entity_pollset_set(&pollent_));
|
243
247
|
grpc_oauth2_pending_get_request_metadata* prev = pending_request;
|
244
248
|
pending_request = pending_request->next;
|
245
249
|
gpr_free(prev);
|
246
250
|
}
|
247
251
|
GRPC_MDELEM_UNREF(access_token_md);
|
248
|
-
|
252
|
+
Unref();
|
249
253
|
grpc_credentials_metadata_request_destroy(r);
|
250
254
|
}
|
251
255
|
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
grpc_oauth2_token_fetcher_credentials* c =
|
257
|
-
reinterpret_cast<grpc_oauth2_token_fetcher_credentials*>(creds);
|
256
|
+
bool grpc_oauth2_token_fetcher_credentials::get_request_metadata(
|
257
|
+
grpc_polling_entity* pollent, grpc_auth_metadata_context context,
|
258
|
+
grpc_credentials_mdelem_array* md_array, grpc_closure* on_request_metadata,
|
259
|
+
grpc_error** error) {
|
258
260
|
// Check if we can use the cached token.
|
259
261
|
grpc_millis refresh_threshold =
|
260
262
|
GRPC_SECURE_TOKEN_REFRESH_THRESHOLD_SECS * GPR_MS_PER_SEC;
|
261
263
|
grpc_mdelem cached_access_token_md = GRPC_MDNULL;
|
262
|
-
gpr_mu_lock(&
|
263
|
-
if (!GRPC_MDISNULL(
|
264
|
+
gpr_mu_lock(&mu_);
|
265
|
+
if (!GRPC_MDISNULL(access_token_md_) &&
|
264
266
|
gpr_time_cmp(
|
265
|
-
gpr_time_sub(
|
267
|
+
gpr_time_sub(token_expiration_, gpr_now(GPR_CLOCK_MONOTONIC)),
|
266
268
|
gpr_time_from_seconds(GRPC_SECURE_TOKEN_REFRESH_THRESHOLD_SECS,
|
267
269
|
GPR_TIMESPAN)) > 0) {
|
268
|
-
cached_access_token_md = GRPC_MDELEM_REF(
|
270
|
+
cached_access_token_md = GRPC_MDELEM_REF(access_token_md_);
|
269
271
|
}
|
270
272
|
if (!GRPC_MDISNULL(cached_access_token_md)) {
|
271
|
-
gpr_mu_unlock(&
|
273
|
+
gpr_mu_unlock(&mu_);
|
272
274
|
grpc_credentials_mdelem_array_add(md_array, cached_access_token_md);
|
273
275
|
GRPC_MDELEM_UNREF(cached_access_token_md);
|
274
276
|
return true;
|
275
277
|
}
|
276
278
|
// Couldn't get the token from the cache.
|
277
|
-
// Add request to
|
279
|
+
// Add request to pending_requests_ and start a new fetch if needed.
|
278
280
|
grpc_oauth2_pending_get_request_metadata* pending_request =
|
279
281
|
static_cast<grpc_oauth2_pending_get_request_metadata*>(
|
280
282
|
gpr_malloc(sizeof(*pending_request)));
|
@@ -282,41 +284,37 @@ static bool oauth2_token_fetcher_get_request_metadata(
|
|
282
284
|
pending_request->on_request_metadata = on_request_metadata;
|
283
285
|
pending_request->pollent = pollent;
|
284
286
|
grpc_polling_entity_add_to_pollset_set(
|
285
|
-
pollent, grpc_polling_entity_pollset_set(&
|
286
|
-
pending_request->next =
|
287
|
-
|
287
|
+
pollent, grpc_polling_entity_pollset_set(&pollent_));
|
288
|
+
pending_request->next = pending_requests_;
|
289
|
+
pending_requests_ = pending_request;
|
288
290
|
bool start_fetch = false;
|
289
|
-
if (!
|
290
|
-
|
291
|
+
if (!token_fetch_pending_) {
|
292
|
+
token_fetch_pending_ = true;
|
291
293
|
start_fetch = true;
|
292
294
|
}
|
293
|
-
gpr_mu_unlock(&
|
295
|
+
gpr_mu_unlock(&mu_);
|
294
296
|
if (start_fetch) {
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
297
|
+
Ref().release();
|
298
|
+
fetch_oauth2(grpc_credentials_metadata_request_create(this->Ref()),
|
299
|
+
&httpcli_context_, &pollent_,
|
300
|
+
on_oauth2_token_fetcher_http_response,
|
301
|
+
grpc_core::ExecCtx::Get()->Now() + refresh_threshold);
|
300
302
|
}
|
301
303
|
return false;
|
302
304
|
}
|
303
305
|
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
grpc_oauth2_token_fetcher_credentials* c =
|
308
|
-
reinterpret_cast<grpc_oauth2_token_fetcher_credentials*>(creds);
|
309
|
-
gpr_mu_lock(&c->mu);
|
306
|
+
void grpc_oauth2_token_fetcher_credentials::cancel_get_request_metadata(
|
307
|
+
grpc_credentials_mdelem_array* md_array, grpc_error* error) {
|
308
|
+
gpr_mu_lock(&mu_);
|
310
309
|
grpc_oauth2_pending_get_request_metadata* prev = nullptr;
|
311
|
-
grpc_oauth2_pending_get_request_metadata* pending_request =
|
312
|
-
c->pending_requests;
|
310
|
+
grpc_oauth2_pending_get_request_metadata* pending_request = pending_requests_;
|
313
311
|
while (pending_request != nullptr) {
|
314
312
|
if (pending_request->md_array == md_array) {
|
315
313
|
// Remove matching pending request from the list.
|
316
314
|
if (prev != nullptr) {
|
317
315
|
prev->next = pending_request->next;
|
318
316
|
} else {
|
319
|
-
|
317
|
+
pending_requests_ = pending_request->next;
|
320
318
|
}
|
321
319
|
// Invoke the callback immediately with an error.
|
322
320
|
GRPC_CLOSURE_SCHED(pending_request->on_request_metadata,
|
@@ -327,96 +325,89 @@ static void oauth2_token_fetcher_cancel_get_request_metadata(
|
|
327
325
|
prev = pending_request;
|
328
326
|
pending_request = pending_request->next;
|
329
327
|
}
|
330
|
-
gpr_mu_unlock(&
|
328
|
+
gpr_mu_unlock(&mu_);
|
331
329
|
GRPC_ERROR_UNREF(error);
|
332
330
|
}
|
333
331
|
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
gpr_mu_init(&
|
340
|
-
|
341
|
-
c->fetch_func = fetch_func;
|
342
|
-
c->pollent =
|
343
|
-
grpc_polling_entity_create_from_pollset_set(grpc_pollset_set_create());
|
344
|
-
grpc_httpcli_context_init(&c->httpcli_context);
|
332
|
+
grpc_oauth2_token_fetcher_credentials::grpc_oauth2_token_fetcher_credentials()
|
333
|
+
: grpc_call_credentials(GRPC_CALL_CREDENTIALS_TYPE_OAUTH2),
|
334
|
+
token_expiration_(gpr_inf_past(GPR_CLOCK_MONOTONIC)),
|
335
|
+
pollent_(grpc_polling_entity_create_from_pollset_set(
|
336
|
+
grpc_pollset_set_create())) {
|
337
|
+
gpr_mu_init(&mu_);
|
338
|
+
grpc_httpcli_context_init(&httpcli_context_);
|
345
339
|
}
|
346
340
|
|
347
341
|
//
|
348
342
|
// Google Compute Engine credentials.
|
349
343
|
//
|
350
344
|
|
351
|
-
|
352
|
-
|
353
|
-
|
345
|
+
namespace {
|
346
|
+
|
347
|
+
class grpc_compute_engine_token_fetcher_credentials
|
348
|
+
: public grpc_oauth2_token_fetcher_credentials {
|
349
|
+
public:
|
350
|
+
grpc_compute_engine_token_fetcher_credentials() = default;
|
351
|
+
~grpc_compute_engine_token_fetcher_credentials() override = default;
|
352
|
+
|
353
|
+
protected:
|
354
|
+
void fetch_oauth2(grpc_credentials_metadata_request* metadata_req,
|
355
|
+
grpc_httpcli_context* http_context,
|
356
|
+
grpc_polling_entity* pollent,
|
357
|
+
grpc_iomgr_cb_func response_cb,
|
358
|
+
grpc_millis deadline) override {
|
359
|
+
grpc_http_header header = {(char*)"Metadata-Flavor", (char*)"Google"};
|
360
|
+
grpc_httpcli_request request;
|
361
|
+
memset(&request, 0, sizeof(grpc_httpcli_request));
|
362
|
+
request.host = (char*)GRPC_COMPUTE_ENGINE_METADATA_HOST;
|
363
|
+
request.http.path = (char*)GRPC_COMPUTE_ENGINE_METADATA_TOKEN_PATH;
|
364
|
+
request.http.hdr_count = 1;
|
365
|
+
request.http.hdrs = &header;
|
366
|
+
/* TODO(ctiller): Carry the resource_quota in ctx and share it with the host
|
367
|
+
channel. This would allow us to cancel an authentication query when under
|
368
|
+
extreme memory pressure. */
|
369
|
+
grpc_resource_quota* resource_quota =
|
370
|
+
grpc_resource_quota_create("oauth2_credentials");
|
371
|
+
grpc_httpcli_get(http_context, pollent, resource_quota, &request, deadline,
|
372
|
+
GRPC_CLOSURE_CREATE(response_cb, metadata_req,
|
373
|
+
grpc_schedule_on_exec_ctx),
|
374
|
+
&metadata_req->response);
|
375
|
+
grpc_resource_quota_unref_internal(resource_quota);
|
376
|
+
}
|
377
|
+
};
|
354
378
|
|
355
|
-
|
356
|
-
grpc_credentials_metadata_request* metadata_req,
|
357
|
-
grpc_httpcli_context* httpcli_context, grpc_polling_entity* pollent,
|
358
|
-
grpc_iomgr_cb_func response_cb, grpc_millis deadline) {
|
359
|
-
grpc_http_header header = {(char*)"Metadata-Flavor", (char*)"Google"};
|
360
|
-
grpc_httpcli_request request;
|
361
|
-
memset(&request, 0, sizeof(grpc_httpcli_request));
|
362
|
-
request.host = (char*)GRPC_COMPUTE_ENGINE_METADATA_HOST;
|
363
|
-
request.http.path = (char*)GRPC_COMPUTE_ENGINE_METADATA_TOKEN_PATH;
|
364
|
-
request.http.hdr_count = 1;
|
365
|
-
request.http.hdrs = &header;
|
366
|
-
/* TODO(ctiller): Carry the resource_quota in ctx and share it with the host
|
367
|
-
channel. This would allow us to cancel an authentication query when under
|
368
|
-
extreme memory pressure. */
|
369
|
-
grpc_resource_quota* resource_quota =
|
370
|
-
grpc_resource_quota_create("oauth2_credentials");
|
371
|
-
grpc_httpcli_get(
|
372
|
-
httpcli_context, pollent, resource_quota, &request, deadline,
|
373
|
-
GRPC_CLOSURE_CREATE(response_cb, metadata_req, grpc_schedule_on_exec_ctx),
|
374
|
-
&metadata_req->response);
|
375
|
-
grpc_resource_quota_unref_internal(resource_quota);
|
376
|
-
}
|
379
|
+
} // namespace
|
377
380
|
|
378
381
|
grpc_call_credentials* grpc_google_compute_engine_credentials_create(
|
379
382
|
void* reserved) {
|
380
|
-
grpc_oauth2_token_fetcher_credentials* c =
|
381
|
-
static_cast<grpc_oauth2_token_fetcher_credentials*>(
|
382
|
-
gpr_malloc(sizeof(grpc_oauth2_token_fetcher_credentials)));
|
383
383
|
GRPC_API_TRACE("grpc_compute_engine_credentials_create(reserved=%p)", 1,
|
384
384
|
(reserved));
|
385
385
|
GPR_ASSERT(reserved == nullptr);
|
386
|
-
|
387
|
-
|
388
|
-
|
386
|
+
return grpc_core::MakeRefCounted<
|
387
|
+
grpc_compute_engine_token_fetcher_credentials>()
|
388
|
+
.release();
|
389
389
|
}
|
390
390
|
|
391
391
|
//
|
392
392
|
// Google Refresh Token credentials.
|
393
393
|
//
|
394
394
|
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
grpc_auth_refresh_token_destruct(&c->refresh_token);
|
399
|
-
oauth2_token_fetcher_destruct(&c->base.base);
|
395
|
+
grpc_google_refresh_token_credentials::
|
396
|
+
~grpc_google_refresh_token_credentials() {
|
397
|
+
grpc_auth_refresh_token_destruct(&refresh_token_);
|
400
398
|
}
|
401
399
|
|
402
|
-
|
403
|
-
refresh_token_destruct, oauth2_token_fetcher_get_request_metadata,
|
404
|
-
oauth2_token_fetcher_cancel_get_request_metadata};
|
405
|
-
|
406
|
-
static void refresh_token_fetch_oauth2(
|
400
|
+
void grpc_google_refresh_token_credentials::fetch_oauth2(
|
407
401
|
grpc_credentials_metadata_request* metadata_req,
|
408
402
|
grpc_httpcli_context* httpcli_context, grpc_polling_entity* pollent,
|
409
403
|
grpc_iomgr_cb_func response_cb, grpc_millis deadline) {
|
410
|
-
grpc_google_refresh_token_credentials* c =
|
411
|
-
reinterpret_cast<grpc_google_refresh_token_credentials*>(
|
412
|
-
metadata_req->creds);
|
413
404
|
grpc_http_header header = {(char*)"Content-Type",
|
414
405
|
(char*)"application/x-www-form-urlencoded"};
|
415
406
|
grpc_httpcli_request request;
|
416
407
|
char* body = nullptr;
|
417
408
|
gpr_asprintf(&body, GRPC_REFRESH_TOKEN_POST_BODY_FORMAT_STRING,
|
418
|
-
|
419
|
-
|
409
|
+
refresh_token_.client_id, refresh_token_.client_secret,
|
410
|
+
refresh_token_.refresh_token);
|
420
411
|
memset(&request, 0, sizeof(grpc_httpcli_request));
|
421
412
|
request.host = (char*)GRPC_GOOGLE_OAUTH2_SERVICE_HOST;
|
422
413
|
request.http.path = (char*)GRPC_GOOGLE_OAUTH2_SERVICE_TOKEN_PATH;
|
@@ -437,20 +428,19 @@ static void refresh_token_fetch_oauth2(
|
|
437
428
|
gpr_free(body);
|
438
429
|
}
|
439
430
|
|
440
|
-
|
431
|
+
grpc_google_refresh_token_credentials::grpc_google_refresh_token_credentials(
|
432
|
+
grpc_auth_refresh_token refresh_token)
|
433
|
+
: refresh_token_(refresh_token) {}
|
434
|
+
|
435
|
+
grpc_core::RefCountedPtr<grpc_call_credentials>
|
441
436
|
grpc_refresh_token_credentials_create_from_auth_refresh_token(
|
442
437
|
grpc_auth_refresh_token refresh_token) {
|
443
|
-
grpc_google_refresh_token_credentials* c;
|
444
438
|
if (!grpc_auth_refresh_token_is_valid(&refresh_token)) {
|
445
439
|
gpr_log(GPR_ERROR, "Invalid input for refresh token credentials creation");
|
446
440
|
return nullptr;
|
447
441
|
}
|
448
|
-
|
449
|
-
|
450
|
-
init_oauth2_token_fetcher(&c->base, refresh_token_fetch_oauth2);
|
451
|
-
c->base.base.vtable = &refresh_token_vtable;
|
452
|
-
c->refresh_token = refresh_token;
|
453
|
-
return &c->base.base;
|
442
|
+
return grpc_core::MakeRefCounted<grpc_google_refresh_token_credentials>(
|
443
|
+
refresh_token);
|
454
444
|
}
|
455
445
|
|
456
446
|
static char* create_loggable_refresh_token(grpc_auth_refresh_token* token) {
|
@@ -478,59 +468,50 @@ grpc_call_credentials* grpc_google_refresh_token_credentials_create(
|
|
478
468
|
gpr_free(loggable_token);
|
479
469
|
}
|
480
470
|
GPR_ASSERT(reserved == nullptr);
|
481
|
-
return grpc_refresh_token_credentials_create_from_auth_refresh_token(token)
|
471
|
+
return grpc_refresh_token_credentials_create_from_auth_refresh_token(token)
|
472
|
+
.release();
|
482
473
|
}
|
483
474
|
|
484
475
|
//
|
485
476
|
// Oauth2 Access Token credentials.
|
486
477
|
//
|
487
478
|
|
488
|
-
|
489
|
-
|
490
|
-
reinterpret_cast<grpc_access_token_credentials*>(creds);
|
491
|
-
GRPC_MDELEM_UNREF(c->access_token_md);
|
479
|
+
grpc_access_token_credentials::~grpc_access_token_credentials() {
|
480
|
+
GRPC_MDELEM_UNREF(access_token_md_);
|
492
481
|
}
|
493
482
|
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
reinterpret_cast<grpc_access_token_credentials*>(creds);
|
500
|
-
grpc_credentials_mdelem_array_add(md_array, c->access_token_md);
|
483
|
+
bool grpc_access_token_credentials::get_request_metadata(
|
484
|
+
grpc_polling_entity* pollent, grpc_auth_metadata_context context,
|
485
|
+
grpc_credentials_mdelem_array* md_array, grpc_closure* on_request_metadata,
|
486
|
+
grpc_error** error) {
|
487
|
+
grpc_credentials_mdelem_array_add(md_array, access_token_md_);
|
501
488
|
return true;
|
502
489
|
}
|
503
490
|
|
504
|
-
|
505
|
-
|
506
|
-
grpc_error* error) {
|
491
|
+
void grpc_access_token_credentials::cancel_get_request_metadata(
|
492
|
+
grpc_credentials_mdelem_array* md_array, grpc_error* error) {
|
507
493
|
GRPC_ERROR_UNREF(error);
|
508
494
|
}
|
509
495
|
|
510
|
-
|
511
|
-
|
512
|
-
|
496
|
+
grpc_access_token_credentials::grpc_access_token_credentials(
|
497
|
+
const char* access_token)
|
498
|
+
: grpc_call_credentials(GRPC_CALL_CREDENTIALS_TYPE_OAUTH2) {
|
499
|
+
char* token_md_value;
|
500
|
+
gpr_asprintf(&token_md_value, "Bearer %s", access_token);
|
501
|
+
grpc_core::ExecCtx exec_ctx;
|
502
|
+
access_token_md_ = grpc_mdelem_from_slices(
|
503
|
+
grpc_slice_from_static_string(GRPC_AUTHORIZATION_METADATA_KEY),
|
504
|
+
grpc_slice_from_copied_string(token_md_value));
|
505
|
+
gpr_free(token_md_value);
|
506
|
+
}
|
513
507
|
|
514
508
|
grpc_call_credentials* grpc_access_token_credentials_create(
|
515
509
|
const char* access_token, void* reserved) {
|
516
|
-
grpc_access_token_credentials* c =
|
517
|
-
static_cast<grpc_access_token_credentials*>(
|
518
|
-
gpr_zalloc(sizeof(grpc_access_token_credentials)));
|
519
510
|
GRPC_API_TRACE(
|
520
511
|
"grpc_access_token_credentials_create(access_token=<redacted>, "
|
521
512
|
"reserved=%p)",
|
522
513
|
1, (reserved));
|
523
514
|
GPR_ASSERT(reserved == nullptr);
|
524
|
-
|
525
|
-
|
526
|
-
gpr_ref_init(&c->base.refcount, 1);
|
527
|
-
char* token_md_value;
|
528
|
-
gpr_asprintf(&token_md_value, "Bearer %s", access_token);
|
529
|
-
grpc_core::ExecCtx exec_ctx;
|
530
|
-
c->access_token_md = grpc_mdelem_from_slices(
|
531
|
-
grpc_slice_from_static_string(GRPC_AUTHORIZATION_METADATA_KEY),
|
532
|
-
grpc_slice_from_copied_string(token_md_value));
|
533
|
-
|
534
|
-
gpr_free(token_md_value);
|
535
|
-
return &c->base;
|
515
|
+
return grpc_core::MakeRefCounted<grpc_access_token_credentials>(access_token)
|
516
|
+
.release();
|
536
517
|
}
|