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