Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
Added the registry.catalog_page option
Browse files Browse the repository at this point in the history
With this option we will be able to workaround distribution/distribution#1854.
Moreover, with this we will allow administrators to further tweak how Portus
interacts with the registry.

Moreover, because of this new addition, I felt like groupping registry-related
configurable options would be a good idea, so now all these options are under
the new `registry` section. We are still providing a compatibility layer in the
Portus::Migrate module.

Fixes #1001

Signed-off-by: Miquel Sabaté Solà <msabate@suse.com>
  • Loading branch information
mssola committed Jul 21, 2016
1 parent 2f5b7d0 commit de4e4f4
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Expand Up @@ -4,7 +4,7 @@ inherit_from:

# TODO: (mssola) only the LDAP class and portusctl require this.
Metrics/ClassLength:
Max: 162
Max: 180

# TODO: (mssola) Some methods are offending this cop. In the SUSE's style guide
# the approach is to use Rubocop's default value. In the near future I will
Expand Down
30 changes: 20 additions & 10 deletions config/config.yml
Expand Up @@ -105,16 +105,26 @@ signup:
check_ssl_usage:
enabled: true

# Set the expiration time in minutes for the JWT Token that Portus uses to
# authenticate with the registry.
#
# Note that this is just a work-around on the fact that the registry does not
# try to get a new token again after the current one has expired. Once a
# solution is issued upstream, we can deprecate this option.
#
# See: https://github.com/SUSE/Portus/issues/510
jwt_expiration_time:
value: 5
# Contains advanced options that tweak how Portus interacts with the
# Registry. Don't touch any of these values unless you *really* know what you
# are doing.
registry:
# Set the expiration time in minutes for the JWT Token that Portus uses to
# authenticate with the registry.
#
# Note that this is just a work-around on the fact that the registry does not
# try to get a new token again after the current one has expired. Once a
# solution is issued upstream, we can deprecate this option.
#
# See: https://github.com/SUSE/Portus/issues/510
jwt_expiration_time:
value: 5

# Set the pagination value for API calls that fetch data from the
# registry. You can read more about pagination in the registry here:
# https://github.com/docker/distribution/blob/master/docs/spec/api.md#pagination
catalog_page:
value: 100

# The FQDN of the machine where Portus is being deployed.
machine_fqdn:
Expand Down
3 changes: 2 additions & 1 deletion lib/portus/jwt_token.rb
Expand Up @@ -66,7 +66,8 @@ def self.kid(private_key)

# The expiration time to be added to the current token.
def expiration_time
Portus::Migrate.from_humanized_time(APP_CONFIG["jwt_expiration_time"]["value"], 5)
value = Portus::Migrate.registry_config("jwt_expiration_time")
Portus::Migrate.from_humanized_time(value, 5)
end

# Returns an array with the authorized actions hash.
Expand Down
15 changes: 15 additions & 0 deletions lib/portus/migrate.rb
Expand Up @@ -38,5 +38,20 @@ def self.from_humanized_time(duration, default)
eval(duration)
# rubocop:enable Lint/Eval
end

# Provides a compatibility layer for Portus 2.1 for users that haven't
# migrated yet from `jwt_expiration_time` to `registry.jwt_expiration_time`.
#
# TODO: (mssola) remove in the next version.
def self.registry_config(key)
return APP_CONFIG["registry"][key]["value"] if APP_CONFIG["registry"]

Rails.logger.tagged("deprecated") do
Rails.logger.warn "The usage of '#{key}' is deprecated and it's now under the 'registry' "\
"configuration section."
end

APP_CONFIG[key]["value"]
end
end
end
2 changes: 1 addition & 1 deletion lib/portus/registry_client.rb
Expand Up @@ -94,7 +94,7 @@ def delete(name, digest, object = "blobs")
# wrong, it raises an exception.
def paged_response(link, field)
res = []
link += "?n=100"
link += "?n=#{APP_CONFIG["registry"]["catalog_page"]["value"]}"

until link.empty?
page, link = get_page(link)
Expand Down
7 changes: 6 additions & 1 deletion packaging/suse/portusctl/lib/cli.rb
Expand Up @@ -109,7 +109,12 @@ class Cli < Thor
# JWT EXPIRATION TIME
option "jwt-expiration-time",
desc: "Expiration time for the JWT token used by Portus",
default: "5.minutes"
default: 5

