simp-metadata 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +0 -0
  3. data/Rakefile +69 -0
  4. data/exe/simp-install +8 -0
  5. data/exe/simp-media +8 -0
  6. data/exe/simp-metadata +8 -0
  7. data/lib/simp/install.rb +0 -0
  8. data/lib/simp/install/command.rb +70 -0
  9. data/lib/simp/media.rb +9 -0
  10. data/lib/simp/media/command.rb +69 -0
  11. data/lib/simp/media/engine.rb +104 -0
  12. data/lib/simp/media/type.rb +14 -0
  13. data/lib/simp/media/type/base.rb +63 -0
  14. data/lib/simp/media/type/control-repo.rb +211 -0
  15. data/lib/simp/media/type/internet.rb +38 -0
  16. data/lib/simp/media/type/iso.rb +9 -0
  17. data/lib/simp/media/type/local.rb +36 -0
  18. data/lib/simp/media/type/tar.rb +71 -0
  19. data/lib/simp/metadata.rb +416 -0
  20. data/lib/simp/metadata/bootstrap_source.rb +137 -0
  21. data/lib/simp/metadata/buildinfo.rb +58 -0
  22. data/lib/simp/metadata/command.rb +92 -0
  23. data/lib/simp/metadata/commands.rb +21 -0
  24. data/lib/simp/metadata/commands/base.rb +65 -0
  25. data/lib/simp/metadata/commands/clone.rb +26 -0
  26. data/lib/simp/metadata/commands/component.rb +109 -0
  27. data/lib/simp/metadata/commands/delete.rb +26 -0
  28. data/lib/simp/metadata/commands/pry.rb +19 -0
  29. data/lib/simp/metadata/commands/release.rb +47 -0
  30. data/lib/simp/metadata/commands/releases.rb +24 -0
  31. data/lib/simp/metadata/commands/save.rb +33 -0
  32. data/lib/simp/metadata/commands/script.rb +38 -0
  33. data/lib/simp/metadata/commands/search.rb +65 -0
  34. data/lib/simp/metadata/commands/set-write-url.rb +19 -0
  35. data/lib/simp/metadata/commands/set-write.rb +19 -0
  36. data/lib/simp/metadata/commands/update.rb +46 -0
  37. data/lib/simp/metadata/component.rb +388 -0
  38. data/lib/simp/metadata/components.rb +70 -0
  39. data/lib/simp/metadata/engine.rb +101 -0
  40. data/lib/simp/metadata/fake_uri.rb +19 -0
  41. data/lib/simp/metadata/git_ssh_wrapper.sh +6 -0
  42. data/lib/simp/metadata/location.rb +198 -0
  43. data/lib/simp/metadata/locations.rb +54 -0
  44. data/lib/simp/metadata/release.rb +119 -0
  45. data/lib/simp/metadata/releases.rb +57 -0
  46. data/lib/simp/metadata/source.rb +204 -0
  47. data/spec/simp/media/command_spec.rb +12 -0
  48. data/spec/simp/media/engine_spec.rb +28 -0
  49. data/spec/simp/media/type/control_repo_spec.rb +23 -0
  50. data/spec/simp/media/type/internet_spec.rb +29 -0
  51. data/spec/simp/media/type/iso_spec.rb +15 -0
  52. data/spec/simp/media/type/local_spec.rb +16 -0
  53. data/spec/simp/media/type/tar_spec.rb +16 -0
  54. data/spec/simp/metadata/buildinfo_spec.rb +64 -0
  55. data/spec/simp/metadata/commands/clone_spec.rb +8 -0
  56. data/spec/simp/metadata/component_spec.rb +90 -0
  57. data/spec/simp/metadata/engine_spec.rb +70 -0
  58. data/spec/simp/metadata/release_spec.rb +104 -0
  59. data/spec/simp/metadata/source_spec.rb +25 -0
  60. data/spec/simp/metadata_spec.rb +175 -0
  61. data/spec/spec_helper.rb +40 -0
  62. metadata +260 -0
