-
-
Notifications
You must be signed in to change notification settings - Fork 62
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 support for Docker engine #914
base: master
Are you sure you want to change the base?
Changes from 27 commits
ebc1c00
3b80495
573e1db
9de0639
1d8014d
afcbf80
49cabe8
7548ded
91207ec
82c343b
19c6359
8775471
c1051ab
da5fa6b
144c0d6
c4cfaa5
803b4e7
8094f2d
1053303
3094047
56ec1e7
f754f90
1b4a67c
ad8808f
ce3ad8c
f106a2c
83a2fb3
c3bc0be
bbac712
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# frozen_string_literal: true | ||
|
||
module Api::V1::ReleaseEngines | ||
class Oci::BlobsController < Api::V1::BaseController | ||
before_action :scope_to_current_account! | ||
before_action :require_active_subscription! | ||
before_action :authenticate_with_token | ||
before_action :set_package | ||
|
||
def show | ||
authorize! package | ||
|
||
descriptor = authorized_scope(package.descriptors).find_by!( | ||
content_digest: params[:digest], | ||
ezekg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
authorize! descriptor | ||
|
||
if request.head? | ||
# see: https://github.com/opencontainers/distribution-spec/blob/main/spec.md#checking-if-content-exists-in-the-registry | ||
head :ok | ||
else | ||
redirect_to vanity_v1_account_release_artifact_url(current_account, descriptor.artifact, filename: descriptor.content_path, host: request.host), | ||
status: :see_other | ||
end | ||
end | ||
|
||
private | ||
|
||
attr_reader :package | ||
|
||
def set_package | ||
scoped_packages = authorized_scope(current_account.release_packages.oci) | ||
.where_assoc_exists( | ||
:descriptors, # must exist | ||
) | ||
|
||
@package = Current.resource = FindByAliasService.call( | ||
scoped_packages, | ||
id: params[:package], | ||
aliases: :key, | ||
) | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# frozen_string_literal: true | ||
|
||
module Api::V1::ReleaseEngines | ||
class Oci::ManifestsController < Api::V1::BaseController | ||
before_action :scope_to_current_account! | ||
before_action :require_active_subscription! | ||
before_action :authenticate_with_token | ||
before_action :set_package | ||
|
||
def show | ||
authorize! package | ||
|
||
manifest = authorized_scope(package.manifests).find_by_reference!( | ||
params[:reference], | ||
content_type: request.accepts.collect(&:to_s), | ||
ezekg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
authorize! manifest | ||
|
||
# for etag support | ||
return unless | ||
stale?(manifest, cache_control: { max_age: 1.day, private: true }) | ||
|
||
# oci spec is very particular about content/media types | ||
response.content_type = manifest.content_type | ||
|
||
if request.head? | ||
# see: https://github.com/opencontainers/distribution-spec/blob/main/spec.md#checking-if-content-exists-in-the-registry | ||
head :ok | ||
else | ||
render body: manifest.content | ||
end | ||
end | ||
|
||
private | ||
|
||
attr_reader :package | ||
|
||
def set_package | ||
scoped_packages = authorized_scope(current_account.release_packages.oci) | ||
.where_assoc_exists( | ||
:manifests, # must exist | ||
) | ||
|
||
@package = Current.resource = FindByAliasService.call( | ||
scoped_packages, | ||
id: params[:package], | ||
aliases: :key, | ||
) | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,6 +86,8 @@ def render_forbidden(**kwargs) | |
|
||
respond_to do |format| | ||
format.any { | ||
response.content_type = Mime::Type.lookup_by_extension(:jsonapi) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should respond with a JSON content type if asked (or if the route uses the |
||
|
||
render status: :forbidden, json: { | ||
meta: { id: request.request_id }, | ||
errors: [{ | ||
|
@@ -111,6 +113,8 @@ def render_unauthorized(**kwargs) | |
|
||
respond_to do |format| | ||
format.any { | ||
response.content_type = Mime::Type.lookup_by_extension(:jsonapi) | ||
|
||
render status: :unauthorized, json: { | ||
meta: { id: request.request_id }, | ||
errors: [{ | ||
|
@@ -134,6 +138,8 @@ def render_unprocessable_entity(**kwargs) | |
|
||
respond_to do |format| | ||
format.any { | ||
response.content_type = Mime::Type.lookup_by_extension(:jsonapi) | ||
|
||
render status: :unprocessable_entity, json: { | ||
meta: { id: request.request_id }, | ||
errors: [{ | ||
|
@@ -157,6 +163,8 @@ def render_not_found(**kwargs) | |
|
||
respond_to do |format| | ||
format.any { | ||
response.content_type = Mime::Type.lookup_by_extension(:jsonapi) | ||
|
||
render status: :not_found, json: { | ||
meta: { id: request.request_id }, | ||
errors: [{ | ||
|
@@ -181,6 +189,8 @@ def render_bad_request(**kwargs) | |
|
||
respond_to do |format| | ||
format.any { | ||
response.content_type = Mime::Type.lookup_by_extension(:jsonapi) | ||
|
||
render status: :bad_request, json: { | ||
meta: { id: request.request_id }, | ||
errors: [{ | ||
|
@@ -204,6 +214,8 @@ def render_conflict(**kwargs) | |
|
||
respond_to do |format| | ||
format.any { | ||
response.content_type = Mime::Type.lookup_by_extension(:jsonapi) | ||
|
||
render status: :conflict, json: { | ||
meta: { id: request.request_id }, | ||
errors: [{ | ||
|
@@ -227,6 +239,8 @@ def render_payment_required(**kwargs) | |
|
||
respond_to do |format| | ||
format.any { | ||
response.content_type = Mime::Type.lookup_by_extension(:jsonapi) | ||
|
||
render status: :payment_required, json: { | ||
meta: { id: request.request_id }, | ||
errors: [{ | ||
|
@@ -250,6 +264,8 @@ def render_internal_server_error(**kwargs) | |
|
||
respond_to do |format| | ||
format.any { | ||
response.content_type = Mime::Type.lookup_by_extension(:jsonapi) | ||
|
||
render status: :internal_server_error, json: { | ||
meta: { id: request.request_id }, | ||
errors: [{ | ||
|
@@ -273,6 +289,8 @@ def render_service_unavailable(**kwargs) | |
|
||
respond_to do |format| | ||
format.any { | ||
response.content_type = Mime::Type.lookup_by_extension(:jsonapi) | ||
|
||
render status: :service_unavailable, json: { | ||
meta: { id: request.request_id }, | ||
errors: [{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,17 +8,24 @@ module Base | |
include ActionController::MimeResponds | ||
|
||
# overload render method to automatically set content type | ||
def render(args, ...) | ||
case args | ||
in jsonapi: | ||
def render(options, ...) | ||
mime_type, * = Mime::Type.parse(response.content_type.to_s) rescue nil | ||
|
||
# skip if we've already set content type | ||
unless mime_type.nil? | ||
return super | ||
end | ||
|
||
case options | ||
in jsonapi: _ | ||
response.content_type = Mime::Type.lookup_by_extension(:jsonapi) | ||
in json: | ||
in json: _ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can respond with JSONAPI depending on route format and accept header, since JSON and JSONAPI are often synonymous. |
||
response.content_type = Mime::Type.lookup_by_extension(:json) | ||
in body: | ||
in body: _ | ||
response.content_type = Mime::Type.lookup_by_extension(:binary) | ||
in html: | ||
in html: _ | ||
response.content_type = Mime::Type.lookup_by_extension(:html) | ||
in gz: | ||
in gz: _ | ||
response.content_type = Mime::Type.lookup_by_extension(:gzip) | ||
else | ||
# leave as-is | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add tests.