Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

1130 v2 clients #37

Merged
merged 9 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ jobs:
- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
toolchain: stable
override: false
components: rustfmt, clippy
- name: Check formatting
run: cargo +nightly fmt -- --check
run: cargo fmt -- --check
- name: Clippy
run: cargo clippy -- -Dwarnings
- name: Tests
Expand Down
49 changes: 6 additions & 43 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ description = "Command line interface for Golem Cloud"

[dependencies]
async-trait = "0.1.74"
chrono = "0.4.31"
chrono = { version = "0.4.31", features = ["serde"] }
clap = { version = "4.4.6", features = ["derive"] }
clap-verbosity-flag = "2.0.1"
derive_more = "0.99.17"
futures-util = "0.3.28"
golem-client = "0.0.47"
golem-gateway-client = "0.0.47"
golem-client = "0.0.48"
golem-gateway-client = "0.0.48"
golem-examples = "0.1.9"
http = "0.2.9"
indoc = "2.0.4"
itertools = "0.11.0"
native-tls = "0.2.11"
reqwest = "0.11.22"
reqwest = { version = "0.11.22", features = ["stream", "json", "multipart"] }
serde = { version = "1.0.189", features = ["derive"] }
serde_json = "1.0.107"
serde_yaml = "0.9.25"
Expand Down
18 changes: 9 additions & 9 deletions src/account.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use async_trait::async_trait;
use clap::Subcommand;
use golem_client::model::AccountData;
use golem_client::models::AccountData;

use crate::clients::account::AccountClient;
use crate::clients::grant::GrantClient;
Expand Down Expand Up @@ -90,18 +90,18 @@ impl<C: AccountClient + Sync + Send, G: GrantClient + Sync + Send> AccountHandle

