Skip to content
Open
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
41 changes: 30 additions & 11 deletions Cargo.toml
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "clevercloud-sdk"
description = "A rust client and structures to interact with the Clever-Cloud API."
description = "A Rust client and structures to interact with the Clever-Cloud API."
version = "0.15.0"
edition = "2024"
rust-version = "1.85.0"
Expand All @@ -12,12 +12,27 @@ keywords = ["clevercloud", "sdk", "logging", "metrics", "jsonschemas"]

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

[features]
default = ["logging", "network-group"]
jsonschemas = ["dep:schemars"]
logging = ["dep:log", "oauth10a/logging", "tracing/log-always"]
metrics = ["oauth10a/metrics"]
tracing = ["oauth10a/tracing", "dep:tracing"]
network-group = ["dep:base64", "x25519-dalek", "dep:rand_core", "dep:cidr"]

[dependencies]
chrono = { version = "^0.4.40", features = ["serde"] }
oauth10a = { version = "^2.1.1", default-features = false, features = [
base64 = { version = "^0.22.1", optional = true }
chrono = { version = "^0.4.41", features = ["serde"] }
cidr = { version = "^0.3.1", features = ["serde"], optional = true }
oauth10a = { path = "../oauth10a-rust", default-features = false, features = [
"client",
"serde",
"rest",
"sse",
"zeroize",
] }
log = { version = "^0.4.26", optional = true }
log = { version = "^0.4.27", optional = true }
rand_core = { version = "^0.9.3", features = ["os_rng"], optional = true }
schemars = { version = "^0.8.22", features = [
"chrono",
"indexmap1",
Expand All @@ -30,11 +45,15 @@ serde_repr = "^0.1.20"
serde_json = "^1.0.140"
thiserror = "^2.0.12"
tracing = { version = "^0.1.41", optional = true }
uuid = { version = "^1.16.0", features = ["serde", "v4"] }
uuid = { version = "^1.17.0", features = ["serde", "v4"] }
x25519-dalek = { version = "^2.0.1", features = [
"zeroize",
"static_secrets",
], optional = true }
zeroize = { version = "^1.8.1", features = ["serde", "derive"] }
env-capture = { path = "../env-capture", features = [
"serde",
] }

[features]
default = ["logging"]
jsonschemas = ["schemars"]
logging = ["oauth10a/logging", "tracing/log-always", "log"]
metrics = ["oauth10a/metrics"]
tracing = ["oauth10a/tracing", "dep:tracing"]
[dev-dependencies]
tracing-subscriber = { version = "^0.3.19", features = ["env-filter"] }
45 changes: 24 additions & 21 deletions README.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
[![Released API docs](https://docs.rs/clevercloud-sdk/badge.svg)](https://docs.rs/clevercloud-sdk)
[![Continuous integration](https://github.com/CleverCloud/clevercloud-sdk-rust/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/CleverCloud/clevercloud-sdk-rust/actions/workflows/ci.yml)

> This crate provides structures and a client to interact with the Clever-Cloud
> API.
> This crate provides structures and a client to interact with the Clever-Cloud API.

## Status

Expand All @@ -25,17 +24,19 @@ Below, you will find an example of executing a request to get information about
myself.

```rust
use std::error::Error;

use clevercloud_sdk::{Client, v2::myself::{self, Myself}};
use clevercloud_sdk::{
Client,
oauth10a::credentials::Credentials,
v2::myself::{self, Myself},
};

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
let client = Client::from(Credentials {
token: "".to_string(),
secret: "".to_string(),
consumer_key: "".to_string(),
consumer_secret: "".to_string(),
async fn main() -> Result<(), Box<dyn core::error::Error + Send + Sync>> {
let client = Client::from(Credentials::OAuth1 {
token: "",
secret: "",
consumer_key: "",
consumer_secret: "",
});

let _myself: Myself = myself::get(&client).await?;
Expand All @@ -48,21 +49,23 @@ You could found more examples of how you could use the clevercloud-sdk by lookin

## Features

| name | description |
| ----------- |--------------------------------------------------------------------------------------------------|
| trace | Use `tracing` crate to expose traces |
| jsonschemas | Use `schemars` to add a derive instruction to generate json schemas representation of structures |
| logging | Use the `log` facility crate to print logs. Implies `oauth10a/logging` feature |
| metrics | Expose HTTP metrics through `oauth10a` crate feature. |
| name | description |
| ------------- |--------------------------------------------------------------------------------------------------|
| trace | Use `tracing` crate to expose traces |
| jsonschemas | Use `schemars` to add a derive instruction to generate json schemas representation of structures |
| logging | Use the `log` facility crate to print logs. Implies `oauth10a/logging` feature |
| metrics | Expose HTTP metrics through `oauth10a` crate feature. |
| network-group | Enables Clever-Cloud Network Group API. |

### Metrics

Below, the exposed metrics gathered by prometheus:

| name | labels | kind | description |
| -------------------------------- | --------------------------------------------------------------- | ------- | -------------------------- |
| oauth10a_client_request | endpoint: String, method: String, status: Integer | Counter | number of request on api |
| oauth10a_client_request_duration | endpoint: String, method: String, status: Integer, unit: String | Counter | duration of request on api |
| name | labels | kind | description |
| -------------------------------- | --------------------------------------------------------------- | ------- | ---------------------------------- |
| oauth10a_client_request | endpoint: String, method: String, status: Integer | Counter | number of request on API |
| oauth10a_client_request_duration | endpoint: String, method: String, status: Integer, unit: String | Counter | duration of request on API |
| oauth10a_client_sse | endpoint: String | Counter | number of events received from API |

## License

Expand Down
6 changes: 3 additions & 3 deletions examples/cleverctl/src/cfg.rs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

use std::path::PathBuf;

use clevercloud_sdk::Credentials;
use clevercloud_sdk::oauth10a::credentials::Credentials;
use config::{Config, ConfigError, File};
use serde::{Deserialize, Serialize};

// -----------------------------------------------------------------------------
// Error enumeration

#[derive(thiserror::Error, Debug)]
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("failed to load configuration from file '{0}', {1}")]
LoadConfiguration(String, ConfigError),
Expand All @@ -24,7 +24,7 @@ pub enum Error {
// -----------------------------------------------------------------------------
// Configuration structure

#[derive(Serialize, Deserialize, Eq, PartialEq, Clone, Debug)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Configuration {
#[serde(rename = "credentials", flatten)]
pub credentials: Credentials,
Expand Down
4 changes: 2 additions & 2 deletions examples/cleverctl/src/cmd/addon/config_provider/environment.rs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{
// -----------------------------------------------------------------------------
// Error enumeration

#[derive(thiserror::Error, Debug)]
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("failed to format output, {0}")]
FormatOutput(Box<cmd::Error>),
Expand All @@ -37,7 +37,7 @@ pub enum Error {
// -----------------------------------------------------------------------------
// Environment enumeration

#[derive(Subcommand, PartialEq, Eq, Clone, Debug)]
#[derive(Debug, Clone, PartialEq, Eq, Subcommand)]
pub enum Environment {
#[clap(name = "get", about = "Get environment variables")]
Get {
Expand Down
4 changes: 2 additions & 2 deletions examples/cleverctl/src/cmd/addon/config_provider/mod.rs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub mod environment;
// -----------------------------------------------------------------------------
// Error enumeration

#[derive(thiserror::Error, Debug)]
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("failed to execute command on config-provider environment, {0}")]
Environment(environment::Error),
Expand All @@ -25,7 +25,7 @@ pub enum Error {
// -----------------------------------------------------------------------------
// ConfigProvider structure

#[derive(Subcommand, Eq, PartialEq, Clone, Debug)]
#[derive(Debug, Clone, PartialEq, Eq, Subcommand)]
pub enum ConfigProvider {
#[clap(name = "environment", aliases = &["env"], subcommand, about = "Interact with config-provider environment")]
Environment(Environment),
Expand Down
4 changes: 2 additions & 2 deletions examples/cleverctl/src/cmd/addon/mod.rs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub mod config_provider;
// -----------------------------------------------------------------------------
// Error enumeration

#[derive(thiserror::Error, Debug)]
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("failed to format output, {0}")]
FormatOutput(Box<cmd::Error>),
Expand All @@ -33,7 +33,7 @@ pub enum Error {
// -----------------------------------------------------------------------------
// Addon enumeration

#[derive(Subcommand, Eq, PartialEq, Clone, Debug)]
#[derive(Debug, Clone, PartialEq, Eq, Subcommand)]
pub enum Command {
#[clap(name = "list", about = "List addons of an organisation")]
List {
Expand Down
5 changes: 2 additions & 3 deletions examples/cleverctl/src/cmd/functions/deployments.rs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

use std::{collections::BTreeMap, path::PathBuf, sync::Arc};

use clap::Subcommand;
use clevercloud_sdk::{
Client,
oauth10a::reqwest,
Expand All @@ -22,7 +21,7 @@ use crate::{
// ----------------------------------------------------------------------------
// Error

#[derive(thiserror::Error, Debug)]
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("failed to format output, {0}")]
FormatOutput(Box<cmd::Error>),
Expand All @@ -49,7 +48,7 @@ pub enum Error {
// ----------------------------------------------------------------------------
// Command

#[derive(Subcommand, PartialEq, Eq, Clone, Debug)]
#[derive(Debug, Clone, PartialEq, Eq, clap::Subcommand)]
pub enum Command {
#[clap(name = "list", aliases = &["l"], about = "List functions information of an organisation")]
List {
Expand Down
5 changes: 2 additions & 3 deletions examples/cleverctl/src/cmd/functions/mod.rs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
//! This module provides command implementation related to functions product
use std::{collections::BTreeMap, sync::Arc};

use clap::Subcommand;
use clevercloud_sdk::{Client, oauth10a::reqwest, v4::functions};
use tracing::info;

Expand All @@ -23,7 +22,7 @@ pub const DEFAULT_MAX_MEMORY: u64 = 64 * 1024 * 1024;
// -----------------------------------------------------------------------------
// Error enumeration

#[derive(thiserror::Error, Debug)]
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("failed to format output, {0}")]
FormatOutput(Box<cmd::Error>),
Expand Down Expand Up @@ -57,7 +56,7 @@ pub enum Error {
// Command

/// Command enum contains all operations that could be achieved on the user
#[derive(Subcommand, Eq, PartialEq, Clone, Debug)]
#[derive(Debug, Clone, PartialEq, Eq, clap::Subcommand)]
pub enum Command {
#[clap(name = "list", aliases = &["l"], about = "List functions information of an organisation")]
List {
Expand Down
8 changes: 4 additions & 4 deletions examples/cleverctl/src/cmd/mod.rs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub mod zone;
// -----------------------------------------------------------------------------
// Error enumeration

#[derive(thiserror::Error, Debug)]
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("failed to parse output '{0}', available options are 'json' or 'yaml'")]
ParseOutput(String),
Expand All @@ -46,7 +46,7 @@ pub enum Error {
// -----------------------------------------------------------------------------
// Output enumeration

#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Debug, Default)]
#[derive(Debug, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum Output {
#[default]
Json,
Expand Down Expand Up @@ -103,7 +103,7 @@ pub trait Executor {
// Command enumeration

/// Command enum contains all operations that the command line could handle
#[derive(Subcommand, Eq, PartialEq, Clone, Debug)]
#[derive(Debug, Clone, PartialEq, Eq, Subcommand)]
pub enum Command {
#[clap(name = "self", aliases = &["sel", "se", "s"], subcommand, about = "Interact with the current user")]
Myself(myself::Command),
Expand Down Expand Up @@ -133,7 +133,7 @@ impl Executor for Command {

/// Args structure contains all commands and global flags that the command line
/// supports
#[derive(Parser, Eq, PartialEq, Clone, Debug)]
#[derive(Debug, Clone, PartialEq, Eq, Parser)]
#[clap(author, version, about)]
pub struct Args {
/// Specify a configuration file
Expand Down
4 changes: 2 additions & 2 deletions examples/cleverctl/src/cmd/myself.rs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{
// -----------------------------------------------------------------------------
// Error enumeration

#[derive(thiserror::Error, Debug)]
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("failed to format output, {0}")]
FormatOutput(Box<cmd::Error>),
Expand All @@ -28,7 +28,7 @@ pub enum Error {
// Command enumeration

/// Command enum contains all operations that could be achieved on the user
#[derive(Subcommand, Eq, PartialEq, Clone, Debug)]
#[derive(Debug, Clone, PartialEq, Eq, Subcommand)]
pub enum Command {
#[clap(name = "get", aliases = &["ge", "g"], about = "Get information about the current user")]
Get {
Expand Down
7 changes: 3 additions & 4 deletions examples/cleverctl/src/cmd/zone.rs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
//! This module provides command implementation related to the zone API
use std::sync::Arc;

use clap::Subcommand;
use clevercloud_sdk::{Client, oauth10a::reqwest, v4::products::zones};

use crate::{
Expand All @@ -14,7 +13,7 @@ use crate::{
// -----------------------------------------------------------------------------
// Error enumeration

#[derive(thiserror::Error, Debug)]
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("failed to format output, {0}")]
FormatOutput(Box<cmd::Error>),
Expand All @@ -28,7 +27,7 @@ pub enum Error {
// Command enumeration

/// Command enum contains all operations that could be achieved on the zone API
#[derive(Subcommand, Eq, PartialEq, Clone, Debug)]
#[derive(Debug, Clone, PartialEq, Eq, clap::Subcommand)]
pub enum Command {
#[clap(name = "list", aliases = &["l"], about = "List available zones")]
List {
Expand Down Expand Up @@ -66,7 +65,7 @@ impl Executor for Command {
// helpers

pub async fn list(config: Arc<Configuration>, output: &Output) -> Result<(), Error> {
let client = Client::from(config.credentials.to_owned());
let client = Client::from(&config.credentials);
let zones = zones::list(&client).await.map_err(Error::List)?;

println!(
Expand Down
2 changes: 1 addition & 1 deletion examples/cleverctl/src/logging.rs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use tracing::Level;
// -----------------------------------------------------------------------------
// Error enumeration

#[derive(thiserror::Error, Debug)]
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("failed to set global default subscriber, {0}")]
GlobalDefaultSubscriber(tracing::subscriber::SetGlobalDefaultError),
Expand Down
2 changes: 1 addition & 1 deletion examples/cleverctl/src/main.rs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub mod logging;
// -----------------------------------------------------------------------------
// Error enumeration

#[derive(thiserror::Error, Debug)]
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("failed to load configuration, {0}")]
Configuration(cfg::Error),
Expand Down
Loading
Loading