Skip to content

Commit

Permalink
made the code running, can access auth_info from github app
Browse files Browse the repository at this point in the history
  • Loading branch information
MuskanPaliwal committed Oct 14, 2023
1 parent ee415ad commit e5973ce
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ ARG BITBUCKET_CLIENT_SECRET
ARG BITBUCKET_BASE_URL
ARG INSTALL_ID
ARG SERVER_URL
ARG GITHUB_CLIENT_ID
ARG GITHUB_CLIENT_SECRET
ARG GITHUB_BASE_URL
ARG GITHUB_APP_ID


ENV GCP_CREDENTIALS=$GCP_CREDENTIALS
Expand All @@ -29,9 +33,14 @@ ENV BITBUCKET_CLIENT_SECRET=$BITBUCKET_CLIENT_SECRET
ENV BITBUCKET_BASE_URL=$BITBUCKET_BASE_URL
ENV INSTALL_ID=$INSTALL_ID
ENV SERVER_URL=$SERVER_URL
ENV GITHUB_CLIENT_ID=$GITHUB_CLIENT_ID
ENV GITHUB_CLIENT_SECRET=$GITHUB_CLIENT_SECRET
ENV GITHUB_BASE_URL=$GITHUB_BASE_URL
ENV GITHUB_APP_ID=$GITHUB_APP_ID

COPY ./vibi-dpu/target/debug/vibi-dpu /app/vibi-dpu
COPY ./pubsub-sa-test.json /app/pubsub-sa.json
COPY ./repoprofiler_private.pem /app/repoprofiler_private.pem

# Start the Rust application
CMD ["/app/vibi-dpu"]
5 changes: 2 additions & 3 deletions vibi-dpu/src/github/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ struct Claims {
}

fn generate_jwt(github_app_id: &str) -> Result<String, Box<dyn std::error::Error>> {
let pem_file_path = "/tmp/repoprofiler_private.pem";
let pem_file_path = "/app/repoprofiler_private.pem";
let pem_data = fs::read(pem_file_path)?;

let my_claims = Claims {
iat: Utc::now().timestamp(),
exp: (Utc::now() + Duration::minutes(5)).timestamp(),
Expand All @@ -31,7 +30,6 @@ fn generate_jwt(github_app_id: &str) -> Result<String, Box<dyn std::error::Error

let encoding_key = EncodingKey::from_rsa_pem(&pem_data)?;
let token = encode(&Header::new(Algorithm::RS256), &my_claims, &encoding_key)?;

Ok(token)
}

Expand All @@ -43,6 +41,7 @@ pub async fn fetch_access_token(installation_id: &str) -> Result<Value, Box<dyn
let response: Value = client.post(&format!("https://api.github.com/app/installations/{}/access_tokens", installation_id))
.header("Accept", "application/vnd.github+json")
.header("Authorization", format!("Bearer {}", jwt_token))
.header("User-Agent", "Vibinex code review Test App")
.send()
.await?
.json()
Expand Down
2 changes: 1 addition & 1 deletion vibi-dpu/src/setup/setup_gh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub async fn handle_install_github(installation_code: &str) {
// For example:
// 1. Get access token from GitHub using the installation code
let auth_info = fetch_access_token(installation_code).await;
println!("[handle_install_github] auth_info = {:?}", &auth_info);
println!("[handle_install_github] auth_info = {:?}", auth_info);
// 2. Fetch user repositories and other necessary data
// 3. Process webhooks or other setup tasks
// 4. Send setup info or any other post-processing
Expand Down

0 comments on commit e5973ce

Please sign in to comment.