match subcommand {
AccountSubcommand::Get {} => {
let account = self.client.get(&account_id, auth).await?;
let account = self.client.get(&account_id).await?;
Ok(GolemResult::Ok(Box::new(account)))
}
AccountSubcommand::Update {
account_name,
account_email,
} => {
let existing = self.client.get(&account_id, auth).await?;
let existing = self.client.get(&account_id).await?;
let name = account_name.unwrap_or(existing.name);
let email = account_email.unwrap_or(existing.email);
let updated = AccountData { name, email };
let account = self.client.put(&account_id, updated, auth).await?;
let account = self.client.put(&account_id, updated).await?;
Ok(GolemResult::Ok(Box::new(account)))
}
AccountSubcommand::Add {
Expand All @@ -113,27 +113,27 @@ impl<C: AccountClient + Sync + Send, G: GrantClient + Sync + Send> AccountHandle
email: account_email,
};

let account = self.client.post(data, auth).await?;
let account = self.client.post(data).await?;

Ok(GolemResult::Ok(Box::new(account)))
}
AccountSubcommand::Delete {} => {
self.client.delete(&account_id, auth).await?;
self.client.delete(&account_id).await?;
Ok(GolemResult::Str("Deleted".to_string()))
}
AccountSubcommand::Grant { subcommand } => match subcommand {
GrantSubcommand::Get {} => {
let roles = self.grant.get_all(account_id, auth).await?;
let roles = self.grant.get_all(account_id).await?;

Ok(GolemResult::Ok(Box::new(roles)))
}
GrantSubcommand::Add { role } => {
self.grant.put(account_id, role, auth).await?;
self.grant.put(account_id, role).await?;

Ok(GolemResult::Ok(Box::new("RoleGranted".to_string())))
}
GrantSubcommand::Delete { role } => {
self.grant.put(account_id, role, auth).await?;
self.grant.put(account_id, role).await?;

Ok(GolemResult::Ok(Box::new("RoleRemoved".to_string())))
}
Expand Down
26 changes: 15 additions & 11 deletions src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::path::{Path, PathBuf};

use async_trait::async_trait;
use chrono::{DateTime, Utc};
use golem_client::model::{OAuth2Data, Token, TokenSecret, UnsafeToken};
use golem_client::models::{OAuth2Data, Token, TokenSecret, UnsafeToken};
use indoc::printdoc;
use serde::{Deserialize, Serialize};
use tracing::info;
Expand Down Expand Up @@ -54,13 +54,13 @@ impl<L: LoginClient + Send + Sync> AuthLive<L> {

match parsed {
Ok(conf) => Some(CloudAuthentication(UnsafeToken {
data: Token {
data: Box::new(Token {
id: conf.data.id,
account_id: conf.data.account_id,
created_at: conf.data.created_at,
expires_at: conf.data.expires_at,
},
secret: TokenSecret { value: conf.secret },
created_at: conf.data.created_at.to_string(),
expires_at: conf.data.expires_at.to_string(),
}),
secret: Box::new(TokenSecret { value: conf.secret }),
})),
Err(err) => {
info!("Parsing failed: {err}"); // TODO configure
Expand Down Expand Up @@ -97,8 +97,8 @@ impl<L: LoginClient + Send + Sync> AuthLive<L> {
data: CloudAuthenticationConfigData {
id: token.data.id,
account_id: token.data.account_id.clone(),
created_at: token.data.created_at,
expires_at: token.data.expires_at,
created_at: token.data.created_at.parse().unwrap(),
expires_at: token.data.expires_at.parse().unwrap(),
},
secret: token.secret.value,
};
Expand Down Expand Up @@ -132,8 +132,9 @@ impl<L: LoginClient + Send + Sync> AuthLive<L> {
fn inform_user(data: &OAuth2Data) {
let box_url_line = String::from_utf8(vec![b'-'; data.url.len() + 2]).unwrap();
let box_code_line = String::from_utf8(vec![b'-'; data.user_code.len() + 2]).unwrap();
let expires_in = data.expires.signed_duration_since(Utc::now()).num_minutes();
let expires_at = data.expires.format("%T");
let expires: DateTime<Utc> = data.expires.parse().unwrap();
let expires_in = expires.signed_duration_since(Utc::now()).num_minutes();
let expires_at = expires.format("%T");
let url = &data.url;
let user_code = &data.user_code;

Expand Down Expand Up @@ -173,7 +174,10 @@ impl<L: LoginClient + Send + Sync> Auth for AuthLive<L> {
};
let data = self.login.token_details(secret.clone()).await?;

Ok(CloudAuthentication(UnsafeToken { data, secret }))
Ok(CloudAuthentication(UnsafeToken {
data: Box::new(data),
secret: Box::new(secret),
}))
} else {
self.config_authentication(config_dir).await
}
Expand Down
29 changes: 15 additions & 14 deletions src/clients.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use golem_client::model::{TokenSecret, UnsafeToken};
use golem_client::models::{TokenSecret, UnsafeToken};

use crate::model::{AccountId, ProjectAction};

pub mod account;
pub mod errors;
pub mod gateway;
pub mod grant;
pub mod login;
Expand All @@ -17,7 +18,7 @@ pub fn token_header(secret: &TokenSecret) -> String {
format!("bearer {}", secret.value)
}

#[derive(Clone, PartialEq, Eq, Debug)]
#[derive(Clone, PartialEq, Debug)]
pub struct CloudAuthentication(pub UnsafeToken);

impl CloudAuthentication {
Expand All @@ -36,24 +37,24 @@ impl CloudAuthentication {
}
}

pub fn action_cli_to_api(action: ProjectAction) -> golem_client::model::ProjectAction {
pub fn action_cli_to_api(action: ProjectAction) -> golem_client::models::ProjectAction {
match action {
ProjectAction::ViewTemplate => golem_client::model::ProjectAction::ViewComponent {},
ProjectAction::CreateTemplate => golem_client::model::ProjectAction::CreateComponent {},
ProjectAction::UpdateTemplate => golem_client::model::ProjectAction::UpdateComponent {},
ProjectAction::DeleteTemplate => golem_client::model::ProjectAction::DeleteComponent {},
ProjectAction::ViewWorker => golem_client::model::ProjectAction::ViewInstance {},
ProjectAction::CreateWorker => golem_client::model::ProjectAction::CreateInstance {},
ProjectAction::UpdateWorker => golem_client::model::ProjectAction::UpdateInstance {},
ProjectAction::DeleteWorker => golem_client::model::ProjectAction::DeleteInstance {},
ProjectAction::ViewTemplate => golem_client::models::ProjectAction::ViewTemplate {},
ProjectAction::CreateTemplate => golem_client::models::ProjectAction::CreateTemplate {},
ProjectAction::UpdateTemplate => golem_client::models::ProjectAction::UpdateTemplate {},
ProjectAction::DeleteTemplate => golem_client::models::ProjectAction::DeleteTemplate {},
ProjectAction::ViewWorker => golem_client::models::ProjectAction::ViewWorker {},
ProjectAction::CreateWorker => golem_client::models::ProjectAction::CreateWorker {},
ProjectAction::UpdateWorker => golem_client::models::ProjectAction::UpdateWorker {},
ProjectAction::DeleteWorker => golem_client::models::ProjectAction::DeleteWorker {},
ProjectAction::ViewProjectGrants => {
golem_client::model::ProjectAction::ViewProjectGrants {}
golem_client::models::ProjectAction::ViewProjectGrants {}
}
ProjectAction::CreateProjectGrants => {
golem_client::model::ProjectAction::CreateProjectGrants {}
golem_client::models::ProjectAction::CreateProjectGrants {}
}
ProjectAction::DeleteProjectGrants => {
golem_client::model::ProjectAction::DeleteProjectGrants {}
golem_client::models::ProjectAction::DeleteProjectGrants {}
}
}
}
Loading
Loading