Class: Mongo::Jira::Config
- Inherits:
-
Object
- Object
- Mongo::Jira::Config
- Defined in:
- lib/mongo/jira/config.rb
Constant Summary collapse
- CFG_FILE =
"#{ENV['HOME']}/.mongo_jira.json"
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#filename ⇒ Object
Returns the value of attribute filename.
Class Method Summary collapse
-
.check(filename = CFG_FILE) ⇒ true, false
check the config file.
- .decrypt(key, data) ⇒ Object
- .encrypt(key, value) ⇒ Object
- .load(filename = CFG_FILE) ⇒ Object
- .save(config, filename) ⇒ Object
Instance Method Summary collapse
-
#initialize(file) ⇒ Config
constructor
A new instance of Config.
- #password=(pw) ⇒ Object
- #password? ⇒ Boolean
-
#save ⇒ true, false
save the config file.
Constructor Details
#initialize(file) ⇒ Config
Returns a new instance of Config.
55 56 57 58 59 60 61 62 63 |
# File 'lib/mongo/jira/config.rb', line 55 def initialize(file) raise ConfigException , "file not found #{file}" unless File::exists?(file) @filename=file @config = JSON.parse( IO.read(filename) ) config.symbolize_keys!() config[:auth_type] = (config[:auth_type] || :basic).to_sym config[:context_path] = '' config[:password] = Mongo::Jira::Config::decrypt("password", config[:password]) if config[:password] end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
54 55 56 |
# File 'lib/mongo/jira/config.rb', line 54 def config @config end |
#filename ⇒ Object
Returns the value of attribute filename.
54 55 56 |
# File 'lib/mongo/jira/config.rb', line 54 def filename @filename end |
Class Method Details
.check(filename = CFG_FILE) ⇒ true, false
check the config file
34 35 36 |
# File 'lib/mongo/jira/config.rb', line 34 def self.check(filename=CFG_FILE) File::exists?(filename) end |
.decrypt(key, data) ⇒ Object
98 99 100 101 102 103 104 105 |
# File 'lib/mongo/jira/config.rb', line 98 def self.decrypt(key, data) cipher = OpenSSL::Cipher::Cipher.new("des3") cipher.decrypt cipher.key = key * 10 cipher.iv = '12345678' plaintext = cipher.update(Base64.decode64(data)) plaintext << cipher.final end |
.encrypt(key, value) ⇒ Object
88 89 90 91 92 93 94 95 96 |
# File 'lib/mongo/jira/config.rb', line 88 def self.encrypt(key, value) cipher = OpenSSL::Cipher::Cipher.new("des3") cipher.encrypt # Call this before setting key or iv cipher.key = key * 10 cipher.iv = '12345678' text = cipher.update(value) text << cipher.final Base64.encode64(text).chomp end |
.load(filename = CFG_FILE) ⇒ Object
50 51 52 |
# File 'lib/mongo/jira/config.rb', line 50 def self.load(filename=CFG_FILE) Config.new(filename) end |
.save(config, filename) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/mongo/jira/config.rb', line 38 def self.save(config, filename) cpy = config.clone if config[:password] cpy[:password] = Mongo::Jira::Config::encrypt('password',cpy[:password]) else cpy.delete(:password) end cpy[:context_path] ||= '' File.open(filename , 'w') {|f| f.write(JSON.pretty_generate(cpy)) } end |
Instance Method Details
#password=(pw) ⇒ Object
84 85 86 |
# File 'lib/mongo/jira/config.rb', line 84 def password=(pw) config[:password]=pw end |
#password? ⇒ Boolean
80 81 82 |
# File 'lib/mongo/jira/config.rb', line 80 def password? config[:password] end |
#save ⇒ true, false
save the config file
76 77 78 |
# File 'lib/mongo/jira/config.rb', line 76 def save Mongo::Jira::Config::save(config,filename) end |