Skip to content

database/api_tokens: Add crate_scopes and endpoint_scopes columns #5562

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

Merged
merged 1 commit into from
Dec 1, 2022
Merged
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
5 changes: 5 additions & 0 deletions migrations/2022-11-23-135139_add-token-scopes/down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
alter table api_tokens
drop column crate_scopes;

alter table api_tokens
drop column endpoint_scopes;
9 changes: 9 additions & 0 deletions migrations/2022-11-23-135139_add-token-scopes/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
alter table api_tokens
add column crate_scopes text[];

comment on column api_tokens.crate_scopes is 'NULL or an array of crate scope patterns (see RFC #2947)';

alter table api_tokens
add column endpoint_scopes text[];

comment on column api_tokens.endpoint_scopes is 'An array of endpoint scopes or NULL for the `legacy` endpoint scope (see RFC #2947)';
8 changes: 8 additions & 0 deletions src/models/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ pub struct ApiToken {
pub last_used_at: Option<NaiveDateTime>,
#[serde(skip)]
pub revoked: bool,
/// `None` or a list of crate scope patterns (see RFC #2947)
#[serde(skip)]
pub crate_scopes: Option<Vec<String>>,
/// A list of endpoint scopes or `None` for the `legacy` endpoint scope (see RFC #2947)
#[serde(skip)]
pub endpoint_scopes: Option<Vec<String>>,
}

impl ApiToken {
Expand Down Expand Up @@ -106,6 +112,8 @@ mod tests {
.and_hms_opt(14, 23, 12),
)
.unwrap(),
crate_scopes: None,
endpoint_scopes: None,
};
let json = serde_json::to_string(&tok).unwrap();
assert_some!(json
Expand Down
12 changes: 12 additions & 0 deletions src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ table! {
///
/// (Automatically generated by Diesel.)
revoked -> Bool,
/// The `crate_scopes` column of the `api_tokens` table.
///
/// Its SQL type is `Nullable<Array<Text>>`.
///
/// (Automatically generated by Diesel.)
crate_scopes -> Nullable<Array<Text>>,
/// The `endpoint_scopes` column of the `api_tokens` table.
///
/// Its SQL type is `Nullable<Array<Text>>`.
///
/// (Automatically generated by Diesel.)
endpoint_scopes -> Nullable<Array<Text>>,
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/worker/dump_db/dump-db.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ name = "private"
created_at = "private"
last_used_at = "private"
revoked = "private"
crate_scopes = "private"
endpoint_scopes = "private"

[background_jobs.columns]
id = "private"
Expand Down