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

Commit

Permalink
Merge pull request #12 from golemcloud/ci-and-readme
Browse files Browse the repository at this point in the history
Added a README and Github CI
  • Loading branch information
vigoo authored Sep 6, 2023
2 parents 0178d44 + 35a7db4 commit 8a962e5
Show file tree
Hide file tree
Showing 26 changed files with 1,643 additions and 630 deletions.
81 changes: 81 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: CI
on:
push:
tags:
- 'v*.*.*'
branches:
- main
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: true
- uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}-is

- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
override: false
components: rustfmt, clippy
- name: Check formatting
run: cargo +nightly fmt -- --check
- name: Clippy
run: cargo clippy -- -Dwarnings
- name: Tests
run: cargo test --all-features
publish:
needs: [ build ]
if: "startsWith(github.ref, 'refs/tags/v')"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: true
- uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}-is

- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- id: get_version
uses: battila7/get-version-action@v2
- name: Publish crate
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: |
export VERSION="${{ steps.get_version.outputs.version-without-v }}"
sed -i "s/0.0.0/$VERSION/g" Cargo.toml
cargo publish --all-features --allow-dirty
2 changes: 1 addition & 1 deletion Cargo.lock

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

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
[package]
name = "golem-cli"
version = "0.1.0"
version = "0.0.0"
edition = "2021"
license = "Apache-2.0"
homepage = "https://www.golem.cloud/"
authors = ["Simon Popugaev <simon.popugaev@ziverge.com>"]
readme = false
readme = "README.md"
description = "Command line interface for Golem Cloud"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# golem-cli

Command line interface for [Golem Cloud](https://golem.cloud).


## Installation

To install `golem-cli` you currently need to use `cargo`, Rust's build tool.

To get `cargo` on your system, we recommend to use [rustup](https://rustup.rs/):

```shell
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustup install stable
rustup default stable
```

Then you can install `golem-cli` with the following command:

```shell
cargo install golem-cli
```

## More information
Please check the [Golem Cloud developer documentation portal](https://www.golem.cloud/learn) to learn more about how to get started with *Golem Cloud*!
1 change: 1 addition & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
too-many-arguments-threshold = 20
91 changes: 51 additions & 40 deletions src/account.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use crate::clients::account::AccountClient;
use crate::clients::grant::GrantClient;
use crate::clients::CloudAuthentication;
use crate::model::{AccountId, GolemError, GolemResult, Role};
use async_trait::async_trait;
use clap::Subcommand;
use golem_client::model::AccountData;
use crate::model::{AccountId, GolemError, GolemResult, Role};
use crate::clients::account::AccountClient;
use crate::clients::CloudAuthentication;
use crate::clients::grant::GrantClient;


#[derive(Subcommand, Debug)]
#[command()]
Expand Down Expand Up @@ -40,7 +39,6 @@ pub enum AccountSubcommand {
#[command(subcommand)]
subcommand: GrantSubcommand,
},

}

#[derive(Subcommand, Debug)]
Expand All @@ -52,80 +50,93 @@ pub enum GrantSubcommand {
#[command()]
Add {
#[arg(value_name = "ROLE")]
role: Role
role: Role,
},

#[command()]
Delete {
#[arg(value_name = "ROLE")]
role: Role
role: Role,
},
}

#[async_trait]
pub trait AccountHandler {
async fn handle(&self, token: &CloudAuthentication, account_id: Option<AccountId>, subcommand: AccountSubcommand) -> Result<GolemResult, GolemError>;
async fn handle(
&self,
token: &CloudAuthentication,
account_id: Option<AccountId>,
subcommand: AccountSubcommand,
) -> Result<GolemResult, GolemError>;
}

pub struct AccountHandlerLive<C: AccountClient + Sync + Send, G: GrantClient + Sync + Send> {
pub client: C,
pub grant: G
pub grant: G,
}

#[async_trait]
impl<C: AccountClient + Sync + Send, G: GrantClient + Sync + Send> AccountHandler for AccountHandlerLive<C, G> {
async fn handle(&self, auth: &CloudAuthentication, account_id: Option<AccountId>, subcommand: AccountSubcommand) -> Result<GolemResult, GolemError> {
impl<C: AccountClient + Sync + Send, G: GrantClient + Sync + Send> AccountHandler
for AccountHandlerLive<C, G>
{
async fn handle(
&self,
auth: &CloudAuthentication,
account_id: Option<AccountId>,
subcommand: AccountSubcommand,
) -> Result<GolemResult, GolemError> {
let account_id = account_id.unwrap_or(auth.account_id());

match subcommand {
AccountSubcommand::Get { } => {
AccountSubcommand::Get {} => {
let account = self.client.get(&account_id, auth).await?;
Ok(GolemResult::Ok(Box::new(account)))
}
AccountSubcommand::Update { account_name, account_email } => {
AccountSubcommand::Update {
account_name,
account_email,
} => {
let existing = self.client.get(&account_id, auth).await?;
let name = account_name.unwrap_or(existing.name);
let email = account_email.unwrap_or(existing.email);
let updated = AccountData {
name,
email
};
let updated = AccountData { name, email };
let account = self.client.put(&account_id, updated, auth).await?;
Ok(GolemResult::Ok(Box::new(account)))
}
AccountSubcommand::New { account_name, account_email } => {
AccountSubcommand::New {
account_name,
account_email,
} => {
let data = AccountData {
name: account_name,
email: account_email
email: account_email,
};

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

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

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

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

Ok(GolemResult::Ok(Box::new("RoleRemoved".to_string())))
}
AccountSubcommand::Grant { subcommand } => match subcommand {
GrantSubcommand::Get {} => {
let roles = self.grant.get_all(account_id, auth).await?;

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

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

Ok(GolemResult::Ok(Box::new("RoleRemoved".to_string())))
}
},
}
}
}
}
Loading

0 comments on commit 8a962e5

Please sign in to comment.