josef 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.editorconfig +30 -0
- data/.gitignore +16 -0
- data/.rspec +3 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +111 -0
- data/LICENSE.txt +21 -0
- data/README.md +77 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/domains.yml.sample +3 -0
- data/exe/josef +5 -0
- data/josef.gemspec +32 -0
- data/lib/josef.rb +12 -0
- data/lib/josef/cli.rb +34 -0
- data/lib/josef/diff.rb +54 -0
- data/lib/josef/google_workspace/client.rb +37 -0
- data/lib/josef/google_workspace/config.rb +37 -0
- data/lib/josef/google_workspace/group.rb +33 -0
- data/lib/josef/google_workspace/members.rb +27 -0
- data/lib/josef/local.rb +14 -0
- data/lib/josef/remote.rb +55 -0
- data/lib/josef/version.rb +3 -0
- metadata +113 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 659488d85b4d808b98bd81d506672e6e66d5b615df9333107d2cffd445ae71f2
|
4
|
+
data.tar.gz: d6b77ee7df6ac03d6fc2ec9061e90a034704b5d0336170ac195d244408eba788
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 78417ff9f122b2dbbb9191790b576837efd938d2768b45ba58c6d5f47f54599b4215c48088774214ed9d86b53f44fa46d1d5dce07fd4ddbf4ffe8fb5b3282ceb
|
7
|
+
data.tar.gz: bb5b08e16a59084db95d132dc2fd21d3868eb0fcedd5e4b027cf3c80cb755aab4c51387400fda365a29b2fc66d67f88a575c51802c541c187c882e57aa4ded69
|
data/.editorconfig
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
root = true
|
2
|
+
|
3
|
+
[*]
|
4
|
+
end_of_line = lf
|
5
|
+
indent_size = 2
|
6
|
+
indent_style = space
|
7
|
+
insert_final_newline = true
|
8
|
+
tab_width = 8
|
9
|
+
trim_trailing_whitespace = true
|
10
|
+
|
11
|
+
[*.bat]
|
12
|
+
end_of_line = crlf
|
13
|
+
|
14
|
+
[*.gemspec]
|
15
|
+
indent_size = 2
|
16
|
+
|
17
|
+
[*.rb]
|
18
|
+
indent_size = 2
|
19
|
+
|
20
|
+
[*.yml]
|
21
|
+
indent_size = 2
|
22
|
+
|
23
|
+
[{*[Mm]akefile*,*.mak,*.mk,depend}]
|
24
|
+
indent_style = tab
|
25
|
+
|
26
|
+
[enc/*]
|
27
|
+
indent_size = 2
|
28
|
+
|
29
|
+
[reg*.[ch]]
|
30
|
+
indent_size = 2
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
josef (0.1.0)
|
5
|
+
activesupport
|
6
|
+
google-api-client
|
7
|
+
thor
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
activesupport (6.1.3)
|
13
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
14
|
+
i18n (>= 1.6, < 2)
|
15
|
+
minitest (>= 5.1)
|
16
|
+
tzinfo (~> 2.0)
|
17
|
+
zeitwerk (~> 2.3)
|
18
|
+
addressable (2.7.0)
|
19
|
+
public_suffix (>= 2.0.2, < 5.0)
|
20
|
+
concurrent-ruby (1.1.8)
|
21
|
+
declarative (0.0.20)
|
22
|
+
declarative-option (0.1.0)
|
23
|
+
diff-lcs (1.4.4)
|
24
|
+
faraday (1.3.0)
|
25
|
+
faraday-net_http (~> 1.0)
|
26
|
+
multipart-post (>= 1.2, < 3)
|
27
|
+
ruby2_keywords
|
28
|
+
faraday-net_http (1.0.1)
|
29
|
+
gems (1.2.0)
|
30
|
+
google-api-client (0.53.0)
|
31
|
+
google-apis-core (~> 0.1)
|
32
|
+
google-apis-generator (~> 0.1)
|
33
|
+
google-apis-core (0.3.0)
|
34
|
+
addressable (~> 2.5, >= 2.5.1)
|
35
|
+
googleauth (~> 0.14)
|
36
|
+
httpclient (>= 2.8.1, < 3.0)
|
37
|
+
mini_mime (~> 1.0)
|
38
|
+
representable (~> 3.0)
|
39
|
+
retriable (>= 2.0, < 4.0)
|
40
|
+
rexml
|
41
|
+
signet (~> 0.14)
|
42
|
+
webrick
|
43
|
+
google-apis-discovery_v1 (0.2.0)
|
44
|
+
google-apis-core (~> 0.1)
|
45
|
+
google-apis-generator (0.2.0)
|
46
|
+
activesupport (>= 5.0)
|
47
|
+
gems (~> 1.2)
|
48
|
+
google-apis-core (~> 0.1)
|
49
|
+
google-apis-discovery_v1 (~> 0.0)
|
50
|
+
thor (>= 0.20, < 2.a)
|
51
|
+
googleauth (0.16.0)
|
52
|
+
faraday (>= 0.17.3, < 2.0)
|
53
|
+
jwt (>= 1.4, < 3.0)
|
54
|
+
memoist (~> 0.16)
|
55
|
+
multi_json (~> 1.11)
|
56
|
+
os (>= 0.9, < 2.0)
|
57
|
+
signet (~> 0.14)
|
58
|
+
httpclient (2.8.3)
|
59
|
+
i18n (1.8.9)
|
60
|
+
concurrent-ruby (~> 1.0)
|
61
|
+
jwt (2.2.2)
|
62
|
+
memoist (0.16.2)
|
63
|
+
mini_mime (1.0.2)
|
64
|
+
minitest (5.14.4)
|
65
|
+
multi_json (1.15.0)
|
66
|
+
multipart-post (2.1.1)
|
67
|
+
os (1.1.1)
|
68
|
+
public_suffix (4.0.6)
|
69
|
+
rake (12.3.3)
|
70
|
+
representable (3.0.4)
|
71
|
+
declarative (< 0.1.0)
|
72
|
+
declarative-option (< 0.2.0)
|
73
|
+
uber (< 0.2.0)
|
74
|
+
retriable (3.1.2)
|
75
|
+
rexml (3.2.4)
|
76
|
+
rspec (3.10.0)
|
77
|
+
rspec-core (~> 3.10.0)
|
78
|
+
rspec-expectations (~> 3.10.0)
|
79
|
+
rspec-mocks (~> 3.10.0)
|
80
|
+
rspec-core (3.10.1)
|
81
|
+
rspec-support (~> 3.10.0)
|
82
|
+
rspec-expectations (3.10.1)
|
83
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
84
|
+
rspec-support (~> 3.10.0)
|
85
|
+
rspec-mocks (3.10.2)
|
86
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
87
|
+
rspec-support (~> 3.10.0)
|
88
|
+
rspec-support (3.10.2)
|
89
|
+
ruby2_keywords (0.0.4)
|
90
|
+
signet (0.15.0)
|
91
|
+
addressable (~> 2.3)
|
92
|
+
faraday (>= 0.17.3, < 2.0)
|
93
|
+
jwt (>= 1.5, < 3.0)
|
94
|
+
multi_json (~> 1.10)
|
95
|
+
thor (1.1.0)
|
96
|
+
tzinfo (2.0.4)
|
97
|
+
concurrent-ruby (~> 1.0)
|
98
|
+
uber (0.1.0)
|
99
|
+
webrick (1.7.0)
|
100
|
+
zeitwerk (2.4.2)
|
101
|
+
|
102
|
+
PLATFORMS
|
103
|
+
ruby
|
104
|
+
|
105
|
+
DEPENDENCIES
|
106
|
+
josef!
|
107
|
+
rake (~> 12.0)
|
108
|
+
rspec (~> 3.0)
|
109
|
+
|
110
|
+
BUNDLED WITH
|
111
|
+
2.2.3
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 jolantern
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
# Josef
|
2
|
+
|
3
|
+
## What's This?
|
4
|
+
|
5
|
+
Josef is manage Google Group on Google Workspace cli tool. It can dump Google Groups, specific domain's in `domains.yml`. And, apply and dry run with dumped yaml.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'josef'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install josef
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
### Environment Variables
|
26
|
+
|
27
|
+
You can configure setting for domains file and actor with environment valiables.
|
28
|
+
|
29
|
+
`GOOGLE_WORKSPACE_ACTOR` : Josef use Service Account Key, and Admin SDK. So, You must set Googlge Workspace Administrator's primary mail address.
|
30
|
+
|
31
|
+
`DOMAINS_FILE_PATH` : Google Group API is include domain in List Groups request. Josef is not manage Domains. You can configure josef manage target domains in yaml file. Please see `domains.yaml.sample`
|
32
|
+
|
33
|
+
### dump groups and members yaml file
|
34
|
+
|
35
|
+
```sh
|
36
|
+
josef dump
|
37
|
+
```
|
38
|
+
|
39
|
+
### dry run(show diff)
|
40
|
+
|
41
|
+
```sh
|
42
|
+
josef diff ./local_group_file.yml
|
43
|
+
```
|
44
|
+
|
45
|
+
### apply
|
46
|
+
|
47
|
+
```
|
48
|
+
josef apply ./local_group_file.yml
|
49
|
+
```
|
50
|
+
|
51
|
+
## Development
|
52
|
+
|
53
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
54
|
+
|
55
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
56
|
+
|
57
|
+
## Contributing
|
58
|
+
|
59
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/josef.
|
60
|
+
|
61
|
+
## Future
|
62
|
+
|
63
|
+
### Spec
|
64
|
+
|
65
|
+
Josef not have test.
|
66
|
+
|
67
|
+
### Oauth Token?
|
68
|
+
|
69
|
+
This tool manages Google Groups based on yaml. Therefore, I think that the administrator of Google WorkSpace may run it in the local environment. If the purpose is achieved with the service account and you want to use oauth authentication, we will handle it.
|
70
|
+
|
71
|
+
### Domain Management?
|
72
|
+
|
73
|
+
I'm not thinking about domain management for now. It doesn't make sense to be able to add it (because it also requires changing the DNS server settings), and I think it's a little too big to be able to delete it.
|
74
|
+
|
75
|
+
## License
|
76
|
+
|
77
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "josef"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/domains.yml.sample
ADDED
data/exe/josef
ADDED
data/josef.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require_relative 'lib/josef/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "josef"
|
5
|
+
spec.version = Josef::VERSION
|
6
|
+
spec.authors = ["jolantern"]
|
7
|
+
spec.email = ["j.o.lantern0422@gmail.com"]
|
8
|
+
|
9
|
+
spec.summary = "josef is management google workspace mailing list command"
|
10
|
+
spec.description = "manage google workspace mailing list(google group) command"
|
11
|
+
spec.homepage = "https://github.com/j-o-lantern0422/josef"
|
12
|
+
spec.license = "MIT"
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
14
|
+
|
15
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
19
|
+
spec.metadata["changelog_uri"] = spec.homepage
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
end
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
spec.add_dependency "google-api-client"
|
30
|
+
spec.add_dependency "thor"
|
31
|
+
spec.add_dependency "activesupport"
|
32
|
+
end
|
data/lib/josef.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require "josef/version"
|
2
|
+
require "thor"
|
3
|
+
require "google/apis/admin_directory_v1"
|
4
|
+
require "googleauth"
|
5
|
+
require "googleauth/stores/file_token_store"
|
6
|
+
require "fileutils"
|
7
|
+
require "josef/cli"
|
8
|
+
|
9
|
+
|
10
|
+
module Josef
|
11
|
+
class Error < StandardError; end
|
12
|
+
end
|
data/lib/josef/cli.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require "josef/google_workspace/client"
|
2
|
+
require "josef/remote"
|
3
|
+
require "josef/diff"
|
4
|
+
module Josef
|
5
|
+
class Cli < Thor
|
6
|
+
include Josef::GoogleWorkspace::Client
|
7
|
+
include Josef::Remote
|
8
|
+
include Josef::Diff
|
9
|
+
class_option :dry_run, :type => :boolean, :default => false
|
10
|
+
|
11
|
+
desc "dump", "dump google workspace group"
|
12
|
+
def dump
|
13
|
+
remote_dump
|
14
|
+
end
|
15
|
+
|
16
|
+
desc "diff [Path]", "print diff defferent local yaml and remote"
|
17
|
+
method_options path: :string
|
18
|
+
def diff(path)
|
19
|
+
local(path)
|
20
|
+
remote_diff(remote, local, "dry run")
|
21
|
+
end
|
22
|
+
|
23
|
+
desc "apply [Path]", "apply local yaml to Google Workspace"
|
24
|
+
def apply(path)
|
25
|
+
local(path)
|
26
|
+
remote_apply(local)
|
27
|
+
end
|
28
|
+
|
29
|
+
desc "console", "console"
|
30
|
+
def console
|
31
|
+
binding.irb
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/josef/diff.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require "josef/remote"
|
2
|
+
require "josef/local"
|
3
|
+
module Josef
|
4
|
+
module Diff
|
5
|
+
include Josef::Remote
|
6
|
+
include Josef::Local
|
7
|
+
def changed?(local_group)
|
8
|
+
remote_group = remote.find{|g| g[:group_mail_address] == local_group[:group_mail_address]}
|
9
|
+
return false if local_group[:members].nil? || remote_group[:members].nil?
|
10
|
+
return false if local_group[:members].sort == remote_group[:members].sort
|
11
|
+
|
12
|
+
true
|
13
|
+
end
|
14
|
+
|
15
|
+
def be_create?(local_group)
|
16
|
+
remote.find{|g| g[:group_mail_address] == local_group[:group_mail_address]}.nil?
|
17
|
+
end
|
18
|
+
|
19
|
+
def be_delete?(remote_group)
|
20
|
+
local.find{|g| g[:group_mail_address] == remote_group[:group_mail_address]}.nil?
|
21
|
+
end
|
22
|
+
|
23
|
+
def remote_diff(remote, local, mode = "apply")
|
24
|
+
local.each do | local_group |
|
25
|
+
if be_create?(local_group)
|
26
|
+
puts "#{local_group[:group_mail_address]} will be create:#{mode}"
|
27
|
+
local_group[:members].each do | member |
|
28
|
+
puts "+ #{member}"
|
29
|
+
end
|
30
|
+
elsif changed?(local_group)
|
31
|
+
puts "#{local_group[:group_mail_address]} will be change:#{mode}"
|
32
|
+
remote_members = remote.find{|g| g[:group_mail_address] == local_group[:group_mail_address]}[:members]
|
33
|
+
|
34
|
+
add = local_group[:members] - remote_members
|
35
|
+
del = remote_members - local_group[:members]
|
36
|
+
|
37
|
+
add.each do | add_member |
|
38
|
+
puts "+ #{add_member}"
|
39
|
+
end
|
40
|
+
|
41
|
+
del.each do | del_member |
|
42
|
+
puts "- #{del_member}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
remote.each do | remote_group |
|
48
|
+
if be_delete?(remote_group)
|
49
|
+
puts "#{remote_group[:group_mail_address]} will be delete:#{mode}"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require "josef/google_workspace/config"
|
2
|
+
require "josef/google_workspace/group"
|
3
|
+
|
4
|
+
OOB_URI = "urn:ietf:wg:oauth:2.0:oob".freeze
|
5
|
+
APP_NAME = "Josef".freeze
|
6
|
+
SCOPE = Google::Apis::AdminDirectoryV1::AUTH_ADMIN_DIRECTORY_GROUP
|
7
|
+
|
8
|
+
module Josef
|
9
|
+
module GoogleWorkspace
|
10
|
+
module Client
|
11
|
+
include Josef::GoogleWorkspace::Config
|
12
|
+
include Josef::GoogleWorkspace::Group
|
13
|
+
|
14
|
+
def client
|
15
|
+
@_client ||= client!
|
16
|
+
end
|
17
|
+
|
18
|
+
def client!
|
19
|
+
service = Google::Apis::AdminDirectoryV1::DirectoryService.new
|
20
|
+
service.authorization = authorize!
|
21
|
+
service.authorization.fetch_access_token!
|
22
|
+
|
23
|
+
service
|
24
|
+
end
|
25
|
+
|
26
|
+
def authorize!
|
27
|
+
authorization = Google::Auth::ServiceAccountCredentials.make_creds(
|
28
|
+
json_key_io: File.open(credential_path),
|
29
|
+
scope: SCOPE)
|
30
|
+
|
31
|
+
authorization.sub = actor
|
32
|
+
authorization
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require "yaml"
|
2
|
+
module Josef
|
3
|
+
module GoogleWorkspace
|
4
|
+
module Config
|
5
|
+
def credential_path
|
6
|
+
ENV["GOOGLE_WORKSPACE_CREDENTIAL_PATH"]
|
7
|
+
end
|
8
|
+
|
9
|
+
def token_path(path)
|
10
|
+
@_token_path ||= ENV["GOOGLE_WORKSPACE_TOKEN_PATH"] || path
|
11
|
+
end
|
12
|
+
|
13
|
+
def actor
|
14
|
+
@_actor ||= actor!
|
15
|
+
end
|
16
|
+
|
17
|
+
def actor!
|
18
|
+
if ENV["GOOGLE_WORKSPACE_ACTOR"].nil?
|
19
|
+
print("input actor primary mail address:")
|
20
|
+
return $stdin.gets.chomp!("\n")
|
21
|
+
end
|
22
|
+
|
23
|
+
ENV["GOOGLE_WORKSPACE_ACTOR"]
|
24
|
+
end
|
25
|
+
|
26
|
+
def domains(domains_file_path: nil)
|
27
|
+
path = domains_file_path || ENV["DOMAINS_FILE_PATH"]
|
28
|
+
if path.nil?
|
29
|
+
print "input your domains file path:"
|
30
|
+
path = $stdin.gets.chomp!("\n")
|
31
|
+
end
|
32
|
+
YAML.load_file(path)["domains"]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "josef/google_workspace/config"
|
2
|
+
require "josef/google_workspace/members"
|
3
|
+
module Josef
|
4
|
+
module GoogleWorkspace
|
5
|
+
module Group
|
6
|
+
include Josef::GoogleWorkspace::Config
|
7
|
+
include Josef::GoogleWorkspace::Members
|
8
|
+
def groups
|
9
|
+
@_groups ||= groups!
|
10
|
+
end
|
11
|
+
|
12
|
+
def groups!
|
13
|
+
domains.map do | domain |
|
14
|
+
client.list_groups(domain: domain).groups
|
15
|
+
end.flatten.compact
|
16
|
+
end
|
17
|
+
|
18
|
+
def create_group(group_mail_address)
|
19
|
+
group = ::Google::Apis::AdminDirectoryV1::Group.new(email: group_mail_address)
|
20
|
+
|
21
|
+
client.insert_group(group)
|
22
|
+
end
|
23
|
+
|
24
|
+
def delete_group(group_mail_address)
|
25
|
+
group = groups.find{|g| g.email == group_mail_address}
|
26
|
+
|
27
|
+
client.delete_group(group.id)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Josef
|
2
|
+
module GoogleWorkspace
|
3
|
+
module Members
|
4
|
+
def member_mail_addreses(group)
|
5
|
+
members_by(group)&.map do | member |
|
6
|
+
member.email
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def members_by(group)
|
11
|
+
client.list_members(group.id).members
|
12
|
+
end
|
13
|
+
|
14
|
+
def add_member(group_mail_address, member_mail_address)
|
15
|
+
member = ::Google::Apis::AdminDirectoryV1::Member.new(email: member_mail_address)
|
16
|
+
group = groups.find{|g| g.email == group_mail_address}
|
17
|
+
client.insert_member(group.id, member)
|
18
|
+
end
|
19
|
+
|
20
|
+
def del_member(group_mail_address, member_mail_address)
|
21
|
+
group = groups.find{|g| g.email == group_mail_address}
|
22
|
+
member = members_by(group).find{ |member| member.email == member_mail_address }
|
23
|
+
client.delete_member(group.id, member.id)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/josef/local.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "josef/google_workspace/client"
|
2
|
+
require "active_support"
|
3
|
+
require "active_support/core_ext"
|
4
|
+
module Josef
|
5
|
+
module Local
|
6
|
+
def local(local_file = nil)
|
7
|
+
@_local ||= local!(local_file)
|
8
|
+
end
|
9
|
+
|
10
|
+
def local!(local_file)
|
11
|
+
YAML.load_file(local_file).map{|h| h.deep_symbolize_keys}
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/josef/remote.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require "josef/google_workspace/client"
|
2
|
+
require "josef/google_workspace/group"
|
3
|
+
require "active_support"
|
4
|
+
require "active_support/core_ext"
|
5
|
+
module Josef
|
6
|
+
module Remote
|
7
|
+
include Josef::GoogleWorkspace::Client
|
8
|
+
include Josef::GoogleWorkspace::Group
|
9
|
+
def remote
|
10
|
+
@_remote ||= remote!
|
11
|
+
end
|
12
|
+
|
13
|
+
def remote!
|
14
|
+
groups.map do | group |
|
15
|
+
{ group_mail_address: group.email, members: member_mail_addreses(group) }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def remote_dump
|
20
|
+
YAML.dump(remote.map{|h| h.deep_stringify_keys}, File.open('dump.yml', 'w'))
|
21
|
+
end
|
22
|
+
|
23
|
+
def remote_apply(local)
|
24
|
+
remote_diff(remote, local)
|
25
|
+
local.each do | local_group |
|
26
|
+
if be_create?(local_group)
|
27
|
+
create_group(local_group[:group_mail_address])
|
28
|
+
|
29
|
+
local_group[:members].each do | member |
|
30
|
+
add_member(local_group[:group_mail_address], member)
|
31
|
+
end
|
32
|
+
elsif changed?(local_group)
|
33
|
+
remote_members = remote.find{|g| g[:group_mail_address] == local_group[:group_mail_address]}[:members]
|
34
|
+
|
35
|
+
add = local_group[:members] - remote_members
|
36
|
+
del = remote_members - local_group[:members]
|
37
|
+
|
38
|
+
add.each do | add_member_mail_address |
|
39
|
+
add_member(local_group[:group_mail_address], add_member_mail_address)
|
40
|
+
end
|
41
|
+
|
42
|
+
del.each do | del_member_mail_address |
|
43
|
+
del_member(local_group[:group_mail_address], del_member_mail_address)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
remote.each do | remote_group |
|
49
|
+
if be_delete?(remote_group)
|
50
|
+
delete_group(remote_group[:group_mail_address])
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: josef
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- jolantern
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-03-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: google-api-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: thor
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activesupport
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: manage google workspace mailing list(google group) command
|
56
|
+
email:
|
57
|
+
- j.o.lantern0422@gmail.com
|
58
|
+
executables:
|
59
|
+
- josef
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".editorconfig"
|
64
|
+
- ".gitignore"
|
65
|
+
- ".rspec"
|
66
|
+
- Gemfile
|
67
|
+
- Gemfile.lock
|
68
|
+
- LICENSE.txt
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- bin/console
|
72
|
+
- bin/setup
|
73
|
+
- domains.yml.sample
|
74
|
+
- exe/josef
|
75
|
+
- josef.gemspec
|
76
|
+
- lib/josef.rb
|
77
|
+
- lib/josef/cli.rb
|
78
|
+
- lib/josef/diff.rb
|
79
|
+
- lib/josef/google_workspace/client.rb
|
80
|
+
- lib/josef/google_workspace/config.rb
|
81
|
+
- lib/josef/google_workspace/group.rb
|
82
|
+
- lib/josef/google_workspace/members.rb
|
83
|
+
- lib/josef/local.rb
|
84
|
+
- lib/josef/remote.rb
|
85
|
+
- lib/josef/version.rb
|
86
|
+
homepage: https://github.com/j-o-lantern0422/josef
|
87
|
+
licenses:
|
88
|
+
- MIT
|
89
|
+
metadata:
|
90
|
+
allowed_push_host: https://rubygems.org
|
91
|
+
homepage_uri: https://github.com/j-o-lantern0422/josef
|
92
|
+
source_code_uri: https://github.com/j-o-lantern0422/josef
|
93
|
+
changelog_uri: https://github.com/j-o-lantern0422/josef
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: 2.3.0
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubygems_version: 3.1.2
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: josef is management google workspace mailing list command
|
113
|
+
test_files: []
|