google_directory 0.2.2 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9818097fe34668cd39dc6ef720cf127ba5fbc2538bf89ee72ce9f65f585ed0f7
4
- data.tar.gz: 12a8026b64acb4d5f30416bb4904f89f5463ce1b880663e725e946f4bb20c2f0
3
+ metadata.gz: ad3d45be79a46c765d3e286620049175179c317083042a816acd730751a00ebc
4
+ data.tar.gz: 2032dcf141e7f8c93d23cee5262c1104fbb902de6bcab02aff8f031b03c8091a
5
5
  SHA512:
6
- metadata.gz: 13c4dd4666a71ad46397c6c298f6ee7d3db374b0bac46d83bb6de540f20dae966e1098b3a0b78474bfaa889ece9ca0fc2c99e7417267523d052f3f45a96e9633
7
- data.tar.gz: ebfa0eae70d15e7de9fa9c6ca89148824f8052d7bce27d368dc66852fd9c62450948c4f4cb2df9c656339d82f76e89d5a7bc6ef5e437c22cc52eac7b21af9ae3
6
+ metadata.gz: db8d3e223648271045ae7ede6b39e2ff6b6ac4ffbf0979a88338bbe86c408a2e6cb0366328d9723cd03db536e226e85c2839f8ca0e474208ed732733c9a9e6a5
7
+ data.tar.gz: 39e9c27cd74a021935569401113c71fd3814db24bfd7813977d5460b74fc4bde218b3fb23b3c4666687eec1e7addb781d3903e70cc76be66db16a3526c2d82b0
@@ -1,8 +1,6 @@
1
- require 'google/apis/admin_directory_v1'
2
1
  require 'googleauth'
3
- require 'googleauth/stores/file_token_store'
2
+ require 'google/apis/admin_directory_v1'
4
3
  require 'fileutils'
5
-
6
4
  require "google_directory/version"
7
5
  require "google_directory/user_commands"
8
6
 
@@ -19,17 +17,17 @@ module GoogleDirectory
19
17
  include GoogleDirectory::UserCommands
20
18
 
21
19
  # default settings from google for all users
22
- OOB_URI = ENV['OOB_URI'] || 'urn:ietf:wg:oauth:2.0:oob'
23
- CREDENTIALS_PATH = ENV['CREDENTIALS_PATH'] || File.join( Dir.home, '.credentials', "admin-directory_v1-ruby-accounts.yaml")
20
+ CREDENTIALS_PATH = ENV['CREDENTIALS_JSON_PATH']
21
+ SUB_ACCOUNT = ENV['SUB_ACCOUNT_NAME']
24
22
 
25
23
  # Get info the Google Cloud Admin
26
24
  # https://console.cloud.google.com/apis/ or
27
25
  # build using: https://developers.google.com/api-client-library/ruby/guide/aaa_client_secrets
28
- CLIENT_SECRETS_PATH = ENV['CLIENT_SECRETS_PATH'] || 'client_secret.json'
26
+ # CLIENT_SECRETS_PATH = ENV['CLIENT_SECRETS_PATH'] || 'client_secret.json'
29
27
 
30
28
  # Scope options - https://www.googleapis.com/auth/admin.directory.user
31
29
  # https://developers.google.com/admin-sdk/directory/v1/guides/authorizing
32
- SCOPE = Google::Apis::AdminDirectoryV1::AUTH_ADMIN_DIRECTORY_USER
30
+ # SCOPE = Google::Apis::AdminDirectoryV1::AUTH_ADMIN_DIRECTORY_USER
33
31
  # SCOPE = 'https://www.googleapis.com/auth/admin.directory.user'
34
32
 
35
33
  # Initialize the API
@@ -39,9 +37,7 @@ module GoogleDirectory
39
37
  # @note make connection to google directory services
40
38
  # @param service [Class] the default is: Google::Apis::AdminDirectoryV1::DirectoryService
41
39
  def initialize( service: Google::Apis::AdminDirectoryV1::DirectoryService )
42
- app_name ||= ENV['APPLICATION_NAME'] || 'google_cloud_app_name'
43
40
  @service = service.new
44
- @service.client_options.application_name = app_name
45
41
  @service.authorization = authorize
46
42
  end
47
43
 
@@ -49,8 +45,6 @@ module GoogleDirectory
49
45
  VERSION
50
46
  end
51
47
 
52
- # @note Run a command against Google Directory
53
- #
54
48
  # @param command [Symbol] choose command to perform these include: :user_get, :user_exists? (t/f), :user_create, :user_delete, :user_update & convience commands :user_suspend, :user_reactivate, :user_change_password
55
49
  # @param attributes [Hash] attributes needed to perform command
