async fn authenticate(
        &self,
        username: &str,
        password: &str,
        token_name: &str,
    ) -> Result<AuthenticatedClient, AuthenticateError> {
        let body = json!({
            "name": token_name,
            "permissions": [{
                "domain": "api",
                "resource": "write",
            }],
        });

        let response = self
            .http_client()
            .post(self.api_base_url().join("keys").unwrap())
            .basic_auth(username, Some(password))
            .json(&body)
            .send()
            .await?;

        match response.status() {
            StatusCode::CREATED => {
                let body: AuthenticateResponseCreated = response.json().await?;
                Ok(AuthenticatedClient {
                    repository_base: self.repository_base_url().clone(),
                    api_base: self.api_base_url().clone(),
                    api_token: body.secret,
                })
            }

            StatusCode::TOO_MANY_REQUESTS => Err(AuthenticateError::RateLimited),

            StatusCode::UNAUTHORIZED => Err(AuthenticateError::InvalidCredentials),

            status => Err(AuthenticateError::UnexpectedResponse(
                status,
                response.text().await.unwrap_or_default(),
            )),
        }
    }
/// Authenticate with the Hex API using a username and password in order
/// to get an API token, enabling accessing of more APIs and raising the
/// rate limit.
Authenticate with the Hex API using a username and password in order
to get an API token, enabling accessing of more APIs and raising the
rate limit.
Authenticate with the Hex API using a username and password in order to get an API token enabling accessing of more APIs and raising the rate limit .
async fn authenticate(
        &self,
        username: &str,
        password: &str,
        token_name: &str,
    ) -> Result<AuthenticatedClient, AuthenticateError> {
        let body = json!({
            "name": token_name,
            "permissions": [{
                "domain": "api",
                "resource": "write",
            }],
        });
        let response = self
            .http_client()
            .post(self.api_base_url().join("keys").unwrap())
            .basic_auth(username, Some(password))
            .json(&body)
            .send()
            .await?;
        match response.status() {
            StatusCode::CREATED => {
                let body: AuthenticateResponseCreated = response.json().await?;
                Ok(AuthenticatedClient {
                    repository_base: self.repository_base_url().clone(),
                    api_base: self.api_base_url().clone(),
                    api_token: body.secret,
                })
            }
            StatusCode::TOO_MANY_REQUESTS => Err(AuthenticateError::RateLimited),
            StatusCode::UNAUTHORIZED => Err(AuthenticateError::InvalidCredentials),
            status => Err(AuthenticateError::UnexpectedResponse(
                status,
                response.text().await.unwrap_or_default(),
            )),
        }
    }
async fn authenticate ( & self , username : & str , password : & str , token_name : & str , ) -> Result < AuthenticatedClient , AuthenticateError > { let body = json ! ( { " " token_name " " [ { " " " " " " " " } ] } ) ; let response = self . http_client ( ) . post ( self . api_base_url ( ) . join ( " " ) . unwrap ( ) ) . basic_auth ( username , Some ( password ) ) . json ( & body ) . send ( ) . await ? ; match response . status ( ) { StatusCode :: CREATED => { let body : AuthenticateResponseCreated = response . json ( ) . await ? ; Ok ( AuthenticatedClient { repository_base : self . repository_base_url ( ) . clone ( ) , api_base : self . api_base_url ( ) . clone ( ) , api_token : body . secret , } ) } StatusCode :: TOO_MANY_REQUESTS => Err ( AuthenticateError :: RateLimited ) , StatusCode :: UNAUTHORIZED => Err ( AuthenticateError :: InvalidCredentials ) , status => Err ( AuthenticateError :: UnexpectedResponse ( status , response . text ( ) . await . unwrap_or_default ( ) , ) ) , } }
Authenticate with the Hex API using a username and password in order
to get an API token, enabling accessing of more APIs and raising the
rate limit.
Authenticate with the Hex API using a username and password in order to get an API token enabling accessing of more APIs and raising the rate limit .
&self
username
&str
password
&str
token_name
&str
&self
username
&str
password
&str
token_name
&str