Skip to content
This repository was archived by the owner on Oct 28, 2024. It is now read-only.

Commit 03c655d

Browse files
authored
Merge pull request #148 from bacongobbler/hippo-openapi-v0.10.0
bump to hippo-openapi v0.10.0
2 parents 3d8a002 + 2f77dac commit 03c655d

File tree

5 files changed

+71
-48
lines changed

5 files changed

+71
-48
lines changed

Cargo.lock

Lines changed: 13 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ dunce = "1.0"
1818
env_logger = "0.9"
1919
futures = "0.3.14"
2020
glob = "0.3.0"
21-
hippo-openapi = "0.9"
21+
hippo-openapi = "0.10.0"
2222
itertools = "0.10.0"
2323
log = "0.4"
2424
mime_guess = { version = "2.0" }
@@ -30,3 +30,4 @@ serde_json = "1.0"
3030
sha2 = "0.9"
3131
tokio = {version = "1.17", features = ["full"]}
3232
toml = "0.5"
33+
uuid = "1"

src/cli/commands/channel.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,5 @@ pub(crate) enum Commands {
4545
Logs {
4646
/// The channel ID
4747
id: String,
48-
}
48+
},
4949
}

src/cli/mod.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use std::{
1919
io::BufReader,
2020
path::PathBuf,
2121
};
22+
use uuid::Uuid;
2223

2324
const ABOUT_HIPPO: &str = r#"Create and manage Hippo applications.
2425
@@ -167,13 +168,17 @@ impl Cli {
167168
};
168169
let id = hippo_client
169170
.add_channel(
170-
app_id.to_owned(),
171+
Uuid::parse_str(app_id)?,
171172
name.to_owned(),
172173
domain.to_owned(),
173174
revision_selection_strategy,
174175
range_rule.to_owned(),
175-
revision_id.to_owned(),
176-
certificate_id.to_owned(),
176+
revision_id.as_ref().map_or(None, |r| {
177+
Some(Uuid::parse_str(&r).expect("could not parse active revision id"))
178+
}),
179+
certificate_id.as_ref().map_or(None, |c| {
180+
Some(Uuid::parse_str(&c).expect("could not parse certificate id"))
181+
}),
177182
)
178183
.await?;
179184
println!("Added {} (ID = '{}')", name, id);
@@ -205,22 +210,22 @@ impl Cli {
205210
.add_environment_variable(
206211
key.to_owned(),
207212
value.to_owned(),
208-
channel_id.to_owned(),
213+
Uuid::parse_str(channel_id)?,
209214
)
210215
.await?;
211216
println!("Added {}={}", key, value);
212217
}
213218

214219
Commands::Env(EnvCommands::List { channel_id }) => {
215220
let envs = hippo_client
216-
.list_environment_variables(channel_id.to_owned())
221+
.list_environment_variables(Uuid::parse_str(channel_id)?)
217222
.await?;
218223
println!("{}", serde_json::to_string_pretty(&envs)?);
219224
}
220225

221226
Commands::Env(EnvCommands::Remove { channel_id, id }) => {
222227
hippo_client
223-
.remove_environment_variable(channel_id.to_owned(), id.to_owned())
228+
.remove_environment_variable(Uuid::parse_str(channel_id)?, id.to_owned())
224229
.await?;
225230
println!("Removed {}", id);
226231
}

src/client.rs

Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@ use hippo_openapi::models::GetChannelLogsVm;
22
use hippo_openapi::models::PatchChannelCommand;
33
use std::collections::HashMap;
44