# Catalog pagination
option "catalog-page",
desc: "Pagination value for API calls to the registry",
default: 100

# FIRST USER
option "first-user-admin-enable",
Expand Down
3 changes: 2 additions & 1 deletion packaging/suse/portusctl/spec/options_spec.rb
Expand Up @@ -6,7 +6,8 @@ def format_key(key)
key.tr("_", "-")
.gsub("enabled", "enable")
.gsub("user-name", "username")
.gsub(/^jwt-expiration-time-value$/, "jwt-expiration-time")
.gsub(/^registry-jwt-expiration-time-value$/, "jwt-expiration-time")
.gsub(/^registry-catalog-page-value$/, "catalog-page")
.gsub(/^check-ssl-usage-enable$/, "secure")
end

Expand Down
28 changes: 20 additions & 8 deletions packaging/suse/portusctl/templates/config-local.yml.erb
Expand Up @@ -114,14 +114,26 @@ signup:
check_ssl_usage:
enabled: <%= @options["secure"] %>

# Set the expiration time for the JWT Token that Portus uses to authenticate
# with the registry. Note that this is just a work-around on the fact that the
# registry does not try to get a new token again after the current one has
# expired. Once a solution is issued upstream, we can deprecate this option.
#
# See: https://github.com/SUSE/Portus/issues/510
jwt_expiration_time:
value: <%= @options["jwt-expiration-time"] %>
# Contains advanced options that tweak how Portus interacts with the
# Registry. Don't touch any of these values unless you *really* know what you
# are doing.
registry:
# Set the expiration time in minutes for the JWT Token that Portus uses to
# authenticate with the registry.
#
# Note that this is just a work-around on the fact that the registry does not
# try to get a new token again after the current one has expired. Once a
# solution is issued upstream, we can deprecate this option.
#
# See: https://github.com/SUSE/Portus/issues/510
jwt_expiration_time:
value: <%= @options["jwt-expiration-time"] %>

# Set the pagination value for API calls that fetch data from the
# registry. You can read more about pagination in the registry here:
# https://github.com/docker/distribution/blob/master/docs/spec/api.md#pagination
catalog_page:
value: <%= @options["catalog-page"] %>

# The FQDN of the machine where Portus is being deployed.
machine_fqdn:
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/portus/jwt_token_spec.rb
Expand Up @@ -74,7 +74,7 @@

describe ":exp" do
it "is set to #expires_at" do
APP_CONFIG["jwt_expiration_time"] = { "value" => "6.minutes" }
APP_CONFIG["registry"]["jwt_expiration_time"] = { "value" => "6.minutes" }

now = Time.zone.now
expected = now + 6.minutes
Expand Down
20 changes: 20 additions & 0 deletions spec/lib/portus/migrate_spec.rb
Expand Up @@ -26,4 +26,24 @@
expect(val).to eq 3.seconds
end
end

describe "registry_config" do
before :each do
@registry = APP_CONFIG["registry"]
end

after :each do
APP_CONFIG["registry"] = @registry
APP_CONFIG["jwt_expiration_time"] = nil
end

it "returns a value depending of the format" do
expect(Portus::Migrate.registry_config("jwt_expiration_time")).to_not be_nil

APP_CONFIG["registry"] = nil
APP_CONFIG["jwt_expiration_time"] = { "value" => 5 }

expect(Portus::Migrate.registry_config("jwt_expiration_time")).to eq 5
end
end
end
6 changes: 4 additions & 2 deletions spec/spec_helper.rb
@@ -1,4 +1,3 @@

require "codeclimate-test-reporter"
CodeClimate::TestReporter.start

Expand Down Expand Up @@ -46,7 +45,10 @@

# This value is expected to be always available. The default value will be
# set
APP_CONFIG["jwt_expiration_time"] = { "value" => "5.minutes" }
APP_CONFIG["registry"] = {
"jwt_expiration_time" => { "value" => 5 },
"catalog_page" => { "value" => 100 }
}
end

config.order = :random
Expand Down

0 comments on commit de4e4f4

Please sign in to comment.