Class: Google::Cloud::Gemserver::Authentication
- Inherits:
-
Object
- Object
- Google::Cloud::Gemserver::Authentication
- Defined in:
- lib/google/cloud/gemserver/authentication.rb
Overview
Authentication
Manages the permissions of the currently logged in user with the gcloud sdk.
Instance Attribute Summary collapse
-
#proj ⇒ String
The project id of the Google App Engine project the gemserver was deployed to.
Instance Method Summary collapse
-
#access_token ⇒ String
Generates an access token from a user authenticated by gcloud.
-
#can_modify? ⇒ Boolean
Checks if the currently logged in user can modify the gemserver i.e.
-
#initialize ⇒ Authentication
constructor
Creates the Authentication object and sets the project id field.
Constructor Details
#initialize ⇒ Authentication
Creates the Authentication object and sets the project id field.
41 42 43 |
# File 'lib/google/cloud/gemserver/authentication.rb', line 41 def initialize @proj = Configuration.new[:proj_id] end |
Instance Attribute Details
#proj ⇒ String
The project id of the Google App Engine project the gemserver was deployed to.
37 38 39 |
# File 'lib/google/cloud/gemserver/authentication.rb', line 37 def proj @proj end |
Instance Method Details
#access_token ⇒ String
Generates an access token from a user authenticated by gcloud.
67 68 69 70 71 72 |
# File 'lib/google/cloud/gemserver/authentication.rb', line 67 def access_token return unless can_modify? scope = ["https://www.googleapis.com/auth/cloud-platform"] auth = Google::Auth.get_application_default scope auth.fetch_access_token! end |
#can_modify? ⇒ Boolean
Checks if the currently logged in user can modify the gemserver i.e. create keys.
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/google/cloud/gemserver/authentication.rb', line 50 def can_modify? user = curr_user owners.each do |owner| return true if extract_account(owner) == user end editors.each do |editor| return true if extract_account(editor) == user end puts "You are either not authenticated with gcloud or lack access" \ " to the gemserver." false end |