Skip to content

Commit

Permalink
Add more filters to api_key/version to help measure trusted publishin…
Browse files Browse the repository at this point in the history
…g & attestation adoption (#5256)

Signed-off-by: Samuel Giddins <[email protected]>
  • Loading branch information
segiddins authored Nov 19, 2024
1 parent 802f0f8 commit 8996a6c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/avo/resources/api_key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ class Avo::Resources::ApiKey < Avo::BaseResource
self.includes = []

class ExpiredFilter < Avo::Filters::ScopeBooleanFilter; end
class TrustedPublisherFilter < Avo::Filters::ScopeBooleanFilter; end

def filters
filter ExpiredFilter, arguments: { default: { expired: false, unexpired: true } }
filter TrustedPublisherFilter, arguments: { default: { trusted_publisher: true, not_trusted_publisher: true } }
end

def fields
Expand Down
5 changes: 5 additions & 0 deletions app/avo/resources/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ def actions
end

class IndexedFilter < Avo::Filters::ScopeBooleanFilter; end
class TrustedPublisherFilter < Avo::Filters::ScopeBooleanFilter; end
class AttestationFilter < Avo::Filters::ScopeBooleanFilter; end

def filters
filter IndexedFilter, arguments: { default: { indexed: true, yanked: true } }
filter TrustedPublisherFilter, arguments: { default: { pushed_with_trusted_publishing: true, pushed_without_trusted_publishing: true } }
filter AttestationFilter, arguments: { default: { with_attestations: true, without_attestations: true } }
end

def fields # rubocop:disable Metrics
Expand Down Expand Up @@ -74,6 +78,7 @@ def fields # rubocop:disable Metrics
field :dependencies, as: :has_many
field :gem_download, as: :has_one, name: "Downloads"
field :deletion, as: :has_one
field :attestations, as: :has_many
end
end
end
3 changes: 3 additions & 0 deletions app/models/api_key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ class ScopeError < RuntimeError; end
scope :oidc, -> { joins(:oidc_id_token) }
scope :not_oidc, -> { where.missing(:oidc_id_token) }

scope :trusted_publisher, -> { where("owner_type like ?", "OIDC::TrustedPublisher::%") }
scope :not_trusted_publisher, -> { where("owner_type not like ?", "OIDC::TrustedPublisher::%") }

def self.expire_all!
transaction do
unexpired.find_each.all?(&:expire!)
Expand Down
16 changes: 16 additions & 0 deletions app/models/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,22 @@ def self.created_between(start_time, end_time)
where(created_at: start_time..end_time).order(:created_at, :id)
end

def self.pushed_with_trusted_publishing
joins(:pusher_api_key).merge(ApiKey.trusted_publisher)
end

def self.pushed_without_trusted_publishing
left_joins(:pusher_api_key).merge(ApiKey.not_trusted_publisher.or(where(pusher_api_key: nil).only(:where)))
end

def self.with_attestations
where.associated(:attestations)
end

def self.without_attestations
where.missing(:attestations)
end

def platformed?
platform != "ruby"
end
Expand Down

0 comments on commit 8996a6c

Please sign in to comment.