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:
21 22 23 |
# File 'lib/right_hook/authenticator.rb', line 21 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 |
# File 'lib/right_hook/authenticator.rb', line 14 def interactive_build(username) require 'io/console' 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.
27 28 29 |
# File 'lib/right_hook/authenticator.rb', line 27 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
37 38 39 40 41 42 43 44 |
# File 'lib/right_hook/authenticator.rb', line 37 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.
32 33 34 |
# File 'lib/right_hook/authenticator.rb', line 32 def _client. end |