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

Commit

Permalink
Added a rake task showing general info
Browse files Browse the repository at this point in the history
For now it shows the version and the evaluated config.

Signed-off-by: Miquel Sabaté Solà <[email protected]>
  • Loading branch information
mssola committed Mar 30, 2016
1 parent a0cea2a commit 152ce27
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 3 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
into fixing the issue #512.
- Teams can be renamed. See PR [#536](https://github.com/SUSE/Portus/pull/536).
- Users can be created from the admin page.
See PR [543](https://github.com/SUSE/Portus/pull/543). This is a first step
See PR [#543](https://github.com/SUSE/Portus/pull/543). This is a first step
into fixing the issues #283 and #179.
- Team and namespace descriptions can be written using Markdown. See pull
requests: [#546](https://github.com/SUSE/Portus/pull/546) and
[#531](https://github.com/SUSE/Portus/pull/531).
- Team members can comment on repositories. See pull request: [#538](https://github.com/SUSE/Portus/pull/583)
- Users can create security tokens to use instead of their credentials. See pull request: [625](https://github.com/SUSE/Portus/pull/625)
- Users can create security tokens to use instead of their credentials. See pull request: [#625](https://github.com/SUSE/Portus/pull/625)
- Added the `portus:info` rake task. See PR [#799](https://github.com/SUSE/Portus/pull/799).

## 2.0.3

Expand Down
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ points if your issue is about Portus behaving in an unexpected manner:
That being said, if you are using a custom setup explain to us how all the
pieces are glued together (you don't have to be too verbose, just specify the
most important stuff like configurations, etc.).
- Paste the output of `rake portus:info` (or `portusctl rake portus:info` if
you are using the RPM).
- If relevant, provide the related logs. If you are using the provided RPM,
this is as simple as just calling `portusctl logs`. Otherwise, provide the
contents of your `log/$environment.log` file, and the contents of the logs of
Expand Down
5 changes: 5 additions & 0 deletions lib/portus/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ def fetch
add_enabled(hsh)
end

# Returns a string representation of the evaluated configuration.
def to_s
hide_password(fetch.dup).to_yaml
end

protected

include ::Portus::HashUtils
Expand Down
12 changes: 12 additions & 0 deletions lib/portus/hash_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ def strict_merge_with_env(cfg, local, prefix = "portus")
hsh
end

# Hide any sensitive value, replacing it with "*" characters.
def hide_password(hsh)
hsh.each do |k, v|
if v.is_a?(Hash)
hsh[k] = hide_password(v)
elsif k == "password"
hsh[k] = "****"
end
end
hsh
end

private

# Get the typed value of the specified environment variable. If it doesn't
Expand Down
10 changes: 10 additions & 0 deletions lib/tasks/info.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace :portus do
desc "Get general info about the running instance"
task info: :environment do
puts "\nPortus version: #{Version.value}"
default = File.join(Rails.root, "config", "config.yml")
local = File.join(Rails.root, "config", "config-local.yml")
cfg = Portus::Config.new(default, local)
puts "Portus has evaluated the following configuration:\n#{cfg}"
end
end
4 changes: 4 additions & 0 deletions spec/fixtures/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ ldap:
hostname: "ldap_hostname"
port: 389
base: ""
authentication:
enabled: false
bind_dn: ""
password: "mypassword"
10 changes: 10 additions & 0 deletions spec/lib/portus/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,14 @@ def strict_merge_with_env(cfg, local, prefix = "portus")
expect(cfg["ldap"]["count"]).to eq 2 # env
expect(cfg["ldap"]["string"]).to eq "string" # env
end

it "returns the proper config while hiding passwords" do
cfg = get_config("config.yml", "local.yml")
fetched = cfg.fetch
evaled = YAML.load(cfg.to_s)

expect(fetched).to_not eq(evaled)
fetched["ldap"]["authentication"]["password"] = "****"
expect(fetched).to eq(evaled)
end
end
2 changes: 1 addition & 1 deletion spec/models/registry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def create_empty_namespace
mock.get_tag_from_target_test(nil, "busybox", "a", "sha:1234")
end

it "fetches the tag from the target if it exists", focus: true do
it "fetches the tag from the target if it exists" do
mock = RegistryMock.new(false)

# We leave everything empty to show that if the tag is provided, we pick
Expand Down

0 comments on commit 152ce27

Please sign in to comment.