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
use crate::{CliResult, DetermineAccountId, Output};
use clap::Subcommand;
use divviup_client::{DivviupClient, NewAggregator, Url, Uuid};
#[derive(Subcommand, Debug)]
pub enum AggregatorAction {
/// Show an aggregator
Show { aggregator_id: Uuid },
/// List all aggregators for the target account
List {
/// list only shared aggregators
#[arg(short, long)]
shared: bool,
},
/// Create a new aggregator
Create {
/// Human-readable identifier for this aggregator
///
/// This can be changed later
#[arg(short, long)]
name: String,
/// API URL for this aggregator
///
/// must be https
#[arg(short, long)]
api_url: Url,
/// bearer token for this aggregator
#[arg(short, long)]
bearer_token: String,
#[arg(short, long)]
#[cfg(feature = "admin")]
/// create an aggregator that is usable by all accounts (ADMIN)
shared: bool,
#[arg(short, long, requires = "shared")]
#[cfg(feature = "admin")]
/// create an aggregator that is considered first party (ADMIN)
first_party: bool,
},
/// Change the display name of an aggregator
Rename {
/// uuid for this aggregator
aggregator_id: Uuid,
/// new name
name: String,
},
/// Rotate the bearer token for an aggregator
RotateBearerToken {
/// uuid for this aggregator
aggregator_id: Uuid,
/// new bearer token for this aggregator
bearer_token: String,
},
/// Update the aggregator's configuration
UpdateConfig {
/// uuid for this aggregator
aggregator_id: Uuid,
},
}
impl AggregatorAction {
pub(crate) async fn run(
self,
account_id: DetermineAccountId,
client: DivviupClient,
output: Output,
) -> CliResult {
match self {
Self::Show { aggregator_id } => output.display(client.aggregator(aggregator_id).await?),
Self::List { shared: true } => output.display(client.shared_aggregators().await?),
Self::List { shared: false } => {
let account_id = account_id.await?;
output.display(client.aggregators(account_id).await?)
}
#[cfg(feature = "admin")]
Self::Create {
name,
api_url,
bearer_token,
first_party,
shared: true,
} => output.display(
client
.create_shared_aggregator(divviup_client::NewSharedAggregator {
name,
api_url,
bearer_token,
is_first_party: first_party,
})
.await?,
),
Self::Create {
name,
api_url,
bearer_token,
#[cfg(feature = "admin")]
shared: false,
..
} => output.display(
client
.create_aggregator(
account_id.await?,
NewAggregator {
name,
api_url,
bearer_token,
},
)
.await?,
),
Self::Rename {
aggregator_id,
name,
} => output.display(client.rename_aggregator(aggregator_id, &name).await?),
Self::RotateBearerToken {
aggregator_id,
bearer_token,
} => output.display(
client
.rotate_aggregator_bearer_token(aggregator_id, &bearer_token)
.await?,
),
Self::UpdateConfig { aggregator_id } => output.display(
client
.update_aggregator_configuration(aggregator_id)
.await?,
),
}
Ok(())
}
}