Class: Google::Cloud::Gemserver::Authentication

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeAuthentication

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

#projString

The project id of the Google App Engine project the gemserver was deployed to.

Returns:

  • (String)


37
38
39
# File 'lib/google/cloud/gemserver/authentication.rb', line 37

def proj
  @proj
end

Instance Method Details

#access_tokenString

Generates an access token from a user authenticated by gcloud.

Returns:

  • (String)


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.

Returns:

  • (Boolean)


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 (owner) == user
  end
  editors.each do |editor|
    return true if (editor) == user
  end
  puts "You are either not authenticated with gcloud or lack access" \
    " to the gemserver."
  false
end