MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / completion_grpc_client

Function completion_grpc_client

crates/openshell-cli/src/completers.rs:88–131  ·  view source on GitHub ↗
(
    server: &str,
    gateway_name: &str,
)

Source from the content-addressed store, hash-verified

86}
87
88async fn completion_grpc_client(
89 server: &str,
90 gateway_name: &str,
91) -> Option<OpenShellClient<InterceptedService<Channel, EdgeAuthInterceptor>>> {
92 let mut tls_opts = TlsOptions::default().with_gateway_name(gateway_name);
93 tls_opts.gateway_insecure = std::env::var("OPENSHELL_GATEWAY_INSECURE")
94 .is_ok_and(|v| !v.is_empty() && v != "0" && v != "false");
95
96 if let Ok(meta) = load_gateway_metadata(gateway_name) {
97 match meta.auth_mode.as_deref() {
98 Some("oidc") => {
99 if let Some(bundle) = load_oidc_token(gateway_name) {
100 if is_token_expired(&bundle) {
101 match oidc_refresh_token(&bundle, tls_opts.gateway_insecure).await {
102 Ok(refreshed) => {
103 let _ = store_oidc_token(gateway_name, &refreshed);
104 tls_opts.oidc_token = Some(refreshed.access_token);
105 }
106 Err(_) => {
107 tls_opts.oidc_token = Some(bundle.access_token);
108 }
109 }
110 } else {
111 tls_opts.oidc_token = Some(bundle.access_token);
112 }
113 }
114 }
115 Some("cloudflare_jwt") => {
116 if let Some(token) = load_edge_token(gateway_name) {
117 tls_opts.edge_token = Some(token);
118 }
119 }
120 _ => {}
121 }
122 }
123
124 let channel = build_channel(server, &tls_opts).await.ok()?;
125 let interceptor = EdgeAuthInterceptor::new(
126 tls_opts.oidc_token.as_deref(),
127 tls_opts.edge_token.as_deref(),
128 )
129 .ok()?;
130 Some(OpenShellClient::with_interceptor(channel, interceptor))
131}
132
133/// Run an async future on a dedicated thread to avoid nested tokio runtime panics.
134///

Callers 2

complete_sandbox_namesFunction · 0.85
complete_provider_namesFunction · 0.85

Calls 9

load_gateway_metadataFunction · 0.85
load_oidc_tokenFunction · 0.85
is_token_expiredFunction · 0.85
oidc_refresh_tokenFunction · 0.85
store_oidc_tokenFunction · 0.85
load_edge_tokenFunction · 0.85
build_channelFunction · 0.85
with_gateway_nameMethod · 0.80
is_emptyMethod · 0.45

Tested by

no test coverage detected