Class: Checklister::Configuration
- Inherits:
-
Object
- Object
- Checklister::Configuration
- Defined in:
- lib/checklister/configuration.rb
Overview
This class maintains all system-wide configuration for checklister. It properly applies the correct source of configuration values based on the different contexts and also makes sure that compulsory data are not missing.
Some values are dependent on a context, for example: host
can have different values
based on what service the user wants to connect to.
Other values are shared by all those contexts, for example log_file
is defined once and
for all and the service selected by our user does not matter.
checklister can work with several publishing destinations, for example:
- gitlab.com (Official Hosted Service)
- privately hosted gitlab server
- github.com
Setting/Selecting the configuration values
When using the checklister binary, you can set one of the many publishing destinations you have access to, via two possible ways:
1. CLI Configuration Values
No configuration file required, you can pass your service credentials directly inline as options.
For example, you might do:
$ checklister --endpoint=https://api.github.com --private_token==supersecret create ...
NOTE: Every time you pass credentials via command line options, they will override any configuration file you have previously set .
2. Configuration File
You can use the command line to add publishing destinations credentials and answer the questions:
$ checklister setup
By default, that configuration file will be saved at /path/to/home/.checklister.json
.
But you can easily use another one by using that option before any checklister commands:
$ checklister --config=/another/path/to/my_checklister.json setup
As soon as you have set up one or many publishing destinations, every time you will be using a checklister command you will be prompted to select which service to use, for example:
$ checklister create ...
Select which service to use:
[1] https://github.com/benichu
[2] https://github.com/mdeloupy
[3] https://gitlab.intello.com
DEVELOPMENT: Using the configuration values
Any time you need to access the credentials, you just need to confidently query the value without worrying about the context selected by the user.
For example:
- The user selected the
https://github.com/benichu
service, queryingChecklister.config.username
will return the appropriate valuegithub_user
- But, if the user selects next the
https://gitlab.intello.com
service, queryingChecklister.config.username
will return the appropriate valuegitlab_user
Constant Summary collapse
- ATTRIBUTES =
List of all the configuration attributes stored for use within the gem
[:endpoint, :private_token, :label, :kind, :client_certificate_path, :client_certificate_password, :endpoint_certificate_path]
Instance Attribute Summary collapse
-
#client_certificate_password ⇒ Object
Returns the value of attribute client_certificate_password.
-
#client_certificate_path ⇒ Object
Returns the value of attribute client_certificate_path.
-
#endpoint ⇒ Object
Returns the value of attribute endpoint.
-
#endpoint_certificate_path ⇒ Object
Returns the value of attribute endpoint_certificate_path.
-
#kind ⇒ Object
Returns the value of attribute kind.
-
#label ⇒ String
The label value, if not specifically set, we infer it from the given endpoint url (we use the host).
-
#private_token ⇒ Object
Returns the value of attribute private_token.
Instance Method Summary collapse
-
#apply(attributes = {}) ⇒ Object
Apply a configuration hash to a configuration instance.
-
#to_hash ⇒ Hash
The configuration instance formatted as a stringified hash.
-
#to_stdout ⇒ Object
Write a configuration summary to STDOUT, useful for output in the CLI.
Instance Attribute Details
#client_certificate_password ⇒ Object
Returns the value of attribute client_certificate_password.
76 77 78 |
# File 'lib/checklister/configuration.rb', line 76 def client_certificate_password @client_certificate_password end |
#client_certificate_path ⇒ Object
Returns the value of attribute client_certificate_path.
76 77 78 |
# File 'lib/checklister/configuration.rb', line 76 def client_certificate_path @client_certificate_path end |
#endpoint ⇒ Object
Returns the value of attribute endpoint.
76 77 78 |
# File 'lib/checklister/configuration.rb', line 76 def endpoint @endpoint end |
#endpoint_certificate_path ⇒ Object
Returns the value of attribute endpoint_certificate_path.
76 77 78 |
# File 'lib/checklister/configuration.rb', line 76 def endpoint_certificate_path @endpoint_certificate_path end |
#kind ⇒ Object
Returns the value of attribute kind.
76 77 78 |
# File 'lib/checklister/configuration.rb', line 76 def kind @kind end |
#label ⇒ String
The label value, if not specifically set, we infer it from the given endpoint url (we use the host)
102 103 104 105 106 107 108 |
# File 'lib/checklister/configuration.rb', line 102 def label if instance_variable_get "@label" @label elsif instance_variable_get "@endpoint" URI.parse(@endpoint).host end end |
#private_token ⇒ Object
Returns the value of attribute private_token.
76 77 78 |
# File 'lib/checklister/configuration.rb', line 76 def private_token @private_token end |
Instance Method Details
#apply(attributes = {}) ⇒ Object
Apply a configuration hash to a configuration instance
89 90 91 92 93 94 95 |
# File 'lib/checklister/configuration.rb', line 89 def apply(attributes = {}) prepared_attributes = prepare_attributes attributes prepared_attributes.each_pair do |attribute, value| send("#{attribute}=", value) end self end |
#to_hash ⇒ Hash
The configuration instance formatted as a stringified hash
118 119 120 121 122 123 124 |
# File 'lib/checklister/configuration.rb', line 118 def to_hash config_hash = ATTRIBUTES.inject({}) do |hash, attr| hash["#{attr}"] = instance_variable_get("@#{attr}") hash end Checklister::Sanitizer.symbolize config_hash end |
#to_stdout ⇒ Object
Write a configuration summary to STDOUT, useful for output in the CLI
128 129 130 131 132 133 |
# File 'lib/checklister/configuration.rb', line 128 def to_stdout to_hash.each_pair do |attribute, value| puts "%-20s %-50s" % ["#{attribute}:", value] end nil end |