5-
use hippo_openapi::apis::account_api::{api_account_createtoken_post, api_account_post};
6-
use hippo_openapi::apis::app_api::{api_app_get, api_app_id_delete, api_app_post};
7-
use hippo_openapi::apis::certificate_api::{
8-
api_certificate_get, api_certificate_id_delete, api_certificate_post,
5+
use hippo_openapi::apis::accounts_api::api_accounts_post;
6+
use hippo_openapi::apis::apps_api::{api_apps_get, api_apps_id_delete, api_apps_post};
7+
use hippo_openapi::apis::auth_tokens_api::api_auth_tokens_post;
8+
use hippo_openapi::apis::certificates_api::{
9+
api_certificates_get, api_certificates_id_delete, api_certificates_post,
910
};
10-
use hippo_openapi::apis::channel_api::{
11-
api_channel_get, api_channel_id_delete, api_channel_id_get, api_channel_id_patch,
12-
api_channel_post, api_channel_logs_id_get
11+
use hippo_openapi::apis::channels_api::{
12+
api_channels_get, api_channels_id_delete, api_channels_id_get, api_channels_id_logs_get,
13+
api_channels_id_patch, api_channels_post,
1314
};
1415
use hippo_openapi::apis::configuration::{ApiKey, Configuration};
15-
use hippo_openapi::apis::revision_api::{api_revision_get, api_revision_post};
16+
use hippo_openapi::apis::revisions_api::{api_revisions_get, api_revisions_post};
1617
use hippo_openapi::apis::Error;
1718
use hippo_openapi::models::{
1819
AppItemPage, CertificateItemPage, ChannelItem, ChannelItemPage,
@@ -22,6 +23,8 @@ use hippo_openapi::models::{
2223
UpdateEnvironmentVariableDtoListField,
2324
};
2425

26+
use uuid::Uuid;
27+
2528
use reqwest::header;
2629
use serde::Deserialize;
2730

@@ -45,7 +48,7 @@ impl Client {
4548

4649
let base_path = match conn_info.url.strip_suffix("/") {
4750
Some(s) => s.to_owned(),
48-
None => conn_info.url
51+
None => conn_info.url,
4952
};
5053
let configuration = Configuration {
5154
base_path: base_path,
@@ -74,7 +77,7 @@ impl Client {
7477
}
7578

7679
pub async fn register(&self, username: String, password: String) -> anyhow::Result<String> {
77-
api_account_post(
80+
api_accounts_post(
7881
&self.configuration,
7982
Some(CreateAccountCommand {
8083
user_name: username,
@@ -86,7 +89,7 @@ impl Client {
8689
}
8790

8891
pub async fn login(&self, username: String, password: String) -> anyhow::Result<TokenInfo> {
89-
api_account_createtoken_post(
92+
api_auth_tokens_post(
9093
&self.configuration,
9194
Some(CreateTokenCommand {
9295
user_name: username,
@@ -97,8 +100,8 @@ impl Client {
97100
.map_err(format_response_error)
98101
}
99102

100-
pub async fn add_app(&self, name: String, storage_id: String) -> anyhow::Result<String> {
101-
api_app_post(
103+
pub async fn add_app(&self, name: String, storage_id: String) -> anyhow::Result<Uuid> {
104+
api_apps_post(
102105
&self.configuration,
103106
Some(CreateAppCommand {
104107
name: name,
@@ -110,13 +113,13 @@ impl Client {
110113
}
111114

112115
pub async fn remove_app(&self, id: String) -> anyhow::Result<()> {
113-
api_app_id_delete(&self.configuration, &id)
116+
api_apps_id_delete(&self.configuration, &id)
114117
.await
115118
.map_err(format_response_error)
116119
}
117120

118121
pub async fn list_apps(&self) -> anyhow::Result<AppItemPage> {
119-
api_app_get(&self.configuration, None, None, None, None, None)
122+
api_apps_get(&self.configuration, None, None, None, None, None)
120123
.await
121124
.map_err(format_response_error)
122125
}
@@ -126,8 +129,8 @@ impl Client {
126129
name: String,
127130
public_key: String,
128131
private_key: String,
129-
) -> anyhow::Result<String> {
130-
api_certificate_post(
132+
) -> anyhow::Result<Uuid> {
133+
api_certificates_post(
131134
&self.configuration,
132135
Some(CreateCertificateCommand {
133136
name: name,
@@ -140,27 +143,27 @@ impl Client {
140143
}
141144

142145
pub async fn list_certificates(&self) -> anyhow::Result<CertificateItemPage> {
143-
api_certificate_get(&self.configuration, None, None, None, None, None)
146+
api_certificates_get(&self.configuration, None, None, None, None, None)
144147
.await
145148
.map_err(format_response_error)
146149
}
147150

148151
pub async fn remove_certificate(&self, id: String) -> anyhow::Result<()> {
149-
api_certificate_id_delete(&self.configuration, &id)
152+
api_certificates_id_delete(&self.configuration, &id)
150153
.await
151154
.map_err(format_response_error)
152155
}
153156

154157
pub async fn add_channel(
155158
&self,
156-
app_id: String,
159+
app_id: Uuid,
157160
name: String,
158161
domain: Option<String>,
159162
revision_selection_strategy: ChannelRevisionSelectionStrategy,
160163
range_rule: Option<String>,
161-
active_revision_id: Option<String>,
162-
certificate_id: Option<String>,
163-
) -> anyhow::Result<String> {
164+
active_revision_id: Option<Uuid>,
165+
certificate_id: Option<Uuid>,
166+
) -> anyhow::Result<Uuid> {
164167
let command = CreateChannelCommand {
165168
app_id: app_id,
166169
name: name,
@@ -170,31 +173,31 @@ impl Client {
170173
active_revision_id,
171174
certificate_id,
172175
};
173-
api_channel_post(&self.configuration, Some(command))
176+
api_channels_post(&self.configuration, Some(command))
174177
.await
175178
.map_err(format_response_error)
176179
}
177180

178181
pub async fn get_channel_by_id(&self, id: &str) -> anyhow::Result<ChannelItem> {
179-
api_channel_id_get(&self.configuration, id)
182+
api_channels_id_get(&self.configuration, id)
180183
.await
181184
.map_err(format_response_error)
182185
}
183186

184187
pub async fn list_channels(&self) -> anyhow::Result<ChannelItemPage> {
185-
api_channel_get(&self.configuration, None, None, None, None, None)
188+
api_channels_get(&self.configuration, Some(""), None, None, Some("Name"), None)
186189
.await
187190
.map_err(format_response_error)
188191
}
189192

190193
pub async fn remove_channel(&self, id: String) -> anyhow::Result<()> {
191-
api_channel_id_delete(&self.configuration, &id)
194+
api_channels_id_delete(&self.configuration, &id)
192195
.await
193196
.map_err(format_response_error)
194197
}
195198

196199
pub async fn channel_logs(&self, id: String) -> anyhow::Result<GetChannelLogsVm> {
197-
api_channel_logs_id_get(&self.configuration, &id)
200+
api_channels_id_logs_get(&self.configuration, &id)
198201
.await
199202
.map_err(format_response_error)
200203
}
@@ -203,7 +206,7 @@ impl Client {
203206
&self,
204207
key: String,
205208
value: String,
206-
channel_id: String,
209+
channel_id: Uuid,
207210
) -> anyhow::Result<()> {
208211
let mut environment_variables = self.list_environment_variables(channel_id.clone()).await?;
209212
environment_variables.push(EnvironmentVariableItem {
@@ -212,9 +215,9 @@ impl Client {
212215
key: key,
213216
value: value,
214217
});
215-
api_channel_id_patch(
218+
api_channels_id_patch(
216219
&self.configuration,
217-
&channel_id,
220+
&channel_id.to_string(),
218221
Some(PatchChannelCommand {
219222
// TODO: fix this in hippo 0.19 - this is a very ugly type cast that shouldn't exist
220223
environment_variables: Some(Box::new(UpdateEnvironmentVariableDtoListField {
@@ -237,15 +240,15 @@ impl Client {
237240

238241
pub async fn list_environment_variables(
239242
&self,
240-
channel_id: String,
243+
channel_id: Uuid,
241244
) -> anyhow::Result<Vec<EnvironmentVariableItem>> {
242-
let channel = self.get_channel_by_id(&channel_id).await?;
245+
let channel = self.get_channel_by_id(&channel_id.to_string()).await?;
243246
Ok(channel.environment_variables)
244247
}
245248

246249
pub async fn remove_environment_variable(
247250
&self,
248-
channel_id: String,
251+
channel_id: Uuid,
249252
key: String,
250253
) -> anyhow::Result<()> {
251254
let mut environment_variables = self.list_environment_variables(channel_id.clone()).await?;
@@ -254,9 +257,9 @@ impl Client {
254257
.position(|e| e.key == key)
255258
.unwrap();
256259
environment_variables.remove(index);
257-
api_channel_id_patch(
260+
api_channels_id_patch(
258261
&self.configuration,
259-
&channel_id,
262+
&channel_id.to_string(),
260263
Some(PatchChannelCommand {
261264
// TODO: fix this in hippo 0.19 - this is a very ugly type cast that shouldn't exist
262265
environment_variables: Some(Box::new(UpdateEnvironmentVariableDtoListField {
@@ -282,7 +285,7 @@ impl Client {
282285
app_storage_id: String,
283286
revision_number: String,
284287
) -> anyhow::Result<()> {
285-
api_revision_post(
288+
api_revisions_post(
286289
&self.configuration,
287290
Some(RegisterRevisionCommand {
288291
app_storage_id: app_storage_id,
@@ -294,7 +297,7 @@ impl Client {
294297
}
295298

296299
pub async fn list_revisions(&self) -> anyhow::Result<RevisionItemPage> {
297-
api_revision_get(&self.configuration, None, None)
300+
api_revisions_get(&self.configuration, None, None)
298301
.await
299302
.map_err(format_response_error)
300303
}
@@ -314,6 +317,9 @@ fn format_response_error<T>(e: Error<T>) -> anyhow::Error {
314317
_ => anyhow::anyhow!(r.content),
315318
}
316319
}
320+
Error::Serde(err ) => {
321+
anyhow::anyhow!(format!("could not parse JSON object: {}", err))
322+
}
317323
_ => anyhow::anyhow!(e.to_string()),
318324
}
319325
}

0 commit comments

Comments
 (0)