Module: Puppet::Util::Webapp
Defined Under Namespace
Classes: WebappError
Constant Summary collapse
- NAME_PATTERN =
'(\S+)::(\/?\S*)'
- PATH_PATTERN =
'\S*\/(\S+)\/htdocs(-secure)?(\/\S*)?'
- APP_PATTERN =
'(\S+)\s(\S+)'
- NAME_REGEX =
Regexp.new "^#{NAME_PATTERN}$"
- PATH_REGEX =
Regexp.new "^#{PATH_PATTERN}$"
- APP_REGEX =
Regexp.new "^#{APP_PATTERN}$"
Instance Method Summary collapse
-
#build_opts(hash, *args) ⇒ Array
Build webapp-config options from webapp properties.
-
#fix_dir(dir) ⇒ String
Fix empty directory strings.
-
#format_webapp(hash) ⇒ String
Format webapp properties to a webapp name.
-
#parse_app(app) ⇒ Hash
Parse an app into appname and appversion.
-
#parse_name(name) ⇒ Hash
Parse a webapp name into host and dir.
-
#parse_path(path) ⇒ Hash
Parse a webapp path into webapp properties.
-
#parse_resource(resource) ⇒ Hash
Parse a webapp resource into webapp properties.
-
#valid_app?(app) ⇒ TrueClass, FalseClass
Determine if a string is a valid app.
-
#valid_name?(name) ⇒ TrueClass, FalseClass
Determine if a string is a valid webapp name.
-
#valid_path?(path) ⇒ TrueClass, FalseClass
Determine if a string is a valid webapp path.
Instance Method Details
#build_opts(hash, *args) ⇒ Array
Build webapp-config options from webapp properties
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/puppet/util/webapp.rb', line 60 def build_opts(hash, *args) opts = args hash.each do |key, value| case key when :secure, :soft value == :yes && opts << '--%s' % key when :appname, :appversion when :name else opts << '--%s' % key << value end end opts << hash[:appname] opts << hash[:appversion] opts.compact end |
#fix_dir(dir) ⇒ String
Fix empty directory strings
51 52 53 |
# File 'lib/puppet/util/webapp.rb', line 51 def fix_dir(dir) (dir.nil? || dir.empty?) && '/' || dir end |
#format_webapp(hash) ⇒ String
Format webapp properties to a webapp name
147 148 149 |
# File 'lib/puppet/util/webapp.rb', line 147 def format_webapp(hash) '%s::%s' % [hash[:host], hash[:dir]] end |
#parse_app(app) ⇒ Hash
Parse an app into appname and appversion
117 118 119 120 121 122 123 124 125 126 |
# File 'lib/puppet/util/webapp.rb', line 117 def parse_app(app) if (match = app.match(APP_REGEX)) { :appname => match[1], :appversion => match[2], } else raise WebappError, "#{app} is not a valid app string" end end |
#parse_name(name) ⇒ Hash
Parse a webapp name into host and dir
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/puppet/util/webapp.rb', line 82 def parse_name(name) if (match = name.match(NAME_REGEX)) { :host => match[1], :dir => fix_dir(match[2]) } else raise WebappError, "#{name} is not a valid webapp name" end end |
#parse_path(path) ⇒ Hash
Parse a webapp path into webapp properties
98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/puppet/util/webapp.rb', line 98 def parse_path(path) if (match = path.match(PATH_REGEX)) host, secure, dir = match[1], match[2], fix_dir(match[3]) { :name => '%s::%s' % [host, dir], :host => host, :dir => dir, :secure => secure.nil? && :no || :yes } else raise WebappError, "#{path} is not a valid webapp path" end end |
#parse_resource(resource) ⇒ Hash
Parse a webapp resource into webapp properties
133 134 135 136 137 138 139 140 |
# File 'lib/puppet/util/webapp.rb', line 133 def parse_resource(resource) webapp = parse_name(resource[:name]) keys = [:appname, :appversion, :server, :user, :group, :soft, :secure] keys.each do |key| resource[key] && webapp[key] = resource[key] end webapp end |
#valid_app?(app) ⇒ TrueClass, FalseClass
Determine if a string is a valid app
42 43 44 |
# File 'lib/puppet/util/webapp.rb', line 42 def valid_app?(app) !!(app =~ APP_REGEX) end |
#valid_name?(name) ⇒ TrueClass, FalseClass
Determine if a string is a valid webapp name
22 23 24 |
# File 'lib/puppet/util/webapp.rb', line 22 def valid_name?(name) !!(name =~ NAME_REGEX) end |
#valid_path?(path) ⇒ TrueClass, FalseClass
Determine if a string is a valid webapp path
32 33 34 |
# File 'lib/puppet/util/webapp.rb', line 32 def valid_path?(path) !!(path =~ PATH_REGEX) end |