Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add builder_id to builds #120

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions migrations/2023-08-09-160537_builder_id/down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE builds DROP COLUMN builder_id;
1 change: 1 addition & 0 deletions migrations/2023-08-09-160537_builder_id/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE builds ADD builder_id TEXT;
2 changes: 2 additions & 0 deletions src/api/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ async fn create_build_async(
app_id: args.app_id.clone(),
public_download,
build_log_url: args.build_log_url.clone(),
builder_id: req.get_claims().unwrap().builder_id.clone(),
})
.await?;
let build_repo_path = config.build_repo_base.join(build.id.to_string());
Expand Down Expand Up @@ -536,6 +537,7 @@ pub fn token_subset(
scope: args.scope.clone(),
name: Some(claims.name.unwrap_or_default() + "/" + &args.name),
jti: claims.jti.clone(),
builder_id: claims.builder_id.clone(),
prefixes: {
if let Some(ref prefixes) = args.prefixes {
prefixes.clone()
Expand Down
9 changes: 9 additions & 0 deletions src/bin/gentoken.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ struct Claims {
prefixes: Vec<String>,
repos: Vec<String>,
exp: i64,
#[serde(skip_serializing_if = "Option::is_none")]
builder_id: Option<String>,
}

fn read_secret(filename: String) -> io::Result<String> {
Expand All @@ -40,6 +42,7 @@ fn main() {
let mut scope: Vec<String> = vec![];
let mut prefixes: Vec<String> = vec![];
let mut repos: Vec<String> = vec![];
let mut builder_id: Option<String> = None;

{
let mut ap = ArgumentParser::new();
Expand Down Expand Up @@ -79,6 +82,11 @@ fn main() {
Store,
"Duration for key in seconds (default 1 year)",
);
ap.refer(&mut builder_id).add_option(
&["--builder-id"],
StoreOption,
"Builder ID (default: none)",
);
ap.parse_args_or_exit();
}

Expand Down Expand Up @@ -130,6 +138,7 @@ fn main() {
repos,
name: name.clone(),
exp: Utc::now().timestamp() + duration,
builder_id,
};

if verbose {
Expand Down
3 changes: 3 additions & 0 deletions src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub struct NewBuild {
pub app_id: Option<String>,
pub public_download: bool,
pub build_log_url: Option<String>,
pub builder_id: Option<String>,
}

#[derive(Identifiable, Serialize, Queryable, Debug, Eq, PartialEq)]
Expand All @@ -34,6 +35,8 @@ pub struct Build {
pub app_id: Option<String>,
pub public_download: bool,
pub build_log_url: Option<String>,
/// The builder_id of the token used to create this build
pub builder_id: Option<String>,
}

#[derive(Deserialize, Debug, Eq, PartialEq)]
Expand Down
1 change: 1 addition & 0 deletions src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ diesel::table! {
app_id -> Nullable<Text>,
public_download -> Bool,
build_log_url -> Nullable<Text>,
builder_id -> Nullable<Text>,
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ pub struct Claims {
pub exp: i64,
pub jti: Option<String>, // an unique ID for the token, for revocation.

pub builder_id: Option<String>,

#[serde(default)]
pub scope: Vec<ClaimsScope>,
#[serde(default)]
Expand Down