From 318ae82185934c4d0a2230af943bec5a3f156a63 Mon Sep 17 00:00:00 2001 From: Chadwick Banning Date: Wed, 11 Apr 2018 13:14:42 -0400 Subject: [PATCH 1/2] Add url helper to internal route links --- lib/puppet_forge_server/app/frontend.rb | 12 ++++++------ lib/puppet_forge_server/app/views/layout.haml | 6 +++--- lib/puppet_forge_server/app/views/module.haml | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/puppet_forge_server/app/frontend.rb b/lib/puppet_forge_server/app/frontend.rb index e4c8e0d..98f3ef4 100644 --- a/lib/puppet_forge_server/app/frontend.rb +++ b/lib/puppet_forge_server/app/frontend.rb @@ -48,7 +48,7 @@ def initialize(root, http_client = PuppetForgeServer::Http::HttpClient.new) halt(400, haml(:security, :locals => {:query => query})) \ unless safe_input? query - modules = get("#{request.base_url}/v3/modules?query=#{query}")['results'] + modules = get("/v3/modules?query=#{query}")['results'] haml :modules, :locals => {:query => query, :modules => modules} end @@ -57,12 +57,12 @@ def initialize(root, http_client = PuppetForgeServer::Http::HttpClient.new) halt(400, haml(:security, :locals => {:query => module_v3_name})) \ unless safe_input? module_v3_name - releases = get("#{request.base_url}/v3/modules/#{module_v3_name}")['releases'] + releases = get("/v3/modules/#{module_v3_name}")['releases'] if params.has_key? 'version' module_uri = releases.find {|r| r['version'] == params['version']}['uri'] - module_metadata = get("#{request.base_url}#{module_uri}") + module_metadata = get("#{module_uri}") else - module_metadata = get("#{request.base_url}#{releases[0]['uri']}") + module_metadata = get("#{releases[0]['uri']}") end begin readme_markdown = markdown(module_metadata['readme']) @@ -70,7 +70,7 @@ def initialize(root, http_client = PuppetForgeServer::Http::HttpClient.new) readme_markdown = '' end haml :module, :locals => { :module_metadata => module_metadata, - :base_url => request.base_url, + :base_url => url(request.base_url), :readme_markdown => readme_markdown, :releases => releases } end @@ -88,7 +88,7 @@ def initialize(root, http_client = PuppetForgeServer::Http::HttpClient.new) private def get(relative_url) begin - JSON.parse(@http_client.get(relative_url)) + JSON.parse(@http_client.get(url(relative_url))) rescue {'results' => []} end diff --git a/lib/puppet_forge_server/app/views/layout.haml b/lib/puppet_forge_server/app/views/layout.haml index 4950696..0914f6a 100644 --- a/lib/puppet_forge_server/app/views/layout.haml +++ b/lib/puppet_forge_server/app/views/layout.haml @@ -21,7 +21,7 @@ %title Internal Puppet Forge -# Latest compiled and minified CSS %link{ :href => 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css', :type => 'text/css', :rel => 'stylesheet' } - %link{ :href => 'css/puppetlabs.css', :type => 'text/css', :rel => 'stylesheet' } + %link{ :href => url('css/puppetlabs.css'), :type => 'text/css', :rel => 'stylesheet' } -#%link{ :href => 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap-theme.min.css', :type => 'text/css', :rel => 'stylesheet' } /[if lt IE 9] %script{:src => 'https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js'} @@ -49,7 +49,7 @@ .side-width.clearfix %a{:href => url('/')} #logo - %img.logo{ :src => 'img/forge-logo.png', :height => 65} + %img.logo{ :src => url('img/forge-logo.png'), :height => 65} %span.logo.puppet= 'Puppet Forge' %span.logo.forge= 'Server' .top-search @@ -61,4 +61,4 @@ .side-width.clearfix = yield %script{ :src => 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js' } - %script{ :src => 'js/internal.js' } + %script{ :src => url('js/internal.js') } diff --git a/lib/puppet_forge_server/app/views/module.haml b/lib/puppet_forge_server/app/views/module.haml index a2502c9..5fcc728 100644 --- a/lib/puppet_forge_server/app/views/module.haml +++ b/lib/puppet_forge_server/app/views/module.haml @@ -60,8 +60,8 @@ %label= 'Select another release: ' %select{:id => 'module-release-selector', :onchange => "location = this.options[this.selectedIndex].value;"} - releases.each do |release| - %option{:value => "/module?name=#{module_metadata['metadata']['name']}&version=#{release['version']}", :selected => module_metadata['metadata']['version'] == release['version']}= release['version'] - %a{:class => 'module-release-download', :href => module_metadata['file_uri'], :title => 'Download module'}= 'Download' + %option{:value => url("/module?name=#{module_metadata['metadata']['name']}&version=#{release['version']}"), :selected => module_metadata['metadata']['version'] == release['version']}= release['version'] + %a{:class => 'module-release-download', :href => url(module_metadata['file_uri']), :title => 'Download module'}= 'Download' %div{:id => 'release-info-tabs', :class => 'module-meta-info'} %div{:class => 'tabbed content'} %div From 099f7b370e9d084d56e661120f0d083dfafb8f5f Mon Sep 17 00:00:00 2001 From: Chadwick Banning Date: Wed, 11 Apr 2018 14:45:21 -0400 Subject: [PATCH 2/2] Account for new attributes returned from the API and normalize them --- lib/puppet_forge_server/models/builder.rb | 7 ++++++- lib/puppet_forge_server/models/metadata.rb | 17 +++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/puppet_forge_server/models/builder.rb b/lib/puppet_forge_server/models/builder.rb index 22451d9..ad1507f 100644 --- a/lib/puppet_forge_server/models/builder.rb +++ b/lib/puppet_forge_server/models/builder.rb @@ -18,7 +18,12 @@ module PuppetForgeServer::Models class Builder def initialize(attributes={}) attributes.each do |name, value| - send("#{name}=", value) unless value.to_s.empty? + if name.to_s == 'decription' + normalized_name = :description + else + normalized_name = name.to_s.tr('-', '_').to_sym + end + send("#{normalized_name}=", value) unless value.to_s.empty? end end diff --git a/lib/puppet_forge_server/models/metadata.rb b/lib/puppet_forge_server/models/metadata.rb index c249fec..535338c 100644 --- a/lib/puppet_forge_server/models/metadata.rb +++ b/lib/puppet_forge_server/models/metadata.rb @@ -14,13 +14,14 @@ # See the License for the specific language governing permissions and # limitations under the License. - module PuppetForgeServer::Models class Metadata < Builder - attr_accessor :author, :name, :version, :dependencies, :summary, :description, :project_page, :types attr_accessor :checksums, :source, :license, :issues_url, :operatingsystem_support, :requirements attr_accessor :puppet_version, :tags, :mail, :classes, :definitions + attr_accessor :pdk_version, :template_url, :template_ref, :data_provider, :docs_project + attr_accessor :forge_url, :package_release_version, :issue_url + attr_accessor :kpn_quality_label, :kpn_module_owner, :kpn_module_support def initialize(attributes) super(attributes) @@ -28,9 +29,9 @@ def initialize(attributes) def ==(other) other && self.class.equal?(other.class) && - @author == other.author && - @name == other.name && - @version == other.version + @author == other.author && + @name == other.name && + @version == other.version end def hash @@ -39,9 +40,9 @@ def hash def eql?(other) other && self.class.equal?(other.class) && - @author.eql?(other.author) && - @name.eql?(other.name) && - @version.eql?(other.version) + @author.eql?(other.author) && + @name.eql?(other.name) && + @version.eql?(other.version) end end end