Class: Ciborg::Config
- Inherits:
-
Hashie::Dash
- Object
- Hashie::Dash
- Ciborg::Config
- Defined in:
- lib/ciborg/config.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_build(name, repository, branch, command) ⇒ Object
- #basic_auth_password ⇒ Object
- #basic_auth_user ⇒ Object
- #builds ⇒ Object
- #cc_menu_url ⇒ Object
- #display ⇒ Object
- #errors ⇒ Object
- #github_ssh_key ⇒ Object
- #github_ssh_key_path ⇒ Object
- #github_ssh_pubkey ⇒ Object
- #github_ssh_pubkey_path ⇒ Object
-
#initialize(attributes = {}) ⇒ Config
constructor
A new instance of Config.
- #jenkins_url ⇒ Object
- #master_url ⇒ Object
- #node_attributes=(attributes) ⇒ Object
- #reload ⇒ Object
- #rss_url(job_name) ⇒ Object
- #save ⇒ Object
- #server_ssh_key ⇒ Object
- #server_ssh_key_path ⇒ Object
- #server_ssh_pubkey ⇒ Object
- #server_ssh_pubkey_path ⇒ Object
- #soloistrc ⇒ Object
- #to_hash ⇒ Object
- #update(options = {}) ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(attributes = {}) ⇒ Config
Returns a new instance of Config.
22 23 24 25 |
# File 'lib/ciborg/config.rb', line 22 def initialize(attributes = {}) super self["node_attributes"] = Hashie::Mash.new(node_attributes) end |
Class Method Details
.from_file(yaml_file) ⇒ Object
165 166 167 168 169 170 |
# File 'lib/ciborg/config.rb', line 165 def self.from_file(yaml_file) config = {:path => yaml_file} config.merge!(read_config(yaml_file)) if File.exists?(yaml_file) config.delete('keypair_name') self.new(config) end |
.read_config(yaml_file) ⇒ Object
172 173 174 |
# File 'lib/ciborg/config.rb', line 172 def self.read_config(yaml_file) File.open(yaml_file, "r") { |file| YAML.load(file.read) } end |
Instance Method Details
#add_build(name, repository, branch, command) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ciborg/config.rb', line 27 def add_build(name, repository, branch, command) build = { "name" => name, "repository" => repository, "branch" => branch, "command" => command, "junit_publisher" => true } self.node_attributes = self.node_attributes.tap do |config| config.jenkins.builds << build unless config.jenkins.builds.include?(build) end end |
#basic_auth_password ⇒ Object
180 181 182 |
# File 'lib/ciborg/config.rb', line 180 def basic_auth_password node_attributes[:nginx][:basic_auth_password] end |
#basic_auth_user ⇒ Object
176 177 178 |
# File 'lib/ciborg/config.rb', line 176 def basic_auth_user node_attributes[:nginx][:basic_auth_user] end |
#builds ⇒ Object
184 185 186 187 188 189 |
# File 'lib/ciborg/config.rb', line 184 def builds node_attributes[:jenkins][:builds]. map { |build| build[:name] } . map { |build| " %-17s %s" % [build, rss_url(build)] } . join("\n") end |
#cc_menu_url ⇒ Object
80 81 82 |
# File 'lib/ciborg/config.rb', line 80 def "#{jenkins_url}/cc.xml" if master end |
#display ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/ciborg/config.rb', line 146 def display <<OOTPÜT.gsub(/(\S)\s+$/, '\1').gsub(/^\./, '') -- ciborg configuration -- Instance ID: #{instance_id} IP Address: #{master} Instance size: #{instance_size} . Builds: #{builds} . Web URL: #{master_url} User name: #{basic_auth_user} User password: #{basic_auth_password} . CC Menu URL: #{} . OOTPÜT end |
#errors ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/ciborg/config.rb', line 96 def errors = [] if node_attributes.has_key?("jenkins") unless node_attributes.jenkins.has_key?("builds") << "[:node_attributes][:jenkins][:builds]" end else << "[:node_attributes][:jenkins]" end .map{ |path| "your config file does not have a #{path} key" } end |
#github_ssh_key ⇒ Object
48 49 50 |
# File 'lib/ciborg/config.rb', line 48 def github_ssh_key File.read(github_ssh_key_path) end |
#github_ssh_key_path ⇒ Object
40 41 42 |
# File 'lib/ciborg/config.rb', line 40 def github_ssh_key_path File.(self["github_ssh_key"]) if self["github_ssh_key"] end |
#github_ssh_pubkey ⇒ Object
52 53 54 |
# File 'lib/ciborg/config.rb', line 52 def github_ssh_pubkey File.read(github_ssh_pubkey_path) end |
#github_ssh_pubkey_path ⇒ Object
44 45 46 |
# File 'lib/ciborg/config.rb', line 44 def github_ssh_pubkey_path github_ssh_key_path + ".pub" if self["github_ssh_key"] end |
#jenkins_url ⇒ Object
76 77 78 |
# File 'lib/ciborg/config.rb', line 76 def jenkins_url "https://#{CGI.escape(basic_auth_user)}:#{CGI.escape(basic_auth_password)}@#{master}" if master end |
#master_url ⇒ Object
72 73 74 |
# File 'lib/ciborg/config.rb', line 72 def master_url "https://#{master}" if master end |
#node_attributes=(attributes) ⇒ Object
88 89 90 |
# File 'lib/ciborg/config.rb', line 88 def node_attributes=(attributes) self["node_attributes"] = Hashie::Mash.new(attributes) end |
#reload ⇒ Object
129 130 131 |
# File 'lib/ciborg/config.rb', line 129 def reload self.class.from_file(path) end |
#rss_url(job_name) ⇒ Object
84 85 86 |
# File 'lib/ciborg/config.rb', line 84 def rss_url(job_name) master_url + "/job/#{job_name}/rssAll" if master_url end |
#save ⇒ Object
116 117 118 119 120 |
# File 'lib/ciborg/config.rb', line 116 def save return self unless path File.open(path, "w+") { |file| file.write(YAML.dump(JSON.parse(JSON.dump(to_hash)))) } self end |
#server_ssh_key ⇒ Object
64 65 66 |
# File 'lib/ciborg/config.rb', line 64 def server_ssh_key File.read(server_ssh_key_path) end |
#server_ssh_key_path ⇒ Object
56 57 58 |
# File 'lib/ciborg/config.rb', line 56 def server_ssh_key_path File.(self["server_ssh_key"]) if self["server_ssh_key"] end |
#server_ssh_pubkey ⇒ Object
68 69 70 |
# File 'lib/ciborg/config.rb', line 68 def server_ssh_pubkey File.read(server_ssh_pubkey_path) end |
#server_ssh_pubkey_path ⇒ Object
60 61 62 |
# File 'lib/ciborg/config.rb', line 60 def server_ssh_pubkey_path server_ssh_key_path + ".pub" if self["server_ssh_key"] end |
#soloistrc ⇒ Object
108 109 110 111 112 113 114 |
# File 'lib/ciborg/config.rb', line 108 def soloistrc { "recipes" => recipes, "cookbook_paths" => cookbook_paths, "node_attributes" => node_attributes.to_hash } end |
#to_hash ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/ciborg/config.rb', line 133 def to_hash hash = super hash.delete("path") { "ssh_port" => ssh_port, "master" => master, "server_ssh_key" => server_ssh_key_path, "recipes" => recipes, "cookbook_paths" => cookbook_paths, "node_attributes" => node_attributes }.merge(hash) end |
#update(options = {}) ⇒ Object
122 123 124 125 126 127 |
# File 'lib/ciborg/config.rb', line 122 def update( = {}) .each_pair do |attr, value| self.send("#{attr}=", value) end save end |
#valid? ⇒ Boolean
92 93 94 |
# File 'lib/ciborg/config.rb', line 92 def valid? errors.empty? end |