@@ -0,0 +1,137 @@
1
+ require 'yaml'
2
+ require 'uri'
3
+
4
+ module Simp
5
+ module Metadata
6
+ class Bootstrap_source
7
+
8
+ attr_accessor :url
9
+ attr_accessor :cachepath
10
+ attr_accessor :components
11
+ attr_accessor :releases
12
+ attr_accessor :basename
13
+ attr_accessor :data
14
+ attr_accessor :components
15
+ attr_accessor :edition
16
+
17
+ def initialize(edition)
18
+ @releases = {}
19
+ @components = {}
20
+ @edition = edition
21
+
22
+ case edition
23
+ when "enterprise"
24
+ @data = {
25
+ "components" => {
26
+ "enterprise-metadata" => {
27
+ "component-type" => "simp-metadata",
28
+ "authoritative" => true,
29
+ "locations" => [
30
+ {
31
+ "url" => "simp-enterprise:///enterprise-metadata?version=master&filetype=tgz",
32
+ "method" => "file",
33
+ "extract" => true,
34
+ "primary" => true,
35
+ }
36
+ ]
37
+ },
38
+ "simp-metadata" => {
39
+ "component-type" => "simp-metadata",
40
+ "authoritative" => true,
41
+ "locations" => [
42
+ {
43
+ "url" => "https://github.com/simp/simp-metadata",
44
+ "method" => "git",
45
+ "primary" => true,
46
+ }
47
+ ],
48
+ },
49
+ }
50
+ }
51
+ when "enterprise-only"
52
+ @data = {
53
+ "components" => {
54
+ "enterprise-metadata" => {
55
+ "component-type" => "simp-metadata",
56
+ "authoritative" => true,
57
+ "locations" => [
58
+ {
59
+ "url" => "simp-enterprise:///enterprise-metadata?version=master&filetype=tgz",
60
+ "method" => "file",
61
+ "extract" => true,
62
+ "primary" => true,
63
+ }
64
+ ]
65
+ }
66
+ }
67
+ }
68
+ else
69
+ @data = {
70
+ "components" => {
71
+ "simp-metadata" => {
72
+ "component-type" => "simp-metadata",
73
+ "authoritative" => true,
74
+ "locations" => [
75
+ {
76
+ "url" => "https://github.com/simp/simp-metadata",
77
+ "method" => "git",
78
+ "primary" => true,
79
+ }
80
+ ],
81
+ }
82
+ }
83
+ }
84
+ end
85
+ @components = @data['components']
86
+ end
87
+
88
+ def release(version)
89
+ case edition
90
+ when "enterprise"
91
+ {
92
+ "enterprise-metadata" => {
93
+ "version" => "master",
94
+ },
95
+ "simp-metadata" => {
96
+ "branch" => "master"
97
+ }
98
+ }
99
+ when "enterprise-only"
100
+ {
101
+ "enterprise-metadata" => {
102
+ "version" => "master",
103
+ }
104
+ }
105
+ else
106
+ {
107
+ "simp-metadata" => {
108
+ "branch" => "master"
109
+ }
110
+ }
111
+ end
112
+ end
113
+ # Stub out 'writing' methods as they don't apply to bootstrap_source
114
+ def create_release(destination, source = 'master')
115
+
116
+ end
117
+ def writable?()
118
+ false
119
+ end
120
+ def dirty?()
121
+ false
122
+ end
123
+ def save()
124
+ true
125
+ end
126
+ def cleanup()
127
+ end
128
+ def to_s()
129
+ self.name
130
+ end
131
+ def name()
132
+ "bootstrap_metadata"
133
+ end
134
+ end
135
+ end
136
+ end
137
+
@@ -0,0 +1,58 @@
1
+ module Simp
2
+ module Metadata
3
+ class Buildinfo
4
+ include Enumerable
5
+ attr_accessor :type
6
+ attr_accessor :component
7
+
8
+ def initialize(component, type)
9
+ @type = type
10
+ @component = component
11
+ end
12
+
13
+ def keys()
14
+ ["type", "build_method"]
15
+ end
16
+
17
+ def [] (index)
18
+ self.send index.to_sym
19
+ end
20
+
21
+ def each(&block)
22
+ self.keys.each do |key|
23
+ yield key, self[key]
24
+ end
25
+ end
26
+
27
+ def fetch_data
28
+ component.fetch_data("buildinfo")
29
+ end
30
+
31
+ def method_defaults
32
+ {
33
+ "rpm" => {
34
+ "build_method" => "simp-core",
35
+ }
36
+ }
37
+ end
38
+
39
+ def build_method()
40
+ buildinfo = self.fetch_data
41
+ if (buildinfo == nil)
42
+ retval = method_defaults[type]["build_method"]
43
+ else
44
+ if (buildinfo.key?(type))
45
+ if (buildinfo[type].key?("build_method"))
46
+ retval = buildinfo[type]["build_method"]
47
+ else
48
+ retval = method_defaults[type]["build_method"]
49
+ end
50
+ else
51
+ retval = method_defaults[type]["build_method"]
52
+ end
53
+ end
54
+ return retval
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,92 @@
1
+ require 'simp/metadata/commands'
2
+ require 'simp/metadata'
3
+
4
+ module Simp
5
+ module Metadata
6
+ class Command
7
+ def run(argv)
8
+ command = argv[0]
9
+ argv.shift
10
+ # XXX ToDo: Make this dynamic, just instantiate a class named the subcommand
11
+ if (command != "")
12
+ if (command == "-h" || command == "help")
13
+ self.help()
14
+ else
15
+ unless (command =~ /^#/)
16
+ begin
17
+ cmd = Module.const_get("Simp::Metadata::Commands::#{command.gsub("-", "_").capitalize}").new()
18
+
19
+ rescue
20
+ Simp::Metadata.critical("Unable to find command: #{command}")
21
+ self.help
22
+ exit 4
23
+ end
24
+ cmd.run(argv)
25
+ end
26
+ end
27
+ else
28
+ self.help()
29
+ end
30
+ end
31
+
32
+ def help()
33
+ puts "Usage: simp-metadata [command] [options]"
34
+ # XXX: ToDo: make this dynamic...
35
+ subcommands = [
36
+ [
37
+ "clone",
38
+ "Clones one simp release into another",
39
+ ],
40
+ [
41
+ "component",
42
+ "create, view, or update a component",
43
+ ],
44
+ [
45
+ "delete",
46
+ "deletes a release",
47
+ ],
48
+ [
49
+ "pry",
50
+ "opens up pry debugger",
51
+ ],
52
+ [
53
+ "release",
54
+ "views components of a release",
55
+ ],
56
+ [
57
+ "releases",
58
+ "lists all releases",
59
+ ],
60
+ [
61
+ "save",
62
+ "Saves metadata changes",
63
+ ],
64
+ [
65
+ "script",
66
+ "Execute a script containing multiple commands",
67
+ ],
68
+ [
69
+ "search",
70
+ "searches for components based on attributes",
71
+ ],
72
+ [
73
+ "set-write",
74
+ "Sets which metadata repo to write to if there are multiple",
75
+ ],
76
+ [
77
+ "set-write-url",
78
+ "view/update/create a component",
79
+ ],
80
+ [
81
+ "update",
82
+ "updates a components attributes",
83
+ ]
84
+ ]
85
+ subcommands.each do |components|
86
+ output_string = "#{(components[0].ljust(38)).rjust(42)}#{components[1]}"
87
+ puts output_string
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,21 @@
1
+ # XXX ToDo: Dynamically load all files
2
+ require 'simp/metadata/commands/base'
3
+ require 'simp/metadata/commands/release'
4
+ require 'simp/metadata/commands/releases'
5
+ require 'simp/metadata/commands/save'
6
+ require 'simp/metadata/commands/script'
7
+ require 'simp/metadata/commands/clone'
8
+ require 'simp/metadata/commands/set-write'
9
+ require 'simp/metadata/commands/delete'
10
+ require 'simp/metadata/commands/set-write-url'
11
+ require 'simp/metadata/commands/update'
12
+ require 'simp/metadata/commands/component'
13
+ require 'simp/metadata/commands/pry'
14
+ require 'simp/metadata/commands/search'
15
+
16
+ module Simp
17
+ module Metadata
18
+ module Commands
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,65 @@
1
+ require_relative '../commands'
2
+ module Simp
3
+ module Metadata
4
+ module Commands
5
+ class Base
6
+ def get_engine(engine, options = {})
7
+ root = false
8
+ if (options["ssh_key"] != nil)
9
+ options["ssh_key"] = File.expand_path(options["ssh_key"])
10
+ end
11
+ if (engine == nil)
12
+ root = true
13
+ metadatarepos = {}
14
+ if (options["writable_urls"] != nil)
15
+ array = options["writable_urls"].split(',')
16
+ elements = array.size / 2;
17
+ (0...elements).each do |offset|
18
+ comp = array[offset * 2]
19
+ url = array[(offset * 2) + 1]
20
+ metadatarepos[comp] = url
21
+ end
22
+ engine = Simp::Metadata::Engine.new(nil, metadatarepos, options["edition"], options)
23
+ else
24
+ engine = Simp::Metadata::Engine.new(nil, nil, options["edition"], options)
25
+ end
26
+ else
27
+ root = false
28
+ end
29
+ return engine, root
30
+ end
31
+ # Defines default arguments for commands
32
+ def defaults(argv, &block)
33
+
34
+ options = {
35
+ "edition" => ENV.fetch('SIMP_METADATA_EDITION', 'community'),
36
+ }
37
+ if (ENV.fetch('SIMP_METADATA_WRITABLE_URLS', nil) != nil)
38
+ options["writable_urls"] = ENV['SIMP_METADATA_WRITABLE_URLS']
39
+ end
40
+ option_parser = OptionParser.new do |opts|
41
+ opts.banner = "Usage: simp-metadata <command> [options]"
42
+ opts.on("-d", "--debug [level]", "debug logging level: critical, error, warning, info, debug1, debug2") do |opt|
43
+ $simp_metadata_debug_level = opt
44
+ end
45
+ opts.on("-v", "--version [release]", "release version") do |opt|
46
+ options["release"] = opt
47
+ end
48
+ opts.on("-i", "--identity [ssh_key_file]", "specify ssh_key to be used") do |opt|
49
+ options["ssh_key"] = opt
50
+ end
51
+ opts.on("-w", "--writable-urls [component,url]", "component,url") do |opt|
52
+ options["writable_urls"] = opt
53
+ end
54
+ opts.on("-e", "--edition [edition]", "simp edition") do |opt|
55
+ options["edition"] = opt
56
+ end
57
+ yield(opts) if block_given?
58
+ end
59
+ option_parser.parse!(argv)
60
+ return options
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,26 @@
1
+ require_relative '../commands'
2
+ module Simp
3
+ module Metadata
4
+ module Commands
5
+ class Clone < Simp::Metadata::Commands::Base
6
+ def run(argv, engine = nil)
7
+
8
+ options = defaults(argv) do |opts|
9
+ opts.banner = "Usage: simp-metadata clone <source_release> <target_release>"
10
+ end
11
+ engine, root = get_engine(engine, options)
12
+
13
+ begin
14
+ engine.releases.create(argv[1], argv[0])
15
+ if (root == true)
16
+ engine.save((["simp-metadata", "clone"] + argv).join(" "))
17
+ end
18
+ rescue RuntimeError => e
19
+ Simp::Metadata.critical(e.message)
20
+ exit 5
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,109 @@
1
+ require_relative '../commands'
2
+ module Simp
3
+ module Metadata
4
+ module Commands
5
+ class Component < Simp::Metadata::Commands::Base
6
+
7
+ def run(argv, engine = nil)
8
+
9
+
10
+ begin
11
+ subcommand = argv[0]
12
+ case subcommand
13
+ when "--help", "-h"
14
+ options = defaults(argv) do |opts|
15
+ opts.banner = "Usage: simp-metadata component [ create | view | update | diff ]"
16
+ end
17
+ when "create"
18
+ options = defaults(argv) do |opts|
19
+ opts.banner = "Usage: simp-metadata component create <component_name> name=<value>"
20
+ end
21
+ engine, root = get_engine(engine, options)
22
+ component = argv[1]
23
+ argv.shift
24
+ data = {"locations" => [{"primary" => true}]}
25
+ argv.each do |argument|
26
+ splitted = argument.split("=")
27
+ name = splitted[0]
28
+ value = splitted[1]
29
+ case name
30
+ when "authoritative"
31
+ data["authoritiative"] = value.to_s == "true"
32
+ when "format"
33
+ data["format"] = value
34
+ when "component-type"
35
+ data["component-type"] = value
36
+ when "primary_url"
37
+ data["locations"].first["url"] = value
38
+ when "primary_url_type"
39
+ data["locations"].first["type"] = value
40
+ end
41
+ end
42
+ engine.components.create(component, data)
43
+ when "update"
44
+ options = defaults(argv) do |opts|
45
+ opts.banner = "Usage: simp-metadata component update <component> <setting> <value>"
46
+ end
47
+ engine, root = get_engine(engine, options)
48
+ component = argv[1]
49
+ setting = argv[2]
50
+ value = argv[3]
51
+ object = engine.components[component]
52
+ unless (object.methods.include?(setting.to_sym))
53
+ Simp::Metadata.critical("#{setting} is not a valid setting")
54
+ exit 7
55
+ end
56
+ begin
57
+ object.send("#{setting}=".to_sym, value)
58
+ rescue NoMethodError => ex
59
+ Simp::Metadata.critical("#{setting} is a read-only setting")
60
+ exit 6
61
+ end
62
+
63
+ when "view"
64
+ options = defaults(argv) do |opts|
65
+ opts.banner = "Usage: simp-metadata component view <component> [attribute]"
66
+ end
67
+ engine, root = get_engine(engine, options)
68
+ component = argv[1]
69
+ attribute = argv[2]
70
+ if (engine.components.key?(component))
71
+ if (options["release"] == nil)
72
+ comp = engine.components[component]
73
+ else
74
+ comp = engine.releases[options["release"]].components[component]
75
+ end
76
+ view = comp.view(attribute)
77
+ puts view.to_yaml
78
+ else
79
+ Simp::Metadata.critical("Unable to find component named #{component}")
80
+ exit 5
81
+ end
82
+
83
+ when "diff"
84
+ options = defaults(argv) do |opts|
85
+ opts.banner = "Usage: simp-metadata component diff <release1> <release2> <component> [attribute]"
86
+ end
87
+ engine, root = get_engine(engine, options)
88
+ release1 = argv[1]
89
+ release2 = argv[2]
90
+ component = argv[3]
91
+ attribute = argv[4]
92
+ component1 = engine.releases[release1].components[component]
93
+ component2 = engine.releases[release2].components[component]
94
+ diff = component1.diff(component2, attribute)
95
+ puts diff.to_yaml
96
+ end
97
+
98
+ if (root == true)
99
+ engine.save((["simp-metadata", "component"] + argv).join(" "))
100
+ end
101
+ rescue RuntimeError => e
102
+ Simp::Metadata.critical(e.message)
103
+ exit 5
104
+ end
105
+ end
106
+ end
107
+ end
108
+ end
109
+ end