gcloud_artifact_registry/lib.rs
1//! # google-cloud-artifact-registry
2//!
3//! Google Cloud Platform Artifact Registry Client library.
4//!
5//! ## Quickstart
6//!
7//! ### Authentication
8//! There are two ways to create a client that is authenticated against the google cloud.
9//!
10//! #### Automatically
11//!
12//! The function `with_auth()` will try and read the credentials from a file specified in the environment variable `GOOGLE_APPLICATION_CREDENTIALS`, `GOOGLE_APPLICATION_CREDENTIALS_JSON` or
13//! from a metadata server.
14//!
15//! This is also described in [google-cloud-auth](https://github.com/yoshidan/google-cloud-rust/blob/main/foundation/auth/README.md)
16//!
17//! ```rust
18//! use google_cloud_artifact_registry::client::{Client, ClientConfig};
19//!
20//! async fn run() {
21//! let config = ClientConfig::default().with_auth().await.unwrap();
22//! let client = Client::new(config);
23//! }
24//! ```
25//!
26//! #### Manually
27//!
28//! When you can't use the `gcloud` authentication but you have a different way to get your credentials (e.g a different environment variable)
29//! you can parse your own version of the 'credentials-file' and use it like that:
30//!
31//! ```rust
32//! use google_cloud_auth::credentials::CredentialsFile;
33//! // or google_artifact_registry::client::google_cloud_auth::credentials::CredentialsFile
34//! use google_cloud_artifact_registry::client::{Client, ClientConfig};
35//!
36//! async fn run(cred: CredentialsFile) {
37//! let config = ClientConfig::default().with_credentials(cred).await.unwrap();
38//! let client = Client::new(config);
39//! }
40//! ```
41//!
42//! ### Usage
43//!
44//! #### Repository operations
45//!
46//! ```rust
47//! use std::collections::HashMap;
48//! use prost_types::FieldMask;
49//! use google_cloud_artifact_registry::client::{Client, ClientConfig};
50//! use google_cloud_googleapis::devtools::artifact_registry::v1::{CreateRepositoryRequest, DeleteRepositoryRequest, GetRepositoryRequest, ListRepositoriesRequest, Repository, UpdateRepositoryRequest};
51//! use google_cloud_googleapis::devtools::artifact_registry::v1::repository::Format;
52//! use google_cloud_googleapis::iam::v1::{GetIamPolicyRequest, Policy, SetIamPolicyRequest, TestIamPermissionsRequest};
53//!
54//! async fn run(config: ClientConfig) {
55//!
56//! // Create client
57//! let mut client = Client::new(config).await.unwrap();
58//!
59//! // Repository
60//! // create
61//! match client
62//! .create_repository(
63//! CreateRepositoryRequest {
64//! parent: "projects/qovery-gcp-tests/locations/europe-west9".to_string(),
65//! repository_id: "repository-for-documentation".to_string(),
66//! repository: Some(Repository {
67//! name: "repository-for-documentation".to_string(),
68//! format: Format::Docker.into(),
69//! description: "Example repository for documentation".to_string(),
70//! labels: HashMap::from_iter(vec![
71//! ("a_label".to_string(), "a_label_value".to_string()),
72//! ("another_label".to_string(), "another_label_value".to_string()),
73//! ]),
74//! ..Default::default()
75//! }),
76//! },
77//! None,
78//! )
79//! .await
80//! {
81//! Ok(mut r) => println!("Created repository {:?}", r.wait(None).await.unwrap()),
82//! Err(err) => panic!("err: {:?}", err),
83//! };
84//!
85//! // update
86//! match client
87//! .update_repository(
88//! UpdateRepositoryRequest {
89//! repository: Some(Repository {
90//! name: "projects/qovery-gcp-tests/locations/europe-west9/repositories/repository-for-documentation"
91//! .to_string(),
92//! description: "updated description".to_string(),
93//! labels: HashMap::from_iter(vec![(
94//! "yet_another_label".to_string(),
95//! "yet_another_label_value".to_string(),
96//! )]),
97//! ..Default::default()
98//! }),
99//! update_mask: Some(FieldMask {
100//! paths: vec!["description".to_string(), "labels".to_string()],
101//! }),
102//! },
103//! None,
104//! )
105//! .await
106//! {
107//! Ok(r) => println!("Updated repository {:?}", r),
108//! Err(err) => panic!("err: {:?}", err),
109//! };
110//!
111//! // list
112//! match client
113//! .list_repositories(
114//! ListRepositoriesRequest {
115//! parent: "projects/qovery-gcp-tests/locations/europe-west9".to_string(),
116//! page_size: 100,
117//! page_token: "".to_string(),
118//! },
119//! None,
120//! )
121//! .await
122//! {
123//! Ok(response) => {
124//! println!("List repositories");
125//! for r in response.repositories {
126//! println!("- {:?}", r);
127//! }
128//! }
129//! Err(err) => panic!("err: {:?}", err),
130//! }
131//!
132//! // get
133//! match client
134//! .get_repository(
135//! GetRepositoryRequest {
136//! name: "projects/qovery-gcp-tests/locations/europe-west9/repositories/repository-for-documentation"
137//! .to_string(),
138//! },
139//! None,
140//! )
141//! .await
142//! {
143//! Ok(r) => println!("Get repository {:?}", r),
144//! Err(err) => panic!("err: {:?}", err),
145//! }
146//!
147//! // delete
148//! match client
149//! .delete_repository(
150//! DeleteRepositoryRequest {
151//! name: "projects/qovery-gcp-tests/locations/europe-west9/repositories/repository-for-documentation"
152//! .to_string(),
153//! },
154//! None,
155//! )
156//! .await
157//! {
158//! Ok(r) => println!("Delete repository `repository-for-documentation`"),
159//! Err(err) => panic!("err: {:?}", err),
160//! }
161//!
162//! // get repository IAM policy
163//! match client
164//! .get_iam_policy(
165//! GetIamPolicyRequest {
166//! resource: "projects/qovery-gcp-tests/locations/europe-west9/repositories/repository-for-documentation"
167//! .to_string(),
168//! ..Default::default()
169//! },
170//! None,
171//! )
172//! .await
173//! {
174//! Ok(policy) => println!("Get IAM Policy for `repository-for-documentation` {:?}", policy),
175//! Err(err) => panic!("err: {:?}", err),
176//! }
177//!
178//! // update repository IAM policy
179//! match client
180//! .set_iam_policy(
181//! SetIamPolicyRequest {
182//! resource: "projects/qovery-gcp-tests/locations/europe-west9/repositories/repository-for-documentation"
183//! .to_string(),
184//! policy: Some(Policy {
185//! version: 3,
186//! ..Default::default()
187//! }),
188//! update_mask: Some(FieldMask {
189//! paths: vec!["policy.version".to_string()],
190//! }),
191//! },
192//! None,
193//! )
194//! .await
195//! {
196//! Ok(policy) => println!("Update IAM Policy for `repository-for-documentation` {:?}", policy),
197//! Err(err) => panic!("err: {:?}", err),
198//! }
199//!
200//! // test IAM repository IAM policy
201//! match client
202//! .test_iam_permissions(
203//! TestIamPermissionsRequest {
204//! resource: "projects/qovery-gcp-tests/locations/europe-west9/repositories/repository-for-documentation"
205//! .to_string(),
206//! ..Default::default()
207//! },
208//! None,
209//! )
210//! .await
211//! {
212//! Ok(permissions) => {
213//! println!("Test permissions for `repository-for-documentation`, permissions:");
214//! for p in permissions {
215//! println!("- Permission: {}", p);
216//! }
217//! }
218//! Err(err) => panic!("err: {:?}", err),
219//! }
220//!
221//! }
222//! ```
223//!
224//! #### Docker images operations
225//!
226//! ```rust
227//! use google_cloud_artifact_registry::client::{Client, ClientConfig};
228//! use google_cloud_googleapis::devtools::artifact_registry::v1::{GetDockerImageRequest, ListDockerImagesRequest};
229//!
230//! async fn run(config: ClientConfig) {
231//!
232//! // Create client.
233//! let mut client = Client::new(config).await.unwrap();
234//!
235//! // Docker images
236//! // list
237//! match client
238//! .list_docker_images(
239//! ListDockerImagesRequest {
240//! parent: "projects/qovery-gcp-tests/locations/europe-west9/repositories/repository-for-documentation"
241//! .to_string(),
242//! ..Default::default()
243//! },
244//! None,
245//! )
246//! .await
247//! {
248//! Ok(response) => {
249//! println!("Docker images for repository `repository-for-documentation`: ");
250//! for image in response.docker_images {
251//! println!("- Image: {:?}", image);
252//! }
253//! }
254//! Err(e) => {
255//! println!("Error: {}", e);
256//! println!("Error details: {:?}", e.metadata())
257//! }
258//! }
259//!
260//! // get
261//! let result = client.get_docker_image(GetDockerImageRequest {
262//! name: "projects/qovery-gcp-tests/locations/europe-west9/repositories/repository-for-documentation/dockerImages/quickstart-image@sha256:2571d3a406da0ecafff96a9c707bc2eba954352dabc85dd918af2e3ec40c263a".to_string(),
263//! }, None).await;
264//!
265//! match result {
266//! Ok(d) => {
267//! println!("Image: {:?}", d);
268//! }
269//! Err(e) => {
270//! println!("Error: {}", e);
271//! println!("Error details: {:?}", e.metadata())
272//! }
273//! }
274//! }
275//! ```
276pub mod client;
277pub mod grpc;