(
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
| 106 | |
| 107 | impl 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( |
nothing calls this directly
no test coverage detected