Class: RightHook::Authenticator
- Inherits:
-
Object
- Object
- RightHook::Authenticator
- Defined in:
- lib/right_hook/authenticator.rb
Overview
The authenticator provides an interface to retrieving or creating GitHub authorizations.
Class Method Summary collapse
-
.build(username, password) ⇒ Object
Build a client with a username and an explicit password.
-
.interactive_build(username) ⇒ Object
Prompt the user for their password (without displaying the entered keys).
Instance Method Summary collapse
-
#create_authorization(note) ⇒ Object
Create a new GitHub authorization with the given note.
-
#find_or_create_authorization_by_note(note) ⇒ Object
If there is already an authorization by this note, use it; otherwise create it.
-
#initialize(_client) ⇒ Authenticator
constructor
:nodoc:.
-
#list_authorizations ⇒ Object
Returns an array of all of the authorizations for the authenticated account.
Constructor Details
#initialize(_client) ⇒ Authenticator
:nodoc:
22 23 24 |
# File 'lib/right_hook/authenticator.rb', line 22 def initialize(_client) @_client = _client end |
Class Method Details
.build(username, password) ⇒ Object
Build a client with a username and an explicit password.
8 9 10 |
# File 'lib/right_hook/authenticator.rb', line 8 def build(username, password) new(Octokit::Client.new(login: username, password: password)) end |
.interactive_build(username) ⇒ Object
Prompt the user for their password (without displaying the entered keys). This approach is offered for convenience to make it easier to not store passwords on disk.
14 15 16 17 18 |
# File 'lib/right_hook/authenticator.rb', line 14 def interactive_build(username) require 'io/console' puts "What is the password for #{username}? (Your typing will be hidden.)" new(Octokit::Client.new(login: username, password: $stdin.noecho(&:gets).chomp)) end |
Instance Method Details
#create_authorization(note) ⇒ Object
Create a new GitHub authorization with the given note. If one already exists with that note, it will not create a duplicate.
28 29 30 |
# File 'lib/right_hook/authenticator.rb', line 28 def (note) _client.(scopes: %w(repo), note: note).token end |
#find_or_create_authorization_by_note(note) ⇒ Object
If there is already an authorization by this note, use it; otherwise create it
38 39 40 41 42 43 44 45 |
# File 'lib/right_hook/authenticator.rb', line 38 def (note) found_auth = .find {|auth| auth.note == note} if found_auth found_auth.token else (note) end end |
#list_authorizations ⇒ Object
Returns an array of all of the authorizations for the authenticated account.
33 34 35 |
# File 'lib/right_hook/authenticator.rb', line 33 def _client. end |