v2 #2
1 changed files with 22 additions and 3 deletions
commit
b3b08936f2
25
src/main.rs
25
src/main.rs
|
|
@ -1,4 +1,4 @@
|
||||||
use std::{ffi::OsString, path::PathBuf, str::FromStr, string::FromUtf8Error};
|
use std::{ffi::OsString, io::Read, path::PathBuf, str::FromStr, string::FromUtf8Error};
|
||||||
|
|
||||||
use anyhow::{Context, Result, bail};
|
use anyhow::{Context, Result, bail};
|
||||||
use flate2::{Compression, GzBuilder};
|
use flate2::{Compression, GzBuilder};
|
||||||
|
|
@ -93,7 +93,6 @@ struct CacheId(u64);
|
||||||
impl Client {
|
impl Client {
|
||||||
fn reserve(&self, key: &CacheKey, cache_size: usize) -> Result<CacheId> {
|
fn reserve(&self, key: &CacheKey, cache_size: usize) -> Result<CacheId> {
|
||||||
let uri = format!("{}_apis/artifactcache/caches", self.base_url);
|
let uri = format!("{}_apis/artifactcache/caches", self.base_url);
|
||||||
println!("will use uri: {uri}");
|
|
||||||
let request = Request::builder()
|
let request = Request::builder()
|
||||||
.uri(uri)
|
.uri(uri)
|
||||||
.method(Method::POST)
|
.method(Method::POST)
|
||||||
|
|
@ -118,7 +117,25 @@ impl Client {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
todo!()
|
let mut body = Vec::with_capacity(100);
|
||||||
|
response
|
||||||
|
.into_body()
|
||||||
|
.read_to_end(&mut body)
|
||||||
|
.context("reading response body")?;
|
||||||
|
let body_value =
|
||||||
|
serde_json::from_slice::<serde_json::Value>(&body).context("parsing response body")?;
|
||||||
|
|
||||||
|
println!("{body_value:#?}");
|
||||||
|
|
||||||
|
let cache_id = body_value
|
||||||
|
.get("result")
|
||||||
|
.context("response.result")?
|
||||||
|
.get("cacheId")
|
||||||
|
.context("response.result.cacheId")?
|
||||||
|
.as_u64()
|
||||||
|
.context("cacheId as u64")?;
|
||||||
|
|
||||||
|
Ok(CacheId(cache_id))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -160,4 +177,6 @@ fn main() {
|
||||||
let cache_id = client.reserve(&key, output.len()).unwrap();
|
let cache_id = client.reserve(&key, output.len()).unwrap();
|
||||||
|
|
||||||
println!("Reserved cache with id {cache_id:?}");
|
println!("Reserved cache with id {cache_id:?}");
|
||||||
|
|
||||||
|
todo!();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue