Skip to content

Commit

Permalink
54 is_active with tokio::select!
Browse files Browse the repository at this point in the history
  • Loading branch information
smart--petea committed Apr 20, 2024
1 parent 326619f commit 67b8538
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 53 deletions.
38 changes: 2 additions & 36 deletions src/console/commands/debug/dockerhub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,43 +26,9 @@ impl crate::console::commands::CallableTrait for DockerhubCommand {
println!("{}", self.json);
let dockerImage: DockerImage = serde_json::from_str(&self.json)?;
let mut dockerhub = DockerHub::try_from(&dockerImage)?;
/*
if dockerhub.creds.username.is_empty() {
*/
let lookupOfficialRepos = dockerhub.lookup_official_repos();
let lookupPublicRepos = dockerhub.lookup_public_repos();
let lookupPublicRepos1 = dockerhub.lookup_public_repos();
tokio::select! {
Ok(true) = lookupOfficialRepos => {println!("lookup oficial repos"); }
Ok(true) = lookupPublicRepos => {println!("lookup public repos"); }
Ok(true) = lookupPublicRepos1 => {println!("lookup public repos1"); }
//todo add timer
//complete => { println!("complete"); }
//default => { println!("no good result"); }
else => { println!("nothing found") }
}
/*
if Ok(true) == dockerhub.lookup_official_repos().await {
println!("official: true");
return Ok(());
} else {
println!("official: false");
};
let isActive = dockerhub.is_active().await?;

if Ok(true) == dockerhub.lookup_public_repos().await {
println!("public: true");
return Ok(());
};
*/
/*
} else {
println!("username is not empty");
if Ok(true) == dockerhub.lookup_private_repo().await {
tracing::debug!("private: true");
return Ok(());
};
}
*/
println!("image is active: {isActive}");

Ok(())
})
Expand Down
32 changes: 15 additions & 17 deletions src/helpers/dockerhub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,15 @@ impl<'a> DockerHub<'a> {
}

pub async fn lookup_private_repo(&'a self) -> Result<bool, String> {
if self.creds.username.is_empty() {
return Ok(false);
}

let url = format!(
"https://hub.docker.com/v2/namespaces/{}/repositories/{}/tags",
&self.creds.username, &self.repos
);

tracing::debug!("Validate image {:?}", url);
let client = reqwest::Client::new()
.get(url)
Expand Down Expand Up @@ -262,30 +267,23 @@ impl<'a> DockerHub<'a> {
// }
// }

if self.creds.username.is_empty() {

if Ok(true) == self.lookup_official_repos().await {
tracing::debug!("official: true");
return Ok(true);
} else {
tracing::debug!("official: false");
};
tokio::select! {
Ok(true) = self.lookup_official_repos() => {
tracing::debug!("official: true");
return Ok(true);
}

if Ok(true) == self.lookup_public_repos().await {
Ok(true) = self.lookup_public_repos() => {
tracing::debug!("public: true");
return Ok(true);
};

Ok(false)

} else {
}

if Ok(true) == self.lookup_private_repo().await {
Ok(true) = self.lookup_private_repo() => {
tracing::debug!("private: true");
return Ok(true);
};
}

Ok(false)
else => { return Ok(false); }
}
}

Expand Down

0 comments on commit 67b8538

Please sign in to comment.