From 9e0edabed4cfc5156b698444e30f8937b3071c02 Mon Sep 17 00:00:00 2001 From: Steve Kowalik Date: Thu, 11 Jun 2015 16:12:36 +1000 Subject: [PATCH] Correctly determine the server id Due to using an undefined variable when determining the server id, the client manifest was writing an incorrectly formatted zanata.ini file. Furthermore, the intent of the change did not go far enough, since it would not strip off the URI scheme or port. Due to the complexities of parsing URIs in regular expressions, use a Puppet function for the heavy lifting. Change-Id: I754ee54f805c91f5548b2cf270b23c68eed3959c --- lib/puppet/parser/functions/parse_server_id.rb | 10 ++++++++++ manifests/client.pp | 4 ++-- templates/zanata.ini.erb | 6 +++--- 3 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 lib/puppet/parser/functions/parse_server_id.rb diff --git a/lib/puppet/parser/functions/parse_server_id.rb b/lib/puppet/parser/functions/parse_server_id.rb new file mode 100644 index 0000000..be131d1 --- /dev/null +++ b/lib/puppet/parser/functions/parse_server_id.rb @@ -0,0 +1,10 @@ +require 'uri' + +module Puppet::Parser::Functions + newfunction(:parse_server_id, :type => :rvalue) do |args| + uri = URI.parse(args[0]) + unless uri.host.nil? + uri.host.gsub(/\./, '_') + end + end +end diff --git a/manifests/client.pp b/manifests/client.pp index 64a8aab..11a8296 100644 --- a/manifests/client.pp +++ b/manifests/client.pp @@ -25,7 +25,7 @@ class zanata::client( $homedir = '/home/jenkins/', ) { - $serverid = regsubst($server, '\.', '_', 'G') + $server_id = parse_server_id($server_url) file { '/opt/zanata': ensure => directory, @@ -77,7 +77,7 @@ class zanata::client( ensure => present, } - file { "${homedir}/.config/zanata.ini": # XXX needs to be in homedir + file { "${homedir}/.config/zanata.ini": ensure => present, owner => $user, group => $group, diff --git a/templates/zanata.ini.erb b/templates/zanata.ini.erb index ca65567..d90e3fd 100644 --- a/templates/zanata.ini.erb +++ b/templates/zanata.ini.erb @@ -1,4 +1,4 @@ [servers] -<%= @serverid -%>.url=<%= @server_url %> -<%= @serverid -%>.username=<%= @server_user %> -<%= @serverid -%>.key=<%= @server_api_key %> +<%= @server_id -%>.url=<%= @server_url %> +<%= @server_id -%>.username=<%= @server_user %> +<%= @server_id -%>.key=<%= @server_api_key %>