MCPcopy Create free account
hub / github.com/aws/amazon-q-developer-cli / new

Method new

crates/chat-cli/src/api_client/mod.rs:108–225  ·  view source on GitHub ↗
(
        env: &Env,
        fs: &Fs,
        database: &mut Database,
        // endpoint is only passed here for list_profiles where it needs to be called for each region
        endpoint: Option<En

Source from the content-addressed store, hash-verified

106
107impl ApiClient {
108 pub async fn new(
109 env: &Env,
110 fs: &Fs,
111 database: &mut Database,
112 // endpoint is only passed here for list_profiles where it needs to be called for each region
113 endpoint: Option<Endpoint>,
114 ) -> Result<Self, ApiClientError> {
115 let endpoint = endpoint.unwrap_or(Endpoint::configured_value(database));
116
117 let credentials = Credentials::new("xxx", "xxx", None, None, "xxx");
118 let bearer_sdk_config = aws_config::defaults(behavior_version())
119 .region(endpoint.region.clone())
120 .credentials_provider(credentials)
121 .timeout_config(timeout_config(database))
122 .retry_config(retry_config())
123 .load()
124 .await;
125
126 let client = CodewhispererClient::from_conf(
127 amzn_codewhisperer_client::config::Builder::from(&bearer_sdk_config)
128 .http_client(crate::aws_common::http_client::client())
129 .interceptor(OptOutInterceptor::new(database))
130 .interceptor(UserAgentOverrideInterceptor::new())
131 .bearer_token_resolver(BearerResolver)
132 .app_name(app_name())
133 .endpoint_url(endpoint.url())
134 .build(),
135 );
136
137 if cfg!(test) && !is_integ_test() {
138 let mut this = Self {
139 client,
140 streaming_client: None,
141 sigv4_streaming_client: None,
142 mock_client: None,
143 profile: None,
144 model_cache: Arc::new(RwLock::new(None)),
145 };
146
147 if let Some(json) = crate::util::env_var::get_mock_chat_response(env) {
148 this.set_mock_output(serde_json::from_str(fs.read_to_string(json).await.unwrap().as_str()).unwrap());
149 }
150
151 return Ok(this);
152 }
153
154 // If SIGV4_AUTH_ENABLED is true, use Q developer client
155 let mut streaming_client = None;
156 let mut sigv4_streaming_client = None;
157 match crate::util::env_var::is_sigv4_enabled(env) {
158 true => {
159 let credentials_chain = CredentialsChain::new().await;
160 if let Err(err) = credentials_chain.provide_credentials().await {
161 return Err(ApiClientError::Credentials(err));
162 };
163
164 sigv4_streaming_client = Some(QDeveloperStreamingClient::from_conf(
165 amzn_qdeveloper_streaming_client::config::Builder::from(

Callers

nothing calls this directly

Calls 15

behavior_versionFunction · 0.85
timeout_configFunction · 0.85
retry_configFunction · 0.85
app_nameFunction · 0.85
get_mock_chat_responseFunction · 0.85
is_sigv4_enabledFunction · 0.85
set_mock_outputMethod · 0.80
read_to_stringMethod · 0.80
get_auth_profileMethod · 0.80
clientFunction · 0.50
is_integ_testFunction · 0.50

Tested by

no test coverage detected