56
50
  # @return [Hash] formatted as: `{success: {command: :command, attributes: {primary_email: "user@domain"}, response: GoogleAnswer} }`
@@ -60,8 +54,9 @@ module GoogleDirectory
60
54
  response = send( command, attributes: attributes )
61
55
  response[:status] = 'success'
62
56
  rescue Google::Apis::ClientError => error
63
- response = {response: error, command: command,
64
- attributes: attributes, status: 'error'}
57
+ response = {status: 'error', response: error,
58
+ attributes: attributes, command: command,
59
+ }
65
60
  end
66
61
  response
67
62
  end
@@ -77,32 +72,15 @@ module GoogleDirectory
77
72
 
78
73
  private
79
74
  attr_reader :service
80
- ##
81
- # FROM:
82
- # https://www.rubydoc.info/github/google/google-api-ruby-client/Google/Apis/AdminDirectoryV1/DirectoryService
83
- # Ensure valid credentials, either by restoring from the saved credentials
84
- # files or intitiating an OAuth2 authorization. If authorization is required,
85
- # the user's default browser will be launched to approve the request.
86
- # @return [Google::Auth::UserRefreshCredentials] OAuth2 credentials
87
- def authorize
88
- FileUtils.mkdir_p(File.dirname(CREDENTIALS_PATH))
89
75
 
90
- client_id = Google::Auth::ClientId.from_file(CLIENT_SECRETS_PATH)
91
- token_store = Google::Auth::Stores::FileTokenStore.new(file: CREDENTIALS_PATH)
92
- authorizer = Google::Auth::UserAuthorizer.new( client_id, SCOPE, token_store )
93
- user_id = 'default'
94
- credentials = authorizer.get_credentials(user_id)
95
- if credentials.nil?
96
- url = authorizer.get_authorization_url(
97
- base_url: OOB_URI)
98
- puts "Open the following URL in the browser and enter the " +
99
- "resulting code after authorization"
100
- puts url
101
- code = gets
102
- credentials = authorizer.get_and_store_credentials_from_code(
103
- user_id: user_id, code: code, base_url: OOB_URI)
104
- end
105
- credentials
76
+ def authorize
77
+ scope = ['https://www.googleapis.com/auth/admin.directory.user', 'https://www.googleapis.com/auth/admin.directory.user.security']
78
+ authorizer = Google::Auth::ServiceAccountCredentials.make_creds(
79
+ json_key_io: File.open(CREDENTIALS_PATH),
80
+ scope: scope)
81
+ authorizer.update!(sub: SUB_ACCOUNT)
82
+ authorizer.fetch_access_token!
83
+ return authorizer
106
84
  end
107
85
  end
108
86
  end
@@ -13,7 +13,7 @@ module GoogleDirectory
13
13
  # @return [Hash] formatted as {success: {command: :user_get, attributes: {primary_email: "user@domain"}, response: GoogleUserObject } }
14
14
  def user_get( attributes: )
15
15
  response = service.get_user( attributes[:primary_email] )
16
- {command: :user_get, user: attributes[:primary_email], response: response}
16
+ {response: response, attributes: attributes[:primary_email], command: :user_get}
17
17
  end
18
18
 
19
19
  # @note Test if user exists in Google Directory
@@ -23,10 +23,10 @@ module GoogleDirectory
23
23
  def user_exists?( attributes: )
24
24
  begin
25
25
  response = service.get_user( attributes[:primary_email] )
26
- return {command: :user_exists?, user: attributes[:primary_email], response: true}
26
+ return {response: true, attributes: attributes[:primary_email], command: :user_exists?}
27
27
  rescue Google::Apis::ClientError => error
28
28
  if error.message.include? 'notFound'
29
- return {command: :user_exists?, user: attributes[:primary_email], response: false}
29
+ return {response: false, attributes: attributes[:primary_email], command: :user_exists?}
30
30
  else
31
31
  raise error
32
32
  end
@@ -46,7 +46,7 @@ module GoogleDirectory
46
46
  user_object = Google::Apis::AdminDirectoryV1::User.new user_attr
47
47
  # create user in directory services
48
48
  response = service.insert_user( user_object )
49
- {command: :user_create, user: attributes[:primary_email], response: response}
49
+ {response: response, attributes: attributes[:primary_email], command: :user_create}
50
50
  end
51
51
 
52
52
  # @note updates an exising Google Directory User
@@ -56,7 +56,7 @@ module GoogleDirectory
56
56
  def user_update( attributes: )
57
57
  # create a user object for google to update
58
58
  response = update_user( attributes )
59
- {command: :user_update, user: attributes[:primary_email], response: response}
59
+ {response: response, attributes: attributes[:primary_email], command: :user_update}
60
60
  end
61
61
 
