foreman_templates 6.0.1 → 6.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d0c518e8c2822c6112f13654488a324eb9c2918a
4
- data.tar.gz: b32fab2dde41371d5367c8d95db70fd2eb85d0ab
3
+ metadata.gz: b21b717ee579458b7a0f5b4ba6ccd17df7f2c100
4
+ data.tar.gz: dbb379a9262aff5e3cd244ae7146d5fe0b2ae2d5
5
5
  SHA512:
6
- metadata.gz: b647c76ec12f0262f6dc95703487fee408ab094bb918b77f0df6141080cb90b3373cb7d4c27620488b75aa66c0d39450c033ed9ae9145e2cf023656189c3ee18
7
- data.tar.gz: '0981be0b744c1a1573fdf0c8c7cec0f82357679cb3873d7ff7264a5af6cc1348e8b8d38da4b9ea5e073b82366e2a79ca284f8b0a4e4037a9951b816c5d692902'
6
+ metadata.gz: 10bde89659cba8d0f0d7374888a6b7bdc2ecf5e002f6c14e8db2f411ddd55e8a378faaea1dde53c2749cc051bbda77a9c12eb1db1b74bfa612f7321f7e0d59ce
7
+ data.tar.gz: e140926347dbf5299c2a5eb58de6708d61bf84c03c432d55c4d898ca38a243a68b28894a9d13c14e19291617a68f53b238a4078a26a2583a423a5e3511124e2c
data/README.md CHANGED
@@ -2,7 +2,8 @@
2
2
 
3
3
  This plugin will sync the contents of the Foreman Community Templates
4
4
  [repository](https://github.com/theforeman/community-templates/) (or a git repo
5
- of your choice) to your local Foreman instance
5
+ of your choice) to your local Foreman instance. It can also be used to sync
6
+ local directory, therefore any other version control systems can be used.
6
7
 
7
8
  ## Installation
8
9
 
@@ -11,7 +12,7 @@ Foreman documentation for how to install Foreman plugins.
11
12
 
12
13
  The gem name is "foreman_templates".
13
14
 
14
- RPM users can install the "ruby193-rubygem-foreman_templates" or "rubygem-foreman_templates" packages.
15
+ RPM users can install the "tfm-rubygem-foreman_templates" or "rubygem-foreman_templates" packages.
15
16
 
16
17
  ## Latest code
17
18
 
@@ -26,124 +27,12 @@ These can be overriden for each import by passing options directly to a Rake tas
26
27
 
27
28
  ## Usage
28
29
 
