From 640cb0c3e0dac28ffb4ddf98eb90b0283309446f Mon Sep 17 00:00:00 2001 From: Santosh Mahto Date: Wed, 8 May 2024 00:23:43 +0530 Subject: [PATCH] lambda : Correct the github authentication. --- Cargo.lock | 1 + resctl-bench/Cargo.toml | 1 + resctl-bench/src/lambda.rs | 21 +++++++++++---------- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f824832..7b324e4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2717,6 +2717,7 @@ dependencies = [ "term_size", "thiserror", "tokio", + "url", ] [[package]] diff --git a/resctl-bench/Cargo.toml b/resctl-bench/Cargo.toml index a5c2012..22f6766 100644 --- a/resctl-bench/Cargo.toml +++ b/resctl-bench/Cargo.toml @@ -25,6 +25,7 @@ aws-sdk-s3 = { version = "0.28.0", optional = true, features = ["rustls", "rt-to aws-sdk-ssm = { version = "0.28.0", optional = true, features = ["rustls", "rt-tokio"], default-features = false } aws_lambda_events = { version = "0.10.0", optional = true } jsonwebtoken = { version = "8.3.0", optional = true } +url = { version = "2.2.2", features = ["serde"] } lambda_runtime = { version = "0.8.1", optional = true } md5 = { version = "0.7", optional = true } octocrab = { version = "0.28.0", optional = true, features = ["rustls"], default-features = false } diff --git a/resctl-bench/src/lambda.rs b/resctl-bench/src/lambda.rs index 9f42a97..5709f46 100644 --- a/resctl-bench/src/lambda.rs +++ b/resctl-bench/src/lambda.rs @@ -11,6 +11,7 @@ use octocrab::Octocrab; use std::io::{Cursor, Read, Write}; use std::os::unix::process::CommandExt; use std::path::Path; +use url::Url; use rd_util::{LambdaRequest as Request, LambdaResponse as Response}; @@ -19,6 +20,9 @@ use crate::job::{FormatOpts, JobCtxs}; // The hard-coded file name is safe because the lambda function runs single-threaded // and isolated - each concurrent instance runs on its own environment. const RESULT_PATH: &'static str = "/tmp/result.json.gz"; +// For testing purpose. +//const IOCOST_BUCKET: &'static str = "iocostbucket"; +//const IOCOST_BUCKET_REGION: &'static str = "eu-north-1"; const IOCOST_BUCKET: &'static str = "iocost-submit"; const IOCOST_BUCKET_REGION: &'static str = "us-east-1"; @@ -180,22 +184,19 @@ impl LambdaHelper { let octocrab = Octocrab::builder().personal_token(token).build()?; - let installations = octocrab + let installation = octocrab .apps() - .installations() - .send() - .await - .unwrap() - .take_items(); + .get_repository_installation("iocost-benchmark", "iocost-benchmarks") + .await?; let mut create_access_token = CreateInstallationAccessToken::default(); create_access_token.repositories = vec!["iocost-benchmarks".to_string()]; + let access_token_url = + Url::parse(installation.access_tokens_url.as_ref().unwrap()).unwrap(); + let access: InstallationToken = octocrab - .post( - installations[0].access_tokens_url.as_ref().unwrap(), - Some(&create_access_token), - ) + .post(access_token_url.path(), Some(&create_access_token)) .await .unwrap();