Skip to content

Commit 87dcd74

Browse files
committed
2 parents 2fc3a0b + 63fbe3e commit 87dcd74

File tree

1,509 files changed

+170878
-22373
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,509 files changed

+170878
-22373
lines changed
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
name: security audit
22
on:
3-
workflow_dispatch:
43
push:
54
paths:
65
- '**/Cargo.toml'
76
- '**/Cargo.lock'
87
schedule:
98
- cron: '5 4 * * 6'
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref_protected && github.run_id || github.event.pull_request.number || github.ref }}
11+
cancel-in-progress: true
1012
jobs:
1113
security_audit:
1214
runs-on: ubuntu-latest
1315
steps:
1416
- uses: actions/checkout@v4
15-
- uses: actions-rs/toolchain@v1
17+
- uses: dtolnay/rust-toolchain@stable
1618
with:
17-
profile: minimal
1819
toolchain: stable
1920
components: rustfmt, clippy
2021
- run: cargo install cargo-audit && cargo audit || true && cargo audit

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ members = [
1313
"examples/kms-client",
1414
"examples/id-token",
1515
"examples/iam-client",
16+
"examples/artifact-registry-client",
17+
"examples/servicecontrol-client",
1618
]

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ More complete examples are located [here](examples).
5353
Cargo.toml:
5454
```toml
5555
[dependencies]
56-
gcloud-sdk = { version = "0.25", features = ["google-firestore-v1"] }
56+
gcloud-sdk = { version = "0.26", features = ["google-firestore-v1"] }
5757
```
5858

5959
## Example for REST API
@@ -87,8 +87,8 @@ Looks for credentials in the following places, preferring the first location fou
8787
The library provides the support for workload identity federation support to use "keyless" integrations with different providers:
8888
- URL based OIDC/SAML (for example GitHub actions) with text/json file formats;
8989
- File based OIDC/SAML with text/json file formats;
90-
91-
AWS provider is not supported yet (feel free to open a PR to support, https://github.com/abdolence/gcloud-sdk-rs/issues/29).
90+
- AWS external account: authentication from AWS computing instances(e.g. EC2, lambda, ECS, etc.) is now supported as "external-account-aws" feature in https://github.com/abdolence/gcloud-sdk-rs/pull/172.
91+
However, it is not intensively tested yet, so please report issues if there's a problem.
9292

9393
### Local development
9494
Don't confuse `gcloud auth login` with `gcloud auth application-default login` for local development,
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
name = "artifact-registry-client-example"
3+
version = "0.3.0"
4+
authors = ["grundjoseph@gmail.com"]
5+
edition = "2021"
6+
7+
[dependencies]
8+
gcloud-sdk = { path = "./../../gcloud-sdk", default-features = false, features = ["google-devtools-artifactregistry-v1", "tls-webpki-roots"] }
9+
tokio = { version = "1.20", features = ["full"] }
10+
tracing = "0.1"
11+
tracing-subscriber = { version ="0.3", features = ["env-filter"] }
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
use gcloud_sdk::google::devtools::artifactregistry::v1::{
2+
artifact_registry_client::ArtifactRegistryClient, ListRepositoriesRequest,
3+
};
4+
use gcloud_sdk::*;
5+
6+
#[tokio::main]
7+
async fn main() -> Result<(), Box<dyn std::error::Error>> {
8+
// Debug logging
9+
let subscriber = tracing_subscriber::fmt()
10+
.with_env_filter("gcloud_sdk=debug")
11+
.finish();
12+
tracing::subscriber::set_global_default(subscriber)?;
13+
14+
// Detect Google project ID using environment variables PROJECT_ID/GCP_PROJECT_ID
15+
// or GKE metadata server when the app runs inside GKE
16+
let google_project_id = GoogleEnvironment::detect_google_project_id().await
17+
.expect("No Google Project ID detected. Please specify it explicitly using env variable: PROJECT_ID");
18+
19+
let artifactregistry_client: GoogleApi<ArtifactRegistryClient<GoogleAuthMiddleware>> =
20+
GoogleApi::from_function(
21+
ArtifactRegistryClient::new,
22+
"https://artifactregistry.googleapis.com",
23+
// cloud resource prefix: used only for some of the APIs (such as Firestore)
24+
None,
25+
)
26+
.await?;
27+
28+
let response = artifactregistry_client
29+
.get()
30+
.list_repositories(tonic::Request::new(ListRepositoriesRequest {
31+
parent: format!("projects/{google_project_id}/locations/us"),
32+
..Default::default()
33+
}))
34+
.await?;
35+
36+
println!("Response from artifactregistry: {response:?}");
37+
38+
Ok(())
39+
}

examples/gcs-rest-client/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ authors = ["me@abdolence.dev"]
55
edition = "2021"
66

77
[dependencies]
8-
gcloud-sdk = { path = "./../../gcloud-sdk", default-features = false, features = ["rest", "google-rest-storage-v1", "google-rest-compute-v1"] }
8+
gcloud-sdk = { path = "./../../gcloud-sdk", default-features = false, features = ["google-rest-storage-v1", "google-rest-compute-v1","tls-webpki-roots"] }
99
tokio = { version = "1.20", features = ["full"] }
1010
tracing = "0.1"
1111
tracing-subscriber = { version ="0.3", features = ["env-filter"] }

examples/gcs-rest-client/src/main.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,21 @@ async fn test_compute() {
7272

7373
let google_rest_client = gcloud_sdk::GoogleRestApi::new().await.unwrap();
7474

75+
let compute_config = google_rest_client
76+
.create_google_compute_v1_config()
77+
.await
78+
.unwrap();
79+
let request = gcloud_sdk::google_rest_apis::compute_v1::instances_api::ComputePeriodInstancesPeriodListParams {
80+
project: google_project_id.to_string(),
81+
zone: "us-central1-a".into(),
82+
..Default::default()
83+
};
7584
let response = gcloud_sdk::google_rest_apis::compute_v1::instances_api::compute_instances_list(
76-
&google_rest_client.create_google_compute_v1_config().await.unwrap(),
77-
gcloud_sdk::google_rest_apis::compute_v1::instances_api::ComputePeriodInstancesPeriodListParams {
78-
project: google_project_id.to_string(),
79-
zone: "us-central1-a".to_string(),
80-
..Default::default()
81-
}
82-
).await.unwrap();
85+
&compute_config,
86+
request,
87+
)
88+
.await
89+
.unwrap();
8390

8491
println!("{:?}", response);
8592
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[package]
2+
name = "servicecontrol-client"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
chrono = "0.4.39"
8+
gcloud-sdk = { path = "./../../gcloud-sdk", default-features = false, features = ["google-rest-servicecontrol-v1", "tls-webpki-roots"] }
9+
serde_json = "1.0.138"
10+
thiserror = "2.0.11"
11+
tokio = { version = "1.20", features = ["full"] }
12+
uuid = { version = "1.8", default-features = false, features = ["v4"] }
13+
14+
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
use gcloud_sdk::{google_rest_apis::servicecontrol_v1, GoogleEnvironment, GoogleRestApi};
2+
3+
#[derive(thiserror::Error, Debug)]
4+
enum Error {
5+
#[error(transparent)]
6+
Gcloud(#[from] gcloud_sdk::error::Error),
7+
#[error(transparent)]
8+
ServiceCheck(
9+
#[from]
10+
servicecontrol_v1::Error<
11+
servicecontrol_v1::services_api::ServicecontrolPeriodServicesPeriodCheckError,
12+
>,
13+
),
14+
#[error("{}", format_check_errors(.0))]
15+
ServiceCheckErrors(Vec<servicecontrol_v1::CheckError>),
16+
}
17+
18+
fn format_check_errors(errs: &[servicecontrol_v1::CheckError]) -> String {
19+
errs.iter()
20+
.filter_map(|e| {
21+
if let Some(ref code) = e.code {
22+
let c = serde_json::to_string(code)
23+
.unwrap_or_else(|_| "ERROR_CODE_UNSPECIFIED".to_string());
24+
if let Some(ref detail) = e.detail {
25+
Some(format!("{c}: {detail}"))
26+
} else {
27+
Some(c)
28+
}
29+
} else {
30+
None
31+
}
32+
})
33+
.collect::<Vec<_>>()
34+
.join(", ")
35+
}
36+
37+
async fn services_check(client: GoogleRestApi, service_name: impl ToString) -> Result<(), Error> {
38+
let cfg = client.create_google_servicecontrol_v1_config().await?;
39+
40+
let response = servicecontrol_v1::services_api::servicecontrol_services_check(
41+
&cfg,
42+
servicecontrol_v1::services_api::ServicecontrolPeriodServicesPeriodCheckParams {
43+
service_name: service_name.to_string(),
44+
check_request: Some(servicecontrol_v1::CheckRequest {
45+
operation: Some(Box::new(servicecontrol_v1::Operation {
46+
start_time: Some(chrono::Utc::now().to_rfc3339()),
47+
operation_id: Some(uuid::Uuid::new_v4().to_string()),
48+
operation_name: Some("Whatever".to_string()),
49+
consumer_id: GoogleEnvironment::detect_google_project_id()
50+
.await
51+
.map(|id| format!("project:{id}")),
52+
..Default::default()
53+
})),
54+
..Default::default()
55+
}),
56+
..Default::default()
57+
},
58+
)
59+
.await?;
60+
61+
if let Some(errs) = response.check_errors {
62+
Err(Error::ServiceCheckErrors(errs))
63+
} else {
64+
Ok(())
65+
}
66+
}
67+
68+
#[tokio::main]
69+
async fn main() -> Result<(), Error> {
70+
let client = GoogleRestApi::new().await?;
71+
services_check(client, "sandbox-lustre.sandbox.googleapis.com").await?;
72+
73+
Ok(())
74+
}

examples/simple-api-client/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ edition = "2021"
66

77
[dependencies]
88
#gcloud-sdk = { version = "0.25.0", git = "https://github.com/abdolence/gcloud-sdk-rs.git", branch = "master", default-features = false, features = ["tls-webpki-roots","google-logging-v2"] }
9-
gcloud-sdk = { path = "./../../gcloud-sdk", default-features = false, features = ["tls-webpki-roots","google-logging-v2"] }
9+
gcloud-sdk = { path = "./../../gcloud-sdk", default-features = false, features = ["tls-webpki-roots","google-logging-v2", "external-account-aws"] }
1010
tokio = { version = "1", features = ["full"] }
1111
tracing = "0.1"
1212
tracing-subscriber = { version ="0.3", features = ["env-filter"] }

0 commit comments

Comments
 (0)