62
62
  # @note updates an exising Google Directory User password - convience method instead of using :user_update
@@ -69,7 +69,7 @@ module GoogleDirectory
69
69
  user_attr = defaults.merge( attributes )
70
70
 
71
71
  response = update_user( user_attr )
72
- {command: :user_change_password, user: attributes[:primary_email], response: response}
72
+ {response: response, attributes: attributes[:primary_email], command: :user_change_password}
73
73
  end
74
74
 
75
75
  # @note activates an exising Google Directory User password - convience method instead of using :user_update
@@ -81,7 +81,7 @@ module GoogleDirectory
81
81
  user_attr = defaults.merge( attributes )
82
82
 
83
83
  response = update_user( user_attr )
84
- {command: :user_reactivate, user: attributes[:primary_email], response: response}
84
+ {response: response, attributes: attributes[:primary_email], command: :user_reactivate}
85
85
  end
86
86
 
87
87
  # @note suspends an exising Google Directory User password - convience method instead of using :user_update
@@ -93,7 +93,7 @@ module GoogleDirectory
93
93
  user_attr = defaults.merge( attributes )
94
94
 
95
95
  response = update_user( user_attr )
96
- {command: :user_suspend, user: attributes[:primary_email], response: response}
96
+ {response: response, attributes: attributes[:primary_email], command: :user_suspend}
97
97
  end
98
98
 
99
99
  # @note deletes an exising Google Directory User
@@ -102,7 +102,7 @@ module GoogleDirectory
102
102
  # @return [Hash] formatted as {success: {command: :user_delete, attributes: {primary_email: "user@domain"}, response: "" } }
103
103
  def user_delete( attributes: )
104
104
  response = service.delete_user( attributes[:primary_email] )
105
- {command: :user_delete, user: attributes[:primary_email], response: response}
105
+ {response: response, attributes: attributes[:primary_email], command: :user_delete}
106
106
  end
107
107
 
108
108
  private
@@ -17,7 +17,7 @@ module GoogleDirectory
17
17
  defaults = { max_results: 10, order_by: 'email' }
18
18
  filters = defaults.merge( attributes )
19
19
  response = service.list_users( filters )
20
- {command: :users_list, filters: filters, response: response}
20
+ {response: response, attributes: filters, command: :users_list}
21
21
  end
22
22
 
23
23
  end
@@ -1,5 +1,5 @@
1
1
  module GoogleDirectory
2
2
  module Version
3
- VERSION = "0.2.2"
3
+ VERSION = "0.2.4"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google_directory
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bill Tihen
8
8
  - Lee Weisbecker
9
- autorequire:
9
+ autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2018-06-14 00:00:00.000000000 Z
12
+ date: 2023-09-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: google-api-client
@@ -17,70 +17,70 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: '0.21'
20
+ version: '0.37'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: '0.21'
27
+ version: '0.37'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: bundler
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
32
  - - "~>"
33
33
  - !ruby/object:Gem::Version
34
- version: '1.16'
34
+ version: '2.1'
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - "~>"
40
40
  - !ruby/object:Gem::Version
41
- version: '1.16'
41
+ version: '2.1'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: rake
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
46
  - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: '10.0'
48
+ version: '13.0'
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: '10.0'
55
+ version: '13.0'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: rspec
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
60
  - - "~>"
61
61
  - !ruby/object:Gem::Version
62
- version: '3.0'
62
+ version: '3.9'
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - "~>"
68
68
  - !ruby/object:Gem::Version
69
- version: '3.0'
69
+ version: '3.9'
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: pry
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
74
  - - "~>"
75
75
  - !ruby/object:Gem::Version
76
- version: '0.11'
76
+ version: '0.12'
77
77
  type: :development
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
81
  - - "~>"
82
82
  - !ruby/object:Gem::Version
83
- version: '0.11'
83
+ version: '0.12'
84
84
  description: Authenticate, list, make, check, suspend and activate google users.
85
85
  email:
86
86
  - btihen@gmail.com
@@ -98,7 +98,7 @@ homepage: https://github.com/LAS-IT/google_directory
98
98
  licenses:
99
99
  - MIT
100
100
  metadata: {}
101
- post_install_message:
101
+ post_install_message:
102
102
  rdoc_options: []
103
103
  require_paths:
104
104
  - lib
@@ -113,9 +113,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
113
  - !ruby/object:Gem::Version
114
114
  version: '0'
115
115
  requirements: []
116
- rubyforge_project:
117
- rubygems_version: 2.7.6
118
- signing_key:
116
+ rubygems_version: 3.1.6
117
+ signing_key:
119
118
  specification_version: 4
120
119
  summary: Simple ruby wrapper to manage google accounts - using oauth2.
121
120
  test_files: []