v2 #2
1 changed files with 37 additions and 10 deletions
add: save the cache
All checks were successful
Build and update the action / build-and-upload (push) Successful in 2m36s
All checks were successful
Build and update the action / build-and-upload (push) Successful in 2m36s
+ minor formatting
commit
1aa6a60f4e
47
src/main.rs
47
src/main.rs
|
|
@ -6,10 +6,10 @@ use isahc::{
|
|||
HttpClient, HttpClientBuilder, Request,
|
||||
auth::{Authentication, Credentials},
|
||||
config::Configurable,
|
||||
http::{Method, StatusCode, Uri},
|
||||
http::{Method, StatusCode},
|
||||
};
|
||||
use secrecy::{ExposeSecret, SecretString};
|
||||
use tar::{Archive, Builder, HeaderMode};
|
||||
use tar::{Builder, HeaderMode};
|
||||
|
||||
fn paths_parser(input: OsString) -> Result<Vec<PathBuf>, FromUtf8Error> {
|
||||
let input = String::from_utf8(input.into_encoded_bytes())?;
|
||||
|
|
@ -105,23 +105,23 @@ impl Client {
|
|||
.to_string(),
|
||||
)
|
||||
.context("building the request")?;
|
||||
let response = self
|
||||
let mut response = self
|
||||
.http_client
|
||||
.send(request)
|
||||
.context("sending the request")?;
|
||||
let status = response.status();
|
||||
let mut body = Vec::with_capacity(100);
|
||||
response
|
||||
.body_mut()
|
||||
.read_to_end(&mut body)
|
||||
.context("reading response body")?;
|
||||
if status != StatusCode::OK {
|
||||
bail!(
|
||||
"Failed reserving a cache (status {status}): {:?}",
|
||||
response.body()
|
||||
String::from_utf8_lossy(&body)
|
||||
);
|
||||
}
|
||||
|
||||
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")?;
|
||||
|
||||
|
|
@ -135,6 +135,33 @@ impl Client {
|
|||
|
||||
Ok(CacheId(cache_id))
|
||||
}
|
||||
|
||||
fn save(&self, id: CacheId, archive: Vec<u8>) -> Result<()> {
|
||||
let uri = format!("{}_apis/artifactcache/caches/{}", self.base_url, id.0);
|
||||
let request = Request::builder()
|
||||
.uri(uri)
|
||||
.method(Method::PATCH)
|
||||
.body(archive)
|
||||
.context("building the request")?;
|
||||
let mut response = self
|
||||
.http_client
|
||||
.send(request)
|
||||
.context("sending the request")?;
|
||||
let status = response.status();
|
||||
let mut body = Vec::with_capacity(100);
|
||||
response
|
||||
.body_mut()
|
||||
.read_to_end(&mut body)
|
||||
.context("reading response body")?;
|
||||
if status != StatusCode::OK {
|
||||
bail!(
|
||||
"Failed saving a cache (status {status}): {:?}",
|
||||
String::from_utf8_lossy(&body)
|
||||
);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
@ -176,5 +203,5 @@ fn main() {
|
|||
|
||||
println!("Reserved cache with id {cache_id:?}");
|
||||
|
||||
todo!();
|
||||
client.save(cache_id, output).unwrap();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue