Module: Conjur::Authn
- Defined in:
- lib/conjur/authn.rb
Class Method Summary collapse
- .ask_for_credentials(options = {}) ⇒ Object
- .authenticate(options = {}) ⇒ Object
- .connect(cls = Conjur::API, options = {}) ⇒ Object
- .delete_credentials ⇒ Object
- .fetch_credentials(options = {}) ⇒ Object
- .get_credentials(options = {}) ⇒ Object
- .host ⇒ Object
- .login(options = {}) ⇒ Object
- .netrc ⇒ Object
- .read_credentials ⇒ Object
- .write_credentials ⇒ Object
Class Method Details
.ask_for_credentials(options = {}) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/conjur/authn.rb', line 72 def ask_for_credentials( = {}) raise "No credentials provided or found" if [:noask] # also use stderr here, because we might be prompting for a password as part # of a command like user:create that we'd want to send to a file. hl = HighLine.new $stdin, $stderr user = [:username] || hl.ask("Enter your username to log into Conjur: ") pass = [:password] || hl.ask("Please enter your password (it will not be echoed): "){ |q| q.echo = false } api_key = if cas_server = [:"cas-server"] Conjur::API.login_cas(user, pass, cas_server) else Conjur::API.login(user, pass) end @credentials = [user, api_key] end |
.authenticate(options = {}) ⇒ Object
32 33 34 |
# File 'lib/conjur/authn.rb', line 32 def authenticate( = {}) Conjur::API.authenticate(*get_credentials()) end |
.connect(cls = Conjur::API, options = {}) ⇒ Object
89 90 91 |
# File 'lib/conjur/authn.rb', line 89 def connect(cls = Conjur::API, = {}) cls.new_from_key(*get_credentials()) end |
.delete_credentials ⇒ Object
36 37 38 39 |
# File 'lib/conjur/authn.rb', line 36 def delete_credentials netrc.delete host netrc.save end |
.fetch_credentials(options = {}) ⇒ Object
61 62 63 64 |
# File 'lib/conjur/authn.rb', line 61 def fetch_credentials( = {}) ask_for_credentials() write_credentials end |
.get_credentials(options = {}) ⇒ Object
53 54 55 |
# File 'lib/conjur/authn.rb', line 53 def get_credentials( = {}) @credentials ||= (read_credentials || fetch_credentials()) end |
.login(options = {}) ⇒ Object
27 28 29 30 |
# File 'lib/conjur/authn.rb', line 27 def login( = {}) delete_credentials get_credentials() end |
.netrc ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/conjur/authn.rb', line 45 def netrc args = [] if path = Conjur::Config[:netrc_path] args.unshift(path) end @netrc ||= Netrc.read(*args) end |
.read_credentials ⇒ Object
57 58 59 |
# File 'lib/conjur/authn.rb', line 57 def read_credentials netrc[host] end |
.write_credentials ⇒ Object
66 67 68 69 70 |
# File 'lib/conjur/authn.rb', line 66 def write_credentials netrc[host] = @credentials netrc.save @credentials end |