lita-gsuite 0.5 → 0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +33 -22
- data/lib/lita-gsuite.rb +1 -0
- data/lib/lita/commands/account_summary.rb +45 -0
- data/lib/lita/google_account.rb +56 -0
- data/lib/lita/gsuite.rb +12 -0
- data/lib/lita/gsuite_gateway.rb +9 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 931b1f87a3ceba7c16ab448dc899bea54adb0bd0
|
4
|
+
data.tar.gz: 9c62785f33b8ffff0126d50ee1bd4105b3681a0e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 570024f9f0da581c40aa5712bded8a66accd874ea6a391bdee6f7539e76fdae136affc2ef859615746bb1d20c7a301d5e53be7a54c50eb9fc2862d2c66a84877
|
7
|
+
data.tar.gz: ed5a2ef9965e10b865370e7d4dcb2290a61bd9d31160e65ebdf337655eb686f65660131128c42c5908c6169be59fc447f04f6aff869534aeee0ee276628d1765
|
data/README.md
CHANGED
@@ -8,34 +8,27 @@ into the account, not provide administrative functions.
|
|
8
8
|
This was written for a GSuite account with ~125 active users. It may not scale
|
9
9
|
well to larger accounts, but feedback and optimisations are welcome.
|
10
10
|
|
11
|
-
##
|
11
|
+
## Getting Started
|
12
12
|
|
13
|
-
|
13
|
+
### 1. Installation
|
14
14
|
|
15
|
-
|
15
|
+
Add this gem to your lita installation by including the following line in your Gemfile:
|
16
16
|
|
17
|
-
|
17
|
+
gem "lita-gsuite"
|
18
18
|
|
19
|
-
|
20
|
-
values are sensitive, so using ENV vars is recommended to keep the values out
|
21
|
-
of version control.
|
19
|
+
### 2. Configuration
|
22
20
|
|
23
|
-
|
24
|
-
|
25
|
-
|
21
|
+
The lita bot requires an OAuth client ID and secret before it can initiate
|
22
|
+
the process to generate an OAuth2 token for each user. That requires an OAuth2
|
23
|
+
client ID and secret.
|
26
24
|
|
27
|
-
|
28
|
-
|
25
|
+
Both values must be added to your lita\_config.rb. Both are sensitive, so using
|
26
|
+
ENV vars is recommended to keep the values out of version control.
|
29
27
|
|
30
28
|
config.handlers.gsuite.oauth_client_id = ENV["GOOGLE_CLIENT_ID"]
|
31
29
|
config.handlers.gsuite.oauth_client_secret = ENV["GOOGLE_CLIENT_SECRET"]
|
32
30
|
|
33
|
-
|
34
|
-
|
35
|
-
The lita bot requires an OAuth client ID and secret before it can initiate
|
36
|
-
the process to generate an OAuth2 token for each user.
|
37
|
-
|
38
|
-
These can be created on the [Google Developers
|
31
|
+
You can generate the ID and secret on the [Google Developers
|
39
32
|
Console](https://console.developers.google.com/), and Google has [some
|
40
33
|
documentation](https://developers.google.com/identity/protocols/OAuth2).
|
41
34
|
|
@@ -47,15 +40,33 @@ will be prompted to complete an OAuth authorisation process before they can star
|
|
47
40
|
generates an API token that's specific to them and will be used to make API calls on
|
48
41
|
their behalf.
|
49
42
|
|
50
|
-
|
43
|
+
### 3. Enable Google API
|
51
44
|
|
52
|
-
The GSuite API must be explicitly enabled for your account
|
53
|
-
must be whitelisted before it can access any data.
|
45
|
+
The GSuite API must be explicitly enabled for your account:
|
54
46
|
|
55
47
|
1. Sign in to https://admin.google.com
|
56
48
|
2. Visit the Security tab, click "API reference" and "Enable API Access"
|
57
49
|
|
58
|
-
|
50
|
+
### 4. Authorising and First Commands
|
51
|
+
|
52
|
+
With the installation and configuration complete, restart your lita bot.
|
53
|
+
|
54
|
+
Open your chat interface, and issue the following commands the bot.
|
55
|
+
|
56
|
+
1. Initiate authentication for your user: `lita gsuite auth`
|
57
|
+
2. Provide your unique token to lita-gsuite: `lita gsuite set-token <token-generated-in-previous-step>`
|
58
|
+
3. Fetch an account summary: `lita gsuite account-summary`
|
59
|
+
|
60
|
+
All going well, you should see a summary of your gsuite account printed in the channel.
|
61
|
+
|
62
|
+
## Chat commands Reference
|
63
|
+
|
64
|
+
### Administrators
|
65
|
+
|
66
|
+
Display a summary of the GSuite account - organisation name, contant details,
|
67
|
+
alternative email address, etc.
|
68
|
+
|
69
|
+
lita gsuite account-summary
|
59
70
|
|
60
71
|
### Administrators
|
61
72
|
|
data/lib/lita-gsuite.rb
CHANGED
@@ -0,0 +1,45 @@
|
|
1
|
+
module Lita
|
2
|
+
module Commands
|
3
|
+
|
4
|
+
class AccountSummary
|
5
|
+
|
6
|
+
def name
|
7
|
+
'account-summary'
|
8
|
+
end
|
9
|
+
|
10
|
+
def run(robot, target, gateway, opts = {})
|
11
|
+
msg = build_msg(gateway)
|
12
|
+
robot.send_message(target, msg)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def build_msg(gateway)
|
18
|
+
data = get_account_data(gateway)
|
19
|
+
|
20
|
+
msg = "GSuite Account Summary - incorrect or out-of-date details can be updated at https://admin.google.com\n\n"
|
21
|
+
data.each do |label, value|
|
22
|
+
msg += "#{label}: #{value}\n"
|
23
|
+
end
|
24
|
+
msg
|
25
|
+
end
|
26
|
+
|
27
|
+
def get_account_data(gateway)
|
28
|
+
account = gateway.account_summary
|
29
|
+
{
|
30
|
+
"ID" => account.id,
|
31
|
+
"Alternate Email" => account.alternate_email,
|
32
|
+
"Created At" => account.created_at.iso8601,
|
33
|
+
"Primary Domain" => account.primary_domain,
|
34
|
+
"Language" => account.language,
|
35
|
+
"Phone Number" => account.phone_number,
|
36
|
+
"Address" => account.address,
|
37
|
+
"Contact Name" => account.contact_name,
|
38
|
+
}.reject { |item|
|
39
|
+
item.nil? || item == ""
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Lita
|
2
|
+
# A GSuite account
|
3
|
+
class GoogleAccount
|
4
|
+
attr_reader :id, :alternate_email, :created_at, :language, :phone_number
|
5
|
+
attr_reader :primary_domain
|
6
|
+
attr_reader :address_line1, :address_line2, :address_line3
|
7
|
+
attr_reader :contact_name, :country_code, :organization_name, :postal_code, :region
|
8
|
+
|
9
|
+
def self.from_api(account)
|
10
|
+
GoogleAccount.new(
|
11
|
+
id: account.id,
|
12
|
+
alternate_email: account.alternate_email,
|
13
|
+
created_at: account.customer_creation_time,
|
14
|
+
primary_domain: account.customer_domain,
|
15
|
+
language: account.language,
|
16
|
+
phone_number: account.phone_number,
|
17
|
+
address_line1: account.postal_address.address_line1,
|
18
|
+
address_line2: account.postal_address.address_line2,
|
19
|
+
address_line3: account.postal_address.address_line3,
|
20
|
+
contact_name: account.postal_address.contact_name,
|
21
|
+
country_code: account.postal_address.country_code,
|
22
|
+
postal_code: account.postal_address.postal_code,
|
23
|
+
region: account.postal_address.region
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
def initialize(id:, alternate_email:, primary_domain:, created_at:, language:, phone_number:, address_line1: nil, address_line2: nil, address_line3: nil, contact_name: nil, country_code: nil, organization_name: nil, postal_code: nil, region: nil)
|
28
|
+
@id, @alternate_email, @created_at = id, alternate_email, created_at
|
29
|
+
@primary_domain = primary_domain
|
30
|
+
@language, @phone_number = language, phone_number
|
31
|
+
@address_line1, @address_line2, @address_line3 = address_line1, address_line2, address_line3
|
32
|
+
@contact_name, @country_code, @organization_name = contact_name, country_code, organization_name
|
33
|
+
@postal_code, @region = postal_code, region
|
34
|
+
end
|
35
|
+
|
36
|
+
def ==(other)
|
37
|
+
@id == other.id
|
38
|
+
end
|
39
|
+
|
40
|
+
def address
|
41
|
+
[
|
42
|
+
address_line1,
|
43
|
+
address_line2,
|
44
|
+
address_line3,
|
45
|
+
region,
|
46
|
+
postal_code,
|
47
|
+
country_code
|
48
|
+
].reject(&:nil?).join(", ")
|
49
|
+
end
|
50
|
+
|
51
|
+
def to_s
|
52
|
+
"Account #{@id}"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
data/lib/lita/gsuite.rb
CHANGED
@@ -9,6 +9,7 @@ module Lita
|
|
9
9
|
OOB_OAUTH_URI = 'urn:ietf:wg:oauth:2.0:oob'
|
10
10
|
|
11
11
|
COMMANDS = [
|
12
|
+
Commands::AccountSummary,
|
12
13
|
Commands::ListAdmins,
|
13
14
|
Commands::EmptyGroups,
|
14
15
|
Commands::NoOrgUnit,
|
@@ -36,6 +37,7 @@ module Lita
|
|
36
37
|
|
37
38
|
# Instant queries. Authenticated users can run these commands and the result will be returned
|
38
39
|
# immediately
|
40
|
+
route(/^gsuite account-summary$/, :account_summary, command: true, help: {"gsuite account" => "Summarise key account details"})
|
39
41
|
route(/^gsuite list-admins$/, :list_admins, command: true, help: {"gsuite list-admins" => "List active admins"})
|
40
42
|
route(/^gsuite suspension-candidates$/, :suspension_candidates, command: true, help: {"gsuite suspension-candidates" => "List active users that habven't signed in for a while"})
|
41
43
|
route(/^gsuite deletion-candidates$/, :deletion_candidates, command: true, help: {"gsuite deletion-candidates" => "List suspended users that habven't signed in for a while"})
|
@@ -58,6 +60,16 @@ module Lita
|
|
58
60
|
window_commands_timer
|
59
61
|
end
|
60
62
|
|
63
|
+
def account_summary(response)
|
64
|
+
return unless confirm_user_authenticated(response)
|
65
|
+
|
66
|
+
Commands::AccountSummary.new.run(
|
67
|
+
robot,
|
68
|
+
Source.new(room: response.room),
|
69
|
+
gateway(response.user)
|
70
|
+
)
|
71
|
+
end
|
72
|
+
|
61
73
|
def deletion_candidates(response)
|
62
74
|
return unless confirm_user_authenticated(response)
|
63
75
|
|
data/lib/lita/gsuite_gateway.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'lita/google_account'
|
1
2
|
require 'lita/google_activity'
|
2
3
|
require 'lita/google_group'
|
3
4
|
require 'lita/google_organisation_unit'
|
@@ -26,13 +27,20 @@ module Lita
|
|
26
27
|
"https://www.googleapis.com/auth/admin.directory.user.readonly",
|
27
28
|
"https://www.googleapis.com/auth/admin.directory.orgunit.readonly",
|
28
29
|
"https://www.googleapis.com/auth/admin.reports.audit.readonly",
|
29
|
-
"https://www.googleapis.com/auth/admin.directory.group.readonly"
|
30
|
+
"https://www.googleapis.com/auth/admin.directory.group.readonly",
|
31
|
+
"https://www.googleapis.com/auth/admin.directory.customer.readonly",
|
30
32
|
]
|
31
33
|
|
32
34
|
def initialize(user_authorization: nil)
|
33
35
|
@user_authorization = user_authorization
|
34
36
|
end
|
35
37
|
|
38
|
+
# return an object with some basic data on the entire gsuite account
|
39
|
+
def account_summary
|
40
|
+
data = directory_service.get_customer("my_customer")
|
41
|
+
GoogleAccount.from_api(data)
|
42
|
+
end
|
43
|
+
|
36
44
|
def admin_activities(start_time, end_time)
|
37
45
|
data = reports_service.list_activities("all", "admin", start_time: start_time.iso8601, end_time: end_time.iso8601)
|
38
46
|
activities = data.items || []
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lita-gsuite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.6'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Healy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06-
|
11
|
+
date: 2017-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -121,6 +121,7 @@ files:
|
|
121
121
|
- MIT-LICENSE
|
122
122
|
- README.md
|
123
123
|
- lib/lita-gsuite.rb
|
124
|
+
- lib/lita/commands/account_summary.rb
|
124
125
|
- lib/lita/commands/deletion_candidates.rb
|
125
126
|
- lib/lita/commands/empty_groups.rb
|
126
127
|
- lib/lita/commands/list_activities.rb
|
@@ -129,6 +130,7 @@ files:
|
|
129
130
|
- lib/lita/commands/suspension_candidates.rb
|
130
131
|
- lib/lita/commands/two_factor_off.rb
|
131
132
|
- lib/lita/commands/two_factor_stats.rb
|
133
|
+
- lib/lita/google_account.rb
|
132
134
|
- lib/lita/google_activity.rb
|
133
135
|
- lib/lita/google_group.rb
|
134
136
|
- lib/lita/google_organisation_unit.rb
|