simp-metadata 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +0 -0
- data/Rakefile +69 -0
- data/exe/simp-install +8 -0
- data/exe/simp-media +8 -0
- data/exe/simp-metadata +8 -0
- data/lib/simp/install.rb +0 -0
- data/lib/simp/install/command.rb +70 -0
- data/lib/simp/media.rb +9 -0
- data/lib/simp/media/command.rb +69 -0
- data/lib/simp/media/engine.rb +104 -0
- data/lib/simp/media/type.rb +14 -0
- data/lib/simp/media/type/base.rb +63 -0
- data/lib/simp/media/type/control-repo.rb +211 -0
- data/lib/simp/media/type/internet.rb +38 -0
- data/lib/simp/media/type/iso.rb +9 -0
- data/lib/simp/media/type/local.rb +36 -0
- data/lib/simp/media/type/tar.rb +71 -0
- data/lib/simp/metadata.rb +416 -0
- data/lib/simp/metadata/bootstrap_source.rb +137 -0
- data/lib/simp/metadata/buildinfo.rb +58 -0
- data/lib/simp/metadata/command.rb +92 -0
- data/lib/simp/metadata/commands.rb +21 -0
- data/lib/simp/metadata/commands/base.rb +65 -0
- data/lib/simp/metadata/commands/clone.rb +26 -0
- data/lib/simp/metadata/commands/component.rb +109 -0
- data/lib/simp/metadata/commands/delete.rb +26 -0
- data/lib/simp/metadata/commands/pry.rb +19 -0
- data/lib/simp/metadata/commands/release.rb +47 -0
- data/lib/simp/metadata/commands/releases.rb +24 -0
- data/lib/simp/metadata/commands/save.rb +33 -0
- data/lib/simp/metadata/commands/script.rb +38 -0
- data/lib/simp/metadata/commands/search.rb +65 -0
- data/lib/simp/metadata/commands/set-write-url.rb +19 -0
- data/lib/simp/metadata/commands/set-write.rb +19 -0
- data/lib/simp/metadata/commands/update.rb +46 -0
- data/lib/simp/metadata/component.rb +388 -0
- data/lib/simp/metadata/components.rb +70 -0
- data/lib/simp/metadata/engine.rb +101 -0
- data/lib/simp/metadata/fake_uri.rb +19 -0
- data/lib/simp/metadata/git_ssh_wrapper.sh +6 -0
- data/lib/simp/metadata/location.rb +198 -0
- data/lib/simp/metadata/locations.rb +54 -0
- data/lib/simp/metadata/release.rb +119 -0
- data/lib/simp/metadata/releases.rb +57 -0
- data/lib/simp/metadata/source.rb +204 -0
- data/spec/simp/media/command_spec.rb +12 -0
- data/spec/simp/media/engine_spec.rb +28 -0
- data/spec/simp/media/type/control_repo_spec.rb +23 -0
- data/spec/simp/media/type/internet_spec.rb +29 -0
- data/spec/simp/media/type/iso_spec.rb +15 -0
- data/spec/simp/media/type/local_spec.rb +16 -0
- data/spec/simp/media/type/tar_spec.rb +16 -0
- data/spec/simp/metadata/buildinfo_spec.rb +64 -0
- data/spec/simp/metadata/commands/clone_spec.rb +8 -0
- data/spec/simp/metadata/component_spec.rb +90 -0
- data/spec/simp/metadata/engine_spec.rb +70 -0
- data/spec/simp/metadata/release_spec.rb +104 -0
- data/spec/simp/metadata/source_spec.rb +25 -0
- data/spec/simp/metadata_spec.rb +175 -0
- data/spec/spec_helper.rb +40 -0
- metadata +260 -0
@@ -0,0 +1,211 @@
|
|
1
|
+
module Simp
|
2
|
+
module Media
|
3
|
+
module Type
|
4
|
+
class Control_repo < Simp::Media::Type::Base
|
5
|
+
attr_accessor :options
|
6
|
+
def initialize(options, engine)
|
7
|
+
super(options, engine)
|
8
|
+
@cleanup = []
|
9
|
+
if (options["output"] == nil)
|
10
|
+
raise "output must be specified for control-repo output"
|
11
|
+
end
|
12
|
+
@origtempdir = Dir.mktmpdir("cachedir")
|
13
|
+
@repopath = "#{@origtempdir}/control-repo"
|
14
|
+
FileUtils.mkdir_p(@repopath)
|
15
|
+
@cleanup << @origtempdir
|
16
|
+
exit_code = run("git clone #{options["output"]} #{@repopath}")
|
17
|
+
unless (exit_code.success?)
|
18
|
+
uri = URI(options["output"])
|
19
|
+
if (uri.scheme == "file")
|
20
|
+
FileUtils.mkdir_p(uri.path)
|
21
|
+
Dir.chdir(uri.path) do |path|
|
22
|
+
if (uri.path =~ /.*\.git$/)
|
23
|
+
run("git init --bare")
|
24
|
+
else
|
25
|
+
run("git init")
|
26
|
+
end
|
27
|
+
|
28
|
+
run("git clone #{options["output"]} #{@repopath}")
|
29
|
+
end
|
30
|
+
else
|
31
|
+
raise "output is not a valid control-repo"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
Dir.chdir(@repopath) do |path|
|
35
|
+
exit_code = run("git checkout #{options["branch"]}")
|
36
|
+
unless exit_code.success?
|
37
|
+
exit_code = run("git checkout -b #{options["branch"]}")
|
38
|
+
unless (exit_code.success?)
|
39
|
+
raise "error, unable to checkout #{options["branch"]} in git repo #{uri}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
@branch = options["branch"]
|
43
|
+
if (options["destination_branch"] != nil)
|
44
|
+
@branch = options["destination_branch"]
|
45
|
+
exit_code = run("git checkout -b #{options["destination_branch"]}")
|
46
|
+
unless exit_code.success?
|
47
|
+
raise "error, unable to create branch #{options["destination_branch"]} in git repo #{uri}"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
run("rm -rf SIMP/modules")
|
51
|
+
run("rm -rf SIMP/assets")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def add_component(component, fetch_return_value)
|
56
|
+
if (options["embed"] == true)
|
57
|
+
# XXX ToDo: Copy components to control-repo if embed == true
|
58
|
+
case component.component_type
|
59
|
+
when "documentation"
|
60
|
+
when "simp-metadata"
|
61
|
+
subdirectory = "SIMP/metadata"
|
62
|
+
outputpath = "#{@repopath}/#{subdirectory}/#{component.name}"
|
63
|
+
FileUtils.mkdir_p(outputpath)
|
64
|
+
if (Dir.exists?("#{fetch_return_value['path']}/.git"))
|
65
|
+
exit_code = run("cd #{fetch_return_value['path']} && git --work-tree=\"#{outputpath}\" checkout #{component.version} .")
|
66
|
+
else
|
67
|
+
exit_code = run("cd #{fetch_return_value['path']} && tar -cf - . | tar -xvpf - -C \"#{outputpath}\"")
|
68
|
+
end
|
69
|
+
|
70
|
+
unless exit_code.success?
|
71
|
+
error "unable to copy #{component.name} to #{outputpath}: error code #{exit_code.exitstatus}"
|
72
|
+
end
|
73
|
+
when "puppet-module"
|
74
|
+
subdirectory = "SIMP/modules"
|
75
|
+
outputpath = "#{@repopath}/#{subdirectory}/#{component.module_name}"
|
76
|
+
debug2("Copying #{component.module_name} to #{outputpath}")
|
77
|
+
FileUtils.mkdir_p(outputpath)
|
78
|
+
exit_code = run("cd #{fetch_return_value['path']} && git --work-tree=\"#{outputpath}\" checkout #{component.version} .")
|
79
|
+
unless exit_code.success?
|
80
|
+
error "unable to copy #{component.module_name} to #{outputpath}: error code #{exit_code.exitstatus}"
|
81
|
+
end
|
82
|
+
else
|
83
|
+
subdirectory = "SIMP/assets/#{component.name}"
|
84
|
+
case component.output_type
|
85
|
+
when :file
|
86
|
+
FileUtils.mkdir_p("#{@repopath}/#{subdirectory}")
|
87
|
+
FileUtils.cp(fetch_return_value["path"], "#{@repopath}/#{subdirectory}/#{component.output_filename}")
|
88
|
+
end
|
89
|
+
end
|
90
|
+
else
|
91
|
+
# XXX ToDo: Add necessary references to generate the puppetfile during finalize
|
92
|
+
raise "not yet implemented"
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
def finalize(manifest)
|
98
|
+
# XXX ToDo: Generate Puppetfile (if options["embed"] == false)
|
99
|
+
# Otherwise copy to control-repo
|
100
|
+
# XXX ToDo: Munge Puppetfile
|
101
|
+
environmentconf = "#{@repopath}/environment.conf"
|
102
|
+
hierayaml = "#{@repopath}/hiera.yaml"
|
103
|
+
# XXX ToDo: Munge hiera.yaml
|
104
|
+
self.munge_hierayaml(hierayaml)
|
105
|
+
if (options["embed"] == true)
|
106
|
+
self.munge_environmentconf(environmentconf)
|
107
|
+
end
|
108
|
+
run("cd #{@repopath} && git add -A")
|
109
|
+
run("cd #{@repopath} && git commit -m \"simp-install: upgrade to #{options["version"]}\"")
|
110
|
+
run("cd #{@repopath} && git push origin #{@branch}")
|
111
|
+
end
|
112
|
+
|
113
|
+
def munge_environmentconf(environmentconf)
|
114
|
+
# Munge environment.conf to add SIMP/modules to modulepath
|
115
|
+
if (File.exists?(environmentconf))
|
116
|
+
data = File.read(environmentconf).split("\n")
|
117
|
+
data.each_with_index do |line, fileline|
|
118
|
+
if (/^modulepath = (?<capture>.*)$/ =~ line)
|
119
|
+
paths = capture.split(":")
|
120
|
+
found = false
|
121
|
+
module_index = nil
|
122
|
+
paths.each_with_index do |path, index|
|
123
|
+
if (path =~ /modules/)
|
124
|
+
module_index = index
|
125
|
+
end
|
126
|
+
if (path =~ /simp\/modules/)
|
127
|
+
found = true
|
128
|
+
end
|
129
|
+
end
|
130
|
+
if (found == false)
|
131
|
+
newarray = []
|
132
|
+
paths.each do |path, index|
|
133
|
+
newarray << path
|
134
|
+
if (index == module_index)
|
135
|
+
newarray << "SIMP/modules"
|
136
|
+
end
|
137
|
+
end
|
138
|
+
data[fileline] = "modulepath = #{newarray.join(":")}"
|
139
|
+
File.open(environmentconf, "w") { |f| f.write(data.join("\n")) }
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
else
|
144
|
+
File.open(environmentconf, "w") { |f| f.write("modulepath = modules:SIMP/modules:$basemodulepath\n") }
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
def munge_hierayaml(hierayaml)
|
149
|
+
data = {}
|
150
|
+
if (File.exists?(hierayaml))
|
151
|
+
data = YAML.load(File.read(hierayaml))
|
152
|
+
version = data["version"]
|
153
|
+
case version
|
154
|
+
when 4
|
155
|
+
# XXX ToDo: Add version 4 hiera.yaml support
|
156
|
+
raise "currently version 4 hiera.yaml's are not supported"
|
157
|
+
when 5
|
158
|
+
found = false
|
159
|
+
data["hierarchy"].each_with_index do |hash|
|
160
|
+
if (hash["lookup_key"] == "compliance_markup::enforcement")
|
161
|
+
found = true
|
162
|
+
end
|
163
|
+
end
|
164
|
+
if (found == false)
|
165
|
+
hash = {"name" => "SIMP Compliance Engine", "lookup_key" => "compliance_markup::enforcement"}
|
166
|
+
data["hierarchy"] << hash
|
167
|
+
end
|
168
|
+
when nil
|
169
|
+
# XXX ToDo: Add version 3 hiera.yaml support
|
170
|
+
raise "currently version 3 hiera.yaml's are not supported"
|
171
|
+
return 0
|
172
|
+
end
|
173
|
+
else
|
174
|
+
raw_yaml = <<-EOF
|
175
|
+
---
|
176
|
+
version: 5
|
177
|
+
defaults:
|
178
|
+
datadir: "data"
|
179
|
+
data_hash: "yaml_data"
|
180
|
+
hierarchy:
|
181
|
+
- name: 'SIMP Defaults'
|
182
|
+
paths:
|
183
|
+
- 'hosts/%{trusted.certname}'
|
184
|
+
- 'domains/%{facts.domain}'
|
185
|
+
- '%{facts.os.family}'
|
186
|
+
- '%{facts.os.name}/%{facts.os.release.full}'
|
187
|
+
- '%{facts.os.name}/%{facts.os.release.major}'
|
188
|
+
- '%{facts.os.name}'
|
189
|
+
- 'hostgroups/%{::hostgroup}'
|
190
|
+
- 'hosttypes/%{::hosttype}'
|
191
|
+
- 'users'
|
192
|
+
- 'groups'
|
193
|
+
- 'type/%{::nodetype}/common.yaml'
|
194
|
+
- 'default'
|
195
|
+
- 'simp_config_settings'
|
196
|
+
- name: 'SIMP Compliance Engine'
|
197
|
+
lookup_key: 'compliance_markup::enforcement'
|
198
|
+
EOF
|
199
|
+
data = YAML.load(raw_yaml)
|
200
|
+
end
|
201
|
+
File.open(hierayaml, "w") { |f| f.write(data.to_yaml)}
|
202
|
+
end
|
203
|
+
def cleanup()
|
204
|
+
@cleanup.each do |path|
|
205
|
+
FileUtils.rmtree(path)
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
|
2
|
+
require 'open3'
|
3
|
+
|
4
|
+
module Simp
|
5
|
+
module Media
|
6
|
+
module Type
|
7
|
+
class Internet < Simp::Media::Type::Base
|
8
|
+
attr_accessor :options
|
9
|
+
def initialize(options, engine)
|
10
|
+
@cleanup = []
|
11
|
+
super(options, engine)
|
12
|
+
end
|
13
|
+
|
14
|
+
def input_directory=(directory)
|
15
|
+
@input_directory = directory
|
16
|
+
end
|
17
|
+
def input_directory
|
18
|
+
if (@input_directory == nil)
|
19
|
+
target = Dir.mktmpdir("cachedir")
|
20
|
+
@cleanup << target
|
21
|
+
@input_directory = target
|
22
|
+
else
|
23
|
+
@input_directory
|
24
|
+
end
|
25
|
+
end
|
26
|
+
def fetch_component(component, options)
|
27
|
+
Simp::Metadata.download_component(component, options.merge({"target" => self.input_directory}))
|
28
|
+
end
|
29
|
+
|
30
|
+
def cleanup()
|
31
|
+
@cleanup.each do |path|
|
32
|
+
FileUtils.rmtree(path)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
module Simp
|
3
|
+
module Media
|
4
|
+
module Type
|
5
|
+
class Local < Simp::Media::Type::Base
|
6
|
+
def input_directory=(directory)
|
7
|
+
@input_directory = directory
|
8
|
+
end
|
9
|
+
def input_directory
|
10
|
+
@options["input"]
|
11
|
+
end
|
12
|
+
def fetch_component(component, options)
|
13
|
+
retval = {}
|
14
|
+
|
15
|
+
case component.class.to_s
|
16
|
+
when "String"
|
17
|
+
retval["path"] = "#{options["input"]}/simp/metadata/#{component.name}"
|
18
|
+
when "Simp::Metadata::Component"
|
19
|
+
# XXX ToDo: Add manifest.yaml support so we don't need this logic at all
|
20
|
+
case component.component_type
|
21
|
+
when "documentation"
|
22
|
+
subdirectory = "simp/docs"
|
23
|
+
when "puppet-module"
|
24
|
+
subdirectory = "simp/modules"
|
25
|
+
else
|
26
|
+
subdirectory = "simp/assets"
|
27
|
+
end
|
28
|
+
|
29
|
+
retval["path"] = "#{options["input"]}/#{subdirectory}/#{component.name}"
|
30
|
+
end
|
31
|
+
return retval
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
module Simp
|
3
|
+
module Media
|
4
|
+
module Type
|
5
|
+
class Tar < Simp::Media::Type::Base
|
6
|
+
|
7
|
+
def initialize(options, engine)
|
8
|
+
@cleanup = []
|
9
|
+
|
10
|
+
@origtempdir = Dir.mktmpdir("cachedir")
|
11
|
+
@tempdir = @origtempdir + "/" + File.basename(options["output"], ".*")
|
12
|
+
@cleanup << @origtempdir
|
13
|
+
super(options, engine)
|
14
|
+
end
|
15
|
+
|
16
|
+
def add_component(component, fetch_return_value)
|
17
|
+
case component.component_type
|
18
|
+
when "documentation"
|
19
|
+
subdirectory = "SIMP/docs"
|
20
|
+
when "simp-metadata"
|
21
|
+
subdirectory = "SIMP/metadata"
|
22
|
+
when "puppet-module"
|
23
|
+
subdirectory = "SIMP/modules"
|
24
|
+
else
|
25
|
+
subdirectory = "SIMP/assets/#{component.name}"
|
26
|
+
end
|
27
|
+
case component.output_type
|
28
|
+
when :directory
|
29
|
+
if (Dir.exists?(fetch_return_value["path"]))
|
30
|
+
unless (Dir.exists?(@tempdir + "/#{subdirectory}/#{component.name}"))
|
31
|
+
FileUtils.mkdir_p(@tempdir + "/#{subdirectory}/#{component.name}")
|
32
|
+
end
|
33
|
+
FileUtils.cp_r(fetch_return_value["path"] + "/.", @tempdir + "/#{subdirectory}/#{component.output_filename}")
|
34
|
+
else
|
35
|
+
raise "Unable to find component #{component.name} in input source: path=#{fetch_return_value["path"]}"
|
36
|
+
end
|
37
|
+
when :file
|
38
|
+
if (File.exists?(fetch_return_value["path"]))
|
39
|
+
FileUtils.mkdir_p(@tempdir + "/#{subdirectory}")
|
40
|
+
FileUtils.cp_r(fetch_return_value["path"], @tempdir + "/#{subdirectory}/#{component.output_filename}")
|
41
|
+
else
|
42
|
+
raise "Unable to find component #{component.name} in input source: path=#{fetch_return_value["path"]}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
def finalize(manifest)
|
49
|
+
if @options.key?("local_directory")
|
50
|
+
if Dir.exists?(@options["local_directory"])
|
51
|
+
FileUtils.cp_r(Dir.glob(@options["local_directory"] + "/*"), @tempdir)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
Dir.chdir(@origtempdir) do
|
55
|
+
`tar -cf - * | gzip -9nc >#{@options["output"]}`
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def output(options, directory, version, metadata, output)
|
60
|
+
metadata.releases[version].components.each do |component|
|
61
|
+
end
|
62
|
+
end
|
63
|
+
def cleanup()
|
64
|
+
@cleanup.each do |path|
|
65
|
+
FileUtils.rmtree(path)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,416 @@
|
|
1
|
+
# vim: set expandtab ts=2 sw=2:
|
2
|
+
require 'open3'
|
3
|
+
require 'tempfile'
|
4
|
+
require 'tmpdir'
|
5
|
+
require 'net/http'
|
6
|
+
require 'uri'
|
7
|
+
require 'openssl'
|
8
|
+
require 'json'
|
9
|
+
require 'simp/metadata/engine'
|
10
|
+
require 'simp/metadata/fake_uri'
|
11
|
+
|
12
|
+
require 'simp/metadata/source'
|
13
|
+
require 'simp/metadata/bootstrap_source'
|
14
|
+
|
15
|
+
require 'simp/metadata/releases'
|
16
|
+
require 'simp/metadata/release'
|
17
|
+
|
18
|
+
require 'simp/metadata/components'
|
19
|
+
require 'simp/metadata/component'
|
20
|
+
require 'simp/metadata/buildinfo'
|
21
|
+
|
22
|
+
require 'simp/metadata/locations'
|
23
|
+
require 'simp/metadata/location'
|
24
|
+
|
25
|
+
module Simp
|
26
|
+
module Metadata
|
27
|
+
|
28
|
+
def self.directory_name(component, options)
|
29
|
+
if (options["target"] != nil)
|
30
|
+
basedir = options["target"]
|
31
|
+
else
|
32
|
+
raise "Must specify 'target'"
|
33
|
+
end
|
34
|
+
case component.class.to_s
|
35
|
+
when "String"
|
36
|
+
"#{basedir}/#{component}"
|
37
|
+
when "Simp::Metadata::Component"
|
38
|
+
"#{basedir}/#{component.output_filename}"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# XXX: ToDo this entire logic stream is crappy.
|
43
|
+
# We need to replace this with a much more simplified version.
|
44
|
+
def self.download_component(component, options)
|
45
|
+
directory_name = self.directory_name(component, options)
|
46
|
+
retval = {}
|
47
|
+
case component.class.to_s
|
48
|
+
when "String"
|
49
|
+
retval["path"] = self.directory_name(component, options)
|
50
|
+
# XXX: ToDo We can bootstrap this with a hard coded source in the simp engine
|
51
|
+
bootstrapped_components = {
|
52
|
+
"simp-metadata" => {
|
53
|
+
"url" => "https://github.com/simp/simp-metadata",
|
54
|
+
"method" => "git"
|
55
|
+
},
|
56
|
+
"enterprise-metadata" => {
|
57
|
+
"url" => "simp-enterprise:///enterprise-metadata?version=master&filetype=tgz",
|
58
|
+
"method" => "file",
|
59
|
+
"extract" => true,
|
60
|
+
},
|
61
|
+
}
|
62
|
+
# All this should be removed and be based on component.file_type
|
63
|
+
componentspec = bootstrapped_components[component]
|
64
|
+
if (componentspec["extract"] == true)
|
65
|
+
tarball = "#{directory_name}.tgz"
|
66
|
+
fetch_from_url(componentspec, tarball, nil, options)
|
67
|
+
unless Dir.exists?(retval["path"])
|
68
|
+
Dir.mkdir(retval["path"])
|
69
|
+
end
|
70
|
+
`tar -xvpf #{tarball} -C #{retval["path"]}`
|
71
|
+
else
|
72
|
+
fetch_from_url(componentspec, retval["path"], nil, options)
|
73
|
+
end
|
74
|
+
when "Simp::Metadata::Component"
|
75
|
+
retval["path"] = directory_name
|
76
|
+
if (options["url"])
|
77
|
+
location = component.primary
|
78
|
+
location.url = options["url"]
|
79
|
+
urlspec = location
|
80
|
+
location.method = "git"
|
81
|
+
else
|
82
|
+
urlspec = component.primary
|
83
|
+
end
|
84
|
+
fetch_from_url(urlspec, retval["path"], component, options)
|
85
|
+
else
|
86
|
+
raise "component.class=#{component.class.to_s}, #{component.class.to_s} is not in ['String', 'Simp::Metadata::Component']"
|
87
|
+
end
|
88
|
+
return retval
|
89
|
+
end
|
90
|
+
|
91
|
+
def self.uri(url)
|
92
|
+
case url
|
93
|
+
when /git@/
|
94
|
+
uri = Simp::Metadata::FakeURI.new(uri)
|
95
|
+
uri.scheme = "ssh"
|
96
|
+
uri
|
97
|
+
else
|
98
|
+
URI(url)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def self.fetch_from_url(urlspec, target, component = nil, options)
|
103
|
+
case urlspec.class.to_s
|
104
|
+
when "Simp::Metadata::Location"
|
105
|
+
url = urlspec.url
|
106
|
+
uri = uri(url)
|
107
|
+
method = urlspec.method
|
108
|
+
when "Hash"
|
109
|
+
url = urlspec["url"]
|
110
|
+
uri = uri(urlspec["url"])
|
111
|
+
if (urlspec.key?("method"))
|
112
|
+
method = urlspec["method"]
|
113
|
+
else
|
114
|
+
# XXX ToDo remove once the upstream simp-metadata has been updated so type != method
|
115
|
+
if (urlspec.key?("type"))
|
116
|
+
if (urlspec["type"] == "git")
|
117
|
+
method = "git"
|
118
|
+
else
|
119
|
+
method = "file"
|
120
|
+
end
|
121
|
+
else
|
122
|
+
method = "file"
|
123
|
+
end
|
124
|
+
end
|
125
|
+
when "String"
|
126
|
+
url = urlspec
|
127
|
+
uri = uri(urlspec)
|
128
|
+
method = "file"
|
129
|
+
end
|
130
|
+
case method
|
131
|
+
when "git"
|
132
|
+
case uri.scheme
|
133
|
+
when "simp"
|
134
|
+
fetch_simp_enterprise(url, target, component, urlspec, options)
|
135
|
+
when "simp-enterprise"
|
136
|
+
fetch_simp_enterprise(url, target, component, urlspec, options)
|
137
|
+
else
|
138
|
+
unless (Dir.exists?(target))
|
139
|
+
info("Cloning from #{url}")
|
140
|
+
run("git clone #{url} #{target}")
|
141
|
+
else
|
142
|
+
Dir.chdir(target) do
|
143
|
+
info("Updating from #{url}")
|
144
|
+
run("git pull origin")
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
when "file"
|
149
|
+
case uri.scheme
|
150
|
+
when "simp"
|
151
|
+
fetch_simp_enterprise(url, target, component, urlspec, options)
|
152
|
+
when "simp-enterprise"
|
153
|
+
fetch_simp_enterprise(url, target, component, urlspec, options)
|
154
|
+
when "http"
|
155
|
+
fetch_simp_enterprise(url, target, component, urlspec, options)
|
156
|
+
when "https"
|
157
|
+
fetch_simp_enterprise(url, target, component, urlspec, options)
|
158
|
+
else
|
159
|
+
raise "unsupported url type #{uri.scheme}"
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
def self.get_license_data(filename)
|
165
|
+
ret_filename = nil
|
166
|
+
ret_data = ""
|
167
|
+
license_data = ENV.fetch('SIMP_LICENSE_KEY', nil)
|
168
|
+
if (license_data != nil)
|
169
|
+
# Environment data trumps all
|
170
|
+
ret_data = license_data
|
171
|
+
if ($simp_license_temp == nil)
|
172
|
+
$simp_license_temp = Tempfile.new('license_data')
|
173
|
+
$simp_license_temp.write(license_data)
|
174
|
+
end
|
175
|
+
ret_filename = $simp_license_temp.path
|
176
|
+
else
|
177
|
+
if (filename.class.to_s == "String")
|
178
|
+
# Attempt to load from the filename passed
|
179
|
+
ret_filename = filename
|
180
|
+
else
|
181
|
+
# Try to load from /etc/simp/license.key file
|
182
|
+
ret_filename = "/etc/simp/license.key"
|
183
|
+
end
|
184
|
+
if (File.exists?(ret_filename))
|
185
|
+
ret_data = File.read(ret_filename)
|
186
|
+
else
|
187
|
+
if ($simp_license_temp == nil)
|
188
|
+
$simp_license_temp = Tempfile.new('license_data')
|
189
|
+
$simp_license_temp.write("")
|
190
|
+
end
|
191
|
+
ret_filename = $simp_license_temp.path
|
192
|
+
end
|
193
|
+
end
|
194
|
+
return ret_filename, ret_data
|
195
|
+
end
|
196
|
+
|
197
|
+
def self.fetch_simp_enterprise(url, destination, component, location = nil, options)
|
198
|
+
if (location.class.to_s == "Simp::Metadata::Location")
|
199
|
+
extract = location.extract
|
200
|
+
else
|
201
|
+
extract = false
|
202
|
+
end
|
203
|
+
uri = uri(url)
|
204
|
+
case uri.scheme
|
205
|
+
when "simp-enterprise"
|
206
|
+
scheme = "https"
|
207
|
+
host = 'enterprise-download.simp-project.com'
|
208
|
+
filetype = 'tgz'
|
209
|
+
if (component != nil)
|
210
|
+
if (component.extension != "")
|
211
|
+
filetype = component.extension
|
212
|
+
end
|
213
|
+
end
|
214
|
+
version = 'latest'
|
215
|
+
if (component != nil)
|
216
|
+
if (component.version != "")
|
217
|
+
version = component.version
|
218
|
+
end
|
219
|
+
end
|
220
|
+
if (uri.query != nil)
|
221
|
+
uri.query.split("&").each do |element|
|
222
|
+
if (element.class.to_s == "String")
|
223
|
+
elements = element.split("=")
|
224
|
+
if (elements.size > 1)
|
225
|
+
case elements[0]
|
226
|
+
when "version"
|
227
|
+
version = elements[1]
|
228
|
+
when "filetype"
|
229
|
+
filetype = elements[1]
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
if (component != nil)
|
237
|
+
name = "/#{component.name}/#{component.binaryname}"
|
238
|
+
else
|
239
|
+
name = "#{uri.path}#{uri.path}#{name}-#{version}.#{filetype}"
|
240
|
+
end
|
241
|
+
path = "/products/simp-enterprise#{name}"
|
242
|
+
when "simp"
|
243
|
+
scheme = "https"
|
244
|
+
host = 'download.simp-project.com'
|
245
|
+
filetype = 'tgz'
|
246
|
+
if (component != nil)
|
247
|
+
if (component.extension != "")
|
248
|
+
filetype = component.extension
|
249
|
+
end
|
250
|
+
end
|
251
|
+
version = 'latest'
|
252
|
+
if (component != nil)
|
253
|
+
if (component.version != "")
|
254
|
+
version = component.version
|
255
|
+
end
|
256
|
+
end
|
257
|
+
if (uri.query != nil)
|
258
|
+
uri.query.split("&").each do |element|
|
259
|
+
if (element.class.to_s == "String")
|
260
|
+
elements = element.split("=")
|
261
|
+
if (elements.size > 1)
|
262
|
+
case elements[0]
|
263
|
+
when "version"
|
264
|
+
version = elements[1]
|
265
|
+
when "filetype"
|
266
|
+
filetype = elements[1]
|
267
|
+
end
|
268
|
+
end
|
269
|
+
end
|
270
|
+
end
|
271
|
+
end
|
272
|
+
if (component != nil)
|
273
|
+
name = "/#{component.name}/#{component.binaryname}"
|
274
|
+
else
|
275
|
+
name = "#{uri.path}#{uri.path}#{name}-#{version}.#{filetype}"
|
276
|
+
end
|
277
|
+
path = "/SIMP/assets#{name}"
|
278
|
+
else
|
279
|
+
scheme = uri.scheme
|
280
|
+
host = uri.host
|
281
|
+
path = uri.path
|
282
|
+
end
|
283
|
+
port = uri.port ? uri.port : 443
|
284
|
+
http = Net::HTTP.new(host, port)
|
285
|
+
case scheme
|
286
|
+
when "https"
|
287
|
+
http.use_ssl = true
|
288
|
+
case uri.scheme
|
289
|
+
when "simp-enterprise"
|
290
|
+
filename, data = self.get_license_data(options["license"])
|
291
|
+
unless (filename == nil)
|
292
|
+
http.ca_file = filename
|
293
|
+
end
|
294
|
+
unless (data == nil)
|
295
|
+
http.cert = OpenSSL::X509::Certificate.new(data)
|
296
|
+
http.key = OpenSSL::PKey::RSA.new(data)
|
297
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
298
|
+
end
|
299
|
+
|
300
|
+
debug2("using the following certificate (#{filename}) for client certificate auth: #{http.cert.subject}")
|
301
|
+
end
|
302
|
+
end
|
303
|
+
info("Fetching from #{scheme}://#{host}:#{port}#{path}")
|
304
|
+
req = Net::HTTP::Get.new(path)
|
305
|
+
response = http.request(req)
|
306
|
+
case response.code
|
307
|
+
when '200'
|
308
|
+
if (extract == true)
|
309
|
+
File.open("#{destination}.tgz", 'w') do |f|
|
310
|
+
f.write response.body
|
311
|
+
end
|
312
|
+
FileUtils.mkdir_p(destination)
|
313
|
+
run("tar -xvpf #{destination}.tgz -C #{destination}")
|
314
|
+
else
|
315
|
+
File.open(destination, 'w') do |f|
|
316
|
+
f.write response.body
|
317
|
+
end
|
318
|
+
end
|
319
|
+
when '302'
|
320
|
+
fetch_simp_enterprise(response['location'], destination, component, location)
|
321
|
+
when '301'
|
322
|
+
fetch_simp_enterprise(response['location'], destination, component, location)
|
323
|
+
else
|
324
|
+
$errorcode = response.code.to_i
|
325
|
+
raise "HTTP Error Code: #{response.code}"
|
326
|
+
end
|
327
|
+
end
|
328
|
+
|
329
|
+
def self.run(command)
|
330
|
+
exitcode = nil
|
331
|
+
Open3.popen3(command) do |stdin, stdout, stderr, thread|
|
332
|
+
pid = thread.pid
|
333
|
+
Simp::Metadata.debug2(stdout.read.chomp)
|
334
|
+
Simp::Metadata.debug1(stderr.read.chomp)
|
335
|
+
exitcode = thread.value
|
336
|
+
end
|
337
|
+
exitcode
|
338
|
+
end
|
339
|
+
|
340
|
+
def self.level?(level)
|
341
|
+
setlevel = Simp::Metadata.convert_level($simp_metadata_debug_level)
|
342
|
+
checklevel = Simp::Metadata.convert_level(level)
|
343
|
+
if (checklevel <= setlevel)
|
344
|
+
true
|
345
|
+
else
|
346
|
+
false
|
347
|
+
end
|
348
|
+
end
|
349
|
+
|
350
|
+
def self.convert_level(level)
|
351
|
+
case level
|
352
|
+
when 'disabled'
|
353
|
+
0
|
354
|
+
when 'critical'
|
355
|
+
1
|
356
|
+
when 'error'
|
357
|
+
2
|
358
|
+
when 'warning'
|
359
|
+
3
|
360
|
+
when 'info'
|
361
|
+
4
|
362
|
+
when 'debug1'
|
363
|
+
5
|
364
|
+
when 'debug2'
|
365
|
+
6
|
366
|
+
else
|
367
|
+
3
|
368
|
+
end
|
369
|
+
end
|
370
|
+
|
371
|
+
def self.print_message(prefix, message)
|
372
|
+
message.split("\n").each do |line|
|
373
|
+
output = "#{prefix}: #{line}"
|
374
|
+
unless ($simp_metadata_debug_output_disabled == true)
|
375
|
+
STDERR.puts output
|
376
|
+
end
|
377
|
+
end
|
378
|
+
end
|
379
|
+
|
380
|
+
def self.debug1(message)
|
381
|
+
if Simp::Metadata.level?('debug1')
|
382
|
+
Simp::Metadata.print_message("DEBUG1", message)
|
383
|
+
end
|
384
|
+
end
|
385
|
+
|
386
|
+
def self.debug2(message)
|
387
|
+
if Simp::Metadata.level?('debug2')
|
388
|
+
Simp::Metadata.print_message("DEBUG2", message)
|
389
|
+
end
|
390
|
+
end
|
391
|
+
|
392
|
+
def self.info(message)
|
393
|
+
if Simp::Metadata.level?('info')
|
394
|
+
Simp::Metadata.print_message("INFO", message)
|
395
|
+
end
|
396
|
+
end
|
397
|
+
|
398
|
+
def self.warning(message)
|
399
|
+
if Simp::Metadata.level?('warning')
|
400
|
+
Simp::Metadata.print_message("WARN", message)
|
401
|
+
end
|
402
|
+
end
|
403
|
+
|
404
|
+
def self.error(message)
|
405
|
+
if Simp::Metadata.level?('error')
|
406
|
+
Simp::Metadata.print_message("ERROR", message)
|
407
|
+
end
|
408
|
+
end
|
409
|
+
|
410
|
+
def self.critical(message)
|
411
|
+
if Simp::Metadata.level?('critical')
|
412
|
+
Simp::Metadata.print_message("CRITICAL", message)
|
413
|
+
end
|
414
|
+
end
|
415
|
+
end
|
416
|
+
end
|