gsaslis / radicle-ci-broker

A placeholder project to use for issue tracking
0 stars 0 forks source link

Code improvements in src/concourse/api.rs from code review #16

Open Archimidis opened 1 year ago

Archimidis commented 1 year ago
pub struct Token {
    pub access_token: String,
    pub expires_in: i64,
    pub id_token: String,
    pub token_type: String,
}

The field expires_in should be of type std::time::Duration. Is it possible for the String types to use the newtype idiom? Is it possible to declare the field token_type type as an enum? Can secstr be used for the access_token field? fintohaps suggested this for accepting passwords, but he recall that it might not have zeroed correctly. Cloudhead suggested to use Passphrase which is Zeroizing<String>.

fn setup(&mut self, project_name: String, patch_branch: String, patch_head: String, project_id: &String, git_uri: String) -> Result<(), anyhow::Error>;

Use Options or Config struct for the setup parameters.

            .header(AUTHORIZATION, format!("Bearer {}", self.token.as_ref().unwrap().access_token))

Test safety of unwrap when getting the access token

Archimidis commented 1 year ago

The crate secstr was used for the access_token field.

Archimidis commented 1 year ago

Wrote a serde field deserializer for expire_in that transforms an epoch to std::time::Duration.

Archimidis commented 1 year ago

The field token_type is now an enum and has it's own custom deserializer.

Archimidis commented 1 year ago

Function parameters of setup of CI trait are gathered under the CIJob struct.

Archimidis commented 1 year ago

Implemented check in ConcourseAPI that checks if an access token exists. Issue #19 is created to further enhance this functionality.