Class: LinuxHub::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/linux-hub/cli.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ CLI

Returns a new instance of CLI.



3
4
5
6
7
8
9
# File 'lib/linux-hub/cli.rb', line 3

def initialize(config)
  @organization = config["organisation"]
  @team = config["team"]
  @groups = config["groups"]

  Github.instance.access_token = config["access_token"]
end

Instance Method Details

#create_usersObject



27
28
29
# File 'lib/linux-hub/cli.rb', line 27

def create_users
  add_users(github_users)
end

#listObject



11
12
13
# File 'lib/linux-hub/cli.rb', line 11

def list
  puts github_users.collect(&:authorized_keys)
end

#sync_usersObject



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/linux-hub/cli.rb', line 15

def sync_users
  linux_users = LinuxUser.users_in_group
  linux_usernames = linux_users.collect(&:username)
  github_usernames = github_users.collect(&:username)
  # Equivalent to github_users - linux_users
  users_to_add = github_users.reject { |u| linux_usernames.include? u.username }
  # Equivalent to linux_users - github_users
  users_to_delete = linux_users.reject { |u| github_usernames.include? u.username }
  add_users(users_to_add)
  delete_users(users_to_delete)
end