29
- ### Import via Rake task
30
-
31
- The plugin provides a Rake task to import the templates. To use it, simply do
32
-
33
- foreman-rake templates:sync
34
-
35
- This will create a set of templates named "Community ...." (or update them if they
36
- already exist). Audit history is preserved, but no comment is currently added for
37
- any changes made.
38
-
39
- The importer will attempt to figure out the OS and Release the template refers to. If
40
- this is a new template being created, and we can find a matching OS in Foreman, the
41
- template will be automatically associated with the OS
42
-
43
- #### Rake options
44
-
45
- * verbose => Print extra information during the run [false]
46
- * repo => Sync templates from a different repo [https://github.com/theforeman/community-templates]. Importing from git and file system is supported.
47
- * branch => Branch in Git repo [_see note below_]
48
- * prefix => The string all imported templates should begin with [Community]
49
- * dirname => The directory within the git tree containing the templates [/]
50
- * filter => Import names matching this regex (case-insensitive; snippets are not filtered)
51
- * associate => Associate to OS, "always", when "new" or "never" [new]
52
- * lock => Lock imported templates [false]
53
-
54
- The `branch` default will use *develop* if you're on Foreman-nightly; or the
55
- matching *1.X-stable* branch for your version of Foreman (if it exists); or
56
- finally it will remain on the default branch as a fallback.
57
-
58
- Passing any option to a Rake task overrides its default value from a corresponding Setting.
59
-
60
- #### Examples
61
-
62
- Just import all the templates from the default repo
63
-
64
- foreman-rake templates:sync
65
-
66
- Import all templates from a custom repo, with a different prefix
67
-
68
- foreman-rake templates:sync repo="http://github.com/GregSutcliffe/community-templates" prefix="Greg"
69
-
70
- Import templates matching the name "Fedora"
71
-
72
- foreman-rake templates:sync filter='fedora'
73
-
74
- Import templates from a subdirectory of a git repo:
75
-
76
- foreman-rake templates:sync repo="http://github.com/GregSutcliffe/community-templates" dirname='/subdir'
77
-
78
- Import templates from file system:
79
-
80
- foreman-rake templates:sync repo="/path/to/my/templates"
81
-
82
- ### Purge
83
-
84
- This task deletes matching templates from the Foreman DB
85
-
86
- #### Rake options
87
-
88
- * prefix => The string all templates to be purged should begin with [Community ]
89
- * negate => Negate the search [false]
90
- * verbose => Print extra information during the run [false]
91
-
92
- #### Examples
93
-
94
- Just purge all the templates the begin with 'Community '
95
-
96
- foreman-rake templates:purge
97
-
98
- Purge all templates that begin with 'Oops '
99
-
100
- foreman-rake templates:purge prefix='Oops '
101
-
102
- Purge all templates that do not begin with 'Community '
103
-
104
- foreman-rake templates:purge negate=true
105
-
106
- ### Import and Export via API
107
-
108
- There is an API (`/template/import/`) to initiate import from external
109
- repository. The API uses Foreman's authorization and authentication
110
- mechanisms. There is also an export action available.
111
-
112
- Unfortunately, there is no CLI support yet. For examples about how to
113
- use the API, [visit our documentation](https://theforeman.org/plugins/foreman_templates/5.0/index.html#5.API).
30
+ For more detailed description, please see [the plugin manual](https://www.theforeman.org/plugins/foreman_templates/), select the approriate version
114
31
 
115
32
  ## Integration with other Foreman Plugins
116
33
 
117
- `templates` will start processing a template by looking for a metadata entry of
118
- `model`. If this is found, `templates` will call `import!` on this model.
119
-
120
- That means it's possible for a plugin to define it's own handling of text and
121
- metadata, relevant to the plugins own interests. The `import!` method will be
122
- sent 3 arguments - the `name` of the template, the `text` of the template, and
123
- a complete copy of the `metadata`.
124
-
125
- As a trivial example for a random plugin, suppose `foreman_nosuchplugin` has
126
- this code:
127
-
128
- ```
129
- module ForemanNosuchplugin
130
- class SomeTemplate
131
- def self.import!(name, text, metadata)
132
- File.open("/tmp/#{name}",'w') {|f| f.write text }
133
- end
134
- end
135
- end
136
- ```
137
-
138
- Assuming a template had "model: SomeTemplate" in it's metadata, this would then
139
- get written to a file in `/tmp`.
140
-
141
- `templates` will expect the `import!` method to return a Hash, containing:
142
-
143
- * `:status` (boolean),
144
- * `:diff` (text, may be nil), or
145
- * `:old` and `:new` (in which case this plugin will calculate the diff)
146
- * :result` (text, may be nil).
34
+ This plugin now fully relies on core importing capabilities. That means models inheriting from Template class are supported. To customize import behavior,
35
+ you can override `import_custom_data` in your inheritting class. See example at [remote execution plugin](https://github.com/theforeman/foreman_remote_execution/blob/v1.5.3/app/models/job_template.rb#L201-L217)
147
36
 
148
37
  ## Copyright
149
38
 
@@ -33,7 +33,9 @@ module ForemanTemplates
33
33
  end
34
34
 
35
35
  def verify_path!(path)
36
- raise "Using file-based synchronization, but couldn't find #{path}" unless Dir.exist?(path)
36
+ msg = _("Using file-based synchronization, but couldn't access %s to export templates. ") % path
37
+ msg += _("Please check the access permissions/SELinux and make sure it is writable for the web application user account, typically 'foreman'.")
38
+ raise msg unless Dir.exist?(path)
37
39
  end
38
40
 
39
41
  private
@@ -128,7 +128,12 @@ module ForemanTemplates
128
128
  private
129
129
 
130
130
  def find_templates
131
- @taxonomies.values.all?(&:empty?) ? Template.all : find_taxed_templates
131
+ @taxonomies.values.all?(&:empty?) ? find_all_templates : find_taxed_templates
132
+ end
133
+
134
+ # We have to go through subclasses because Template does not include Taxonomix
135
+ def find_all_templates
136
+ Template.subclasses.flat_map(&:all)
132
137
  end
133
138
 
134
139
  def find_taxed_templates
@@ -47,8 +47,8 @@ module ForemanTemplates
47
47
  end
48
48
 
49
49
  def parse_files!
50
- Dir["#{@dir}#{@dirname}/**/*.erb"].each do |template_file|
51
- logger.debug 'Parsing: ' + template_file.gsub(/#{@dir}#{@dirname}/, '')
50
+ Dir["#{@dir}/#{@dirname}/**/*.erb"].each do |template_file|
51
+ logger.debug 'Parsing: ' + template_file.gsub(%r{#{@dir}\/#{@dirname}}, '')
52
52
  parse_result = ParseResult.new(template_file)
53
53
 
54
54
  text = File.read(template_file)
@@ -81,8 +81,8 @@ module ForemanTemplates
81
81
  { :force => @force,
82
82
  :associate => @associate,
83
83
  :lock => @lock,
84
- :organization_params => @organizations,
85
- :location_params => @locations }
84
+ :organization_params => @taxonomies[:organizations],
85
+ :location_params => @taxonomies[:locations] }
86
86
  end
87
87
 
88
88
  def template_model(metadata, parse_result)
@@ -1,3 +1,3 @@
1
1
  module ForemanTemplates
2
- VERSION = '6.0.1'.freeze
2
+ VERSION = '6.0.2'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_templates
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.1
4
+ version: 6.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Greg Sutcliffe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-17 00:00:00.000000000 Z
11
+ date: 2018-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: diffy
@@ -77,7 +77,7 @@ files:
77
77
  - lib/foreman_templates/engine.rb
78
78
  - lib/foreman_templates/version.rb
79
79
  - lib/tasks/foreman_templates_tasks.rake
80
- homepage: http://github.com/theforeman/foreman_templates
80
+ homepage: https://github.com/theforeman/foreman_templates
81
81
  licenses:
82
82
  - GPL-3
83
83
  metadata: {}