sem 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/lib/sem/api/base.rb +11 -13
- data/lib/sem/api/env_var.rb +7 -0
- data/lib/sem/api/file.rb +7 -0
- data/lib/sem/api/org.rb +28 -0
- data/lib/sem/api/project.rb +50 -0
- data/lib/sem/api/shared_config.rb +109 -0
- data/lib/sem/api/team.rb +90 -0
- data/lib/sem/api/user.rb +8 -0
- data/lib/sem/api.rb +7 -8
- data/lib/sem/cli/orgs.rb +12 -12
- data/lib/sem/cli/projects.rb +30 -32
- data/lib/sem/cli/shared_configs.rb +71 -67
- data/lib/sem/cli/teams.rb +84 -106
- data/lib/sem/version.rb +1 -1
- data/lib/sem/views/env_vars.rb +2 -2
- data/lib/sem/views/files.rb +2 -2
- data/lib/sem/views/orgs.rb +12 -14
- data/lib/sem/views/projects.rb +28 -29
- data/lib/sem/views/shared_configs.rb +32 -20
- data/lib/sem/views/teams.rb +47 -65
- data/lib/sem/views/users.rb +6 -6
- data/lib/sem.rb +5 -0
- data/sem.gemspec +4 -0
- metadata +59 -36
- data/lib/sem/api/env_vars.rb +0 -22
- data/lib/sem/api/files.rb +0 -21
- data/lib/sem/api/orgs.rb +0 -42
- data/lib/sem/api/projects.rb +0 -42
- data/lib/sem/api/shared_configs.rb +0 -103
- data/lib/sem/api/teams.rb +0 -69
- data/lib/sem/api/traits/associated_with_org.rb +0 -17
- data/lib/sem/api/traits/associated_with_project.rb +0 -29
- data/lib/sem/api/traits/associated_with_shared_config.rb +0 -31
- data/lib/sem/api/traits/associated_with_team.rb +0 -29
- data/lib/sem/api/traits.rb +0 -10
- data/lib/sem/api/users.rb +0 -44
@@ -1,103 +0,0 @@
|
|
1
|
-
module Sem
|
2
|
-
module API
|
3
|
-
class SharedConfigs < Base
|
4
|
-
extend Traits::AssociatedWithTeam
|
5
|
-
extend Traits::AssociatedWithOrg
|
6
|
-
extend Traits::AssociatedWithProject
|
7
|
-
|
8
|
-
class << self
|
9
|
-
def name_to_id(org_name, shared_config_name)
|
10
|
-
info(org_name, shared_config_name)[:id]
|
11
|
-
end
|
12
|
-
|
13
|
-
def list
|
14
|
-
org_names = Orgs.list.map { |org| org[:username] }
|
15
|
-
|
16
|
-
org_names.to_a.pmap { |name| list_for_org(name) }.flatten
|
17
|
-
end
|
18
|
-
|
19
|
-
def info(org_name, shared_config_name)
|
20
|
-
selected_shared_config = list_for_org(org_name).find do |shared_config|
|
21
|
-
shared_config[:name] == shared_config_name
|
22
|
-
end
|
23
|
-
|
24
|
-
if selected_shared_config.nil?
|
25
|
-
raise Sem::Errors::ResourceNotFound.new("Shared Configuration", [org_name, shared_config_name])
|
26
|
-
end
|
27
|
-
|
28
|
-
selected_shared_config
|
29
|
-
end
|
30
|
-
|
31
|
-
def create(org_name, args)
|
32
|
-
shared_config = api.create_for_org(org_name, args)
|
33
|
-
|
34
|
-
if shared_config.nil?
|
35
|
-
raise Sem::Errors::ResourceNotCreated.new("Shared Configuration", [org_name, args[:name]])
|
36
|
-
end
|
37
|
-
|
38
|
-
to_hash(shared_config, org_name)
|
39
|
-
end
|
40
|
-
|
41
|
-
def update(org_name, shared_config_name, args)
|
42
|
-
shared_config = info(org_name, shared_config_name)
|
43
|
-
|
44
|
-
shared_config = api.update(shared_config[:id], args)
|
45
|
-
|
46
|
-
if shared_config.nil?
|
47
|
-
raise Sem::Errors::ResourceNotUpdated.new("Shared Configuration", [org_name, shared_config_name])
|
48
|
-
end
|
49
|
-
|
50
|
-
to_hash(shared_config, org_name)
|
51
|
-
end
|
52
|
-
|
53
|
-
def delete(org_name, shared_config_name)
|
54
|
-
shared_config = info(org_name, shared_config_name)
|
55
|
-
|
56
|
-
api.delete!(shared_config[:id])
|
57
|
-
rescue SemaphoreClient::Exceptions::RequestFailed
|
58
|
-
raise Sem::Errors::ResourceNotDeleted.new("Shared Configuration", [org_name, shared_config_name])
|
59
|
-
end
|
60
|
-
|
61
|
-
def list_env_vars(org_name, shared_config_name)
|
62
|
-
Sem::API::EnvVars.list_for_shared_config(org_name, shared_config_name)
|
63
|
-
end
|
64
|
-
|
65
|
-
def list_files(org_name, shared_config_name)
|
66
|
-
Sem::API::Files.list_for_shared_config(org_name, shared_config_name)
|
67
|
-
end
|
68
|
-
|
69
|
-
def api
|
70
|
-
client.shared_configs
|
71
|
-
end
|
72
|
-
|
73
|
-
def to_hash(shared_config, org)
|
74
|
-
network_actions = [:config_files_count, :env_vars_count]
|
75
|
-
|
76
|
-
config_files, env_vars = network_actions.pmap do |action|
|
77
|
-
send(action, shared_config.id)
|
78
|
-
end
|
79
|
-
|
80
|
-
{
|
81
|
-
:id => shared_config.id,
|
82
|
-
:name => shared_config.name,
|
83
|
-
:org => org,
|
84
|
-
:config_files => config_files,
|
85
|
-
:env_vars => env_vars,
|
86
|
-
:created_at => shared_config.created_at,
|
87
|
-
:updated_at => shared_config.updated_at
|
88
|
-
}
|
89
|
-
end
|
90
|
-
|
91
|
-
private
|
92
|
-
|
93
|
-
def config_files_count(shared_config_id)
|
94
|
-
client.config_files.list_for_shared_config(shared_config_id).to_a.size
|
95
|
-
end
|
96
|
-
|
97
|
-
def env_vars_count(shared_config_id)
|
98
|
-
client.env_vars.list_for_shared_config(shared_config_id).to_a.size
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
data/lib/sem/api/teams.rb
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
module Sem
|
2
|
-
module API
|
3
|
-
class Teams < Base
|
4
|
-
extend Traits::AssociatedWithOrg
|
5
|
-
|
6
|
-
class << self
|
7
|
-
def name_to_id(org_name, team_name)
|
8
|
-
info(org_name, team_name)[:id]
|
9
|
-
end
|
10
|
-
|
11
|
-
def list
|
12
|
-
org_names = Sem::API::Orgs.list.map { |org| org[:username] }
|
13
|
-
|
14
|
-
org_names.to_a.pmap { |name| list_for_org(name) }.flatten
|
15
|
-
end
|
16
|
-
|
17
|
-
def info(org_name, team_name)
|
18
|
-
selected_team = list_for_org(org_name).find { |team| team[:name] == team_name }
|
19
|
-
|
20
|
-
raise Sem::Errors::ResourceNotFound.new("Team", [org_name, team_name]) if selected_team.nil?
|
21
|
-
|
22
|
-
selected_team
|
23
|
-
end
|
24
|
-
|
25
|
-
def create(org_name, args)
|
26
|
-
team = api.create_for_org(org_name, args)
|
27
|
-
|
28
|
-
raise Sem::Errors::ResourceNotCreated.new("Team", [org_name, args[:name]]) if team.nil?
|
29
|
-
|
30
|
-
to_hash(team, org_name)
|
31
|
-
end
|
32
|
-
|
33
|
-
def update(org_name, team_name, args)
|
34
|
-
team = info(org_name, team_name)
|
35
|
-
|
36
|
-
team = api.update(team[:id], args)
|
37
|
-
|
38
|
-
raise Sem::Errors::ResourceNotUpdated.new("Team", [org_name, team_name]) if team.nil?
|
39
|
-
|
40
|
-
to_hash(team, org_name)
|
41
|
-
end
|
42
|
-
|
43
|
-
def delete(org_name, team_name)
|
44
|
-
team = info(org_name, team_name)
|
45
|
-
|
46
|
-
api.delete!(team[:id])
|
47
|
-
rescue SemaphoreClient::Exceptions::RequestFailed
|
48
|
-
raise Sem::Errors::ResourceNotDeleted.new("Team", [org_name, team_name])
|
49
|
-
end
|
50
|
-
|
51
|
-
def api
|
52
|
-
client.teams
|
53
|
-
end
|
54
|
-
|
55
|
-
def to_hash(team, org)
|
56
|
-
{
|
57
|
-
:id => team.id,
|
58
|
-
:name => team.name,
|
59
|
-
:org => org,
|
60
|
-
:permission => team.permission,
|
61
|
-
:members => client.users.list_for_team(team.id).to_a.size.to_s,
|
62
|
-
:created_at => team.created_at,
|
63
|
-
:updated_at => team.updated_at
|
64
|
-
}
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module Sem
|
2
|
-
module API
|
3
|
-
module Traits
|
4
|
-
module AssociatedWithOrg
|
5
|
-
PAGES_PER_CALL = 3
|
6
|
-
|
7
|
-
def list_for_org(org_name)
|
8
|
-
pages = Sem::Pagination.pages(PAGES_PER_CALL) do |page_index|
|
9
|
-
api.list_for_org(org_name, :page => page_index).to_a
|
10
|
-
end
|
11
|
-
|
12
|
-
pages.flatten.pmap { |instance| to_hash(instance, org_name) }
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
module Sem
|
2
|
-
module API
|
3
|
-
module Traits
|
4
|
-
module AssociatedWithProject
|
5
|
-
def list_for_project(org_name, project_name)
|
6
|
-
project = Projects.info(org_name, project_name)
|
7
|
-
|
8
|
-
instances = api.list_for_project(project[:id]).to_a
|
9
|
-
|
10
|
-
instances.map { |instance| to_hash(instance, org_name) }
|
11
|
-
end
|
12
|
-
|
13
|
-
def add_to_project(org_name, project_name, instance_name)
|
14
|
-
instance = info(org_name, instance_name)
|
15
|
-
project = Projects.info(org_name, project_name)
|
16
|
-
|
17
|
-
api.attach_to_project(instance[:id], project[:id])
|
18
|
-
end
|
19
|
-
|
20
|
-
def remove_from_project(org_name, project_name, instance_name)
|
21
|
-
instance = info(org_name, instance_name)
|
22
|
-
project = Projects.info(org_name, project_name)
|
23
|
-
|
24
|
-
api.detach_from_project(instance[:id], project[:id])
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
module Sem
|
2
|
-
module API
|
3
|
-
module Traits
|
4
|
-
module AssociatedWithSharedConfig
|
5
|
-
def list_for_shared_config(org_name, shared_config_name)
|
6
|
-
shared_config = SharedConfigs.info(org_name, shared_config_name)
|
7
|
-
|
8
|
-
instances = api.list_for_shared_config(shared_config[:id]).to_a
|
9
|
-
|
10
|
-
instances.map { |instance| to_hash(instance) }
|
11
|
-
end
|
12
|
-
|
13
|
-
def add_to_shared_config(org_name, shared_config_name, params)
|
14
|
-
shared_config = SharedConfigs.info(org_name, shared_config_name)
|
15
|
-
|
16
|
-
api.create_for_shared_config(shared_config[:id], params)
|
17
|
-
end
|
18
|
-
|
19
|
-
def remove_from_shared_config(org_name, shared_config_name, instance_name)
|
20
|
-
instances = list_for_shared_config(org_name, shared_config_name)
|
21
|
-
|
22
|
-
selected_instance = instances.find { |instance| instance[:name] == instance_name }
|
23
|
-
|
24
|
-
raise Sem::Errors::ResourceNotFound.new("Resource", [org_name, instance_name]) if selected_instance.nil?
|
25
|
-
|
26
|
-
api.delete(selected_instance[:id])
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
module Sem
|
2
|
-
module API
|
3
|
-
module Traits
|
4
|
-
module AssociatedWithTeam
|
5
|
-
def list_for_team(org_name, team_name)
|
6
|
-
team_id = Teams.name_to_id(org_name, team_name)
|
7
|
-
|
8
|
-
instances = api.list_for_team(team_id).to_a
|
9
|
-
|
10
|
-
instances.map { |instance| to_hash(instance, org_name) }
|
11
|
-
end
|
12
|
-
|
13
|
-
def add_to_team(org_name, team_name, instance_name)
|
14
|
-
instance_id = name_to_id(org_name, instance_name)
|
15
|
-
team_id = Teams.name_to_id(org_name, team_name)
|
16
|
-
|
17
|
-
api.attach_to_team(instance_id, team_id)
|
18
|
-
end
|
19
|
-
|
20
|
-
def remove_from_team(org_name, team_name, instance_name)
|
21
|
-
instance_id = name_to_id(org_name, instance_name)
|
22
|
-
team_id = Teams.name_to_id(org_name, team_name)
|
23
|
-
|
24
|
-
api.detach_from_team(instance_id, team_id)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
data/lib/sem/api/traits.rb
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
module Sem
|
2
|
-
module API
|
3
|
-
module Traits
|
4
|
-
require_relative "traits/associated_with_org"
|
5
|
-
require_relative "traits/associated_with_team"
|
6
|
-
require_relative "traits/associated_with_shared_config"
|
7
|
-
require_relative "traits/associated_with_project"
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
data/lib/sem/api/users.rb
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
module Sem
|
2
|
-
module API
|
3
|
-
class Users < Base
|
4
|
-
extend Traits::AssociatedWithOrg
|
5
|
-
extend Traits::AssociatedWithTeam
|
6
|
-
|
7
|
-
class << self
|
8
|
-
def name_to_id(_, name)
|
9
|
-
name
|
10
|
-
end
|
11
|
-
|
12
|
-
def list
|
13
|
-
org_names = Orgs.list.map { |org| org[:username] }
|
14
|
-
|
15
|
-
org_names.to_a.pmap { |name| list_for_org(name) }.flatten
|
16
|
-
end
|
17
|
-
|
18
|
-
def info(*args)
|
19
|
-
if args.count == 2
|
20
|
-
org_name, user_name = args
|
21
|
-
users = list_for_org(org_name)
|
22
|
-
else
|
23
|
-
user_name = args.first
|
24
|
-
users = list
|
25
|
-
end
|
26
|
-
|
27
|
-
selected_user = users.find { |user| user[:id] == user_name }
|
28
|
-
|
29
|
-
raise Sem::Errors::ResourceNotFound.new("User", [user_name]) if selected_user.nil?
|
30
|
-
|
31
|
-
selected_user
|
32
|
-
end
|
33
|
-
|
34
|
-
def api
|
35
|
-
client.users
|
36
|
-
end
|
37
|
-
|
38
|
-
def to_hash(user, _ = nil)
|
39
|
-
{ :id => user.username }
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|