-
Notifications
You must be signed in to change notification settings - Fork 20
/
artifact_provenance.rs
72 lines (61 loc) · 2.32 KB
/
artifact_provenance.rs
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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
// artifact_provenance.rs
// Artifact provenance example, demonstrating how to obtain json
// information about the package's origin; such as identity of publisher
// and, if available, package code repository information.
use anyhow::Result;
use azure_devops_rust_api::artifacts;
use std::env;
mod utils;
#[tokio::main]
async fn main() -> Result<()> {
// Get authentication credential
let credential = utils::get_credential()?;
// Get ADO configuration via environment variables
let organization = env::var("ADO_ORGANIZATION").expect("Must define ADO_ORGANIZATION");
let project = env::var("ADO_PROJECT").expect("Must define ADO_PROJECT");
// Create an artifacts client
println!("Create artifacts client");
let artifacts_client = artifacts::ClientBuilder::new(credential).build();
// Query all the artifact feeds
let feeds = artifacts_client
.feed_management_client()
.get_feeds(&organization, &project)
.await?
.value;
if let Some(feed) = feeds.first() {
if let Some(feed_id) = &feed.feed_core.id {
let packages = artifacts_client
.artifact_details_client()
.get_packages(&organization, feed_id, &project)
.await?
.value;
if let Some(package) = packages.first() {
let name = package.name.as_deref().unwrap_or("");
let id = package.id.as_deref().unwrap_or("");
let version_id = package
.versions
.first()
.expect("No package version information available")
.id
.as_deref()
.unwrap_or("");
println!("{:30}{:40}{:40}", name, id, version_id);
let provenance = artifacts_client
.artifact_details_client()
.get_package_version_provenance(
&organization,
feed_id,
id,
version_id,
&project,
)
.await?
.provenance;
println!("{:#?}", provenance);
}
}
}
Ok(())
}