sem 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/exe/sem +1 -1
- data/lib/sem/api/org.rb +11 -9
- data/lib/sem/api/project.rb +22 -21
- data/lib/sem/api/shared_config.rb +13 -13
- data/lib/sem/api/team.rb +34 -22
- data/lib/sem/api/user.rb +1 -1
- data/lib/sem/cli/teams.rb +17 -3
- data/lib/sem/cli.rb +1 -1
- data/lib/sem/errors.rb +28 -3
- data/lib/sem/version.rb +1 -1
- data/lib/sem/views/env_vars.rb +3 -1
- data/lib/sem.rb +37 -57
- data/sem.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc0d24e7b183207c5e5cce1a800be13467d67e72
|
4
|
+
data.tar.gz: bce66ac37a1ea8d544f1f38c9f280ee5a4dafa19
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89048c8949432d45c90fb17ec3d82ea5644ee8c30eec1a80afc1f69ad5a3903443a27a67b576b7756ffcc731f38132800148b79de7b967e88bcfd9548ef43a83
|
7
|
+
data.tar.gz: 39e29cd19867577bdf1b1a8bf24d1447247088989fbd3d017937efe5a970fa5e31760caecf6c7e27656ceca3296b1bd0fcfc10f3b5119c5a1e0940d0de87c149
|
data/Gemfile
CHANGED
data/exe/sem
CHANGED
data/lib/sem/api/org.rb
CHANGED
@@ -2,27 +2,29 @@ class Sem::API::Org < SimpleDelegator
|
|
2
2
|
extend Sem::API::Base
|
3
3
|
|
4
4
|
def self.all
|
5
|
-
client.orgs.list
|
5
|
+
client.orgs.list!.map { |org| new(org) }
|
6
6
|
end
|
7
7
|
|
8
8
|
def self.find!(org_name)
|
9
|
-
|
10
|
-
|
11
|
-
raise Sem::Errors::ResourceNotFound.new("Organization", [org_name])
|
12
|
-
|
13
|
-
new(org)
|
9
|
+
new(client.orgs.get!(org_name))
|
10
|
+
rescue SemaphoreClient::Exceptions::NotFound
|
11
|
+
raise Sem::Errors::ResourceNotFound.new("Organization", [org_name])
|
14
12
|
end
|
15
13
|
|
16
14
|
def users
|
17
|
-
Sem::API::Base.client.users.list_for_org(
|
15
|
+
Sem::API::Base.client.users.list_for_org!(username).map { |user| Sem::API::User.new(user) }
|
18
16
|
end
|
19
17
|
|
20
18
|
def teams
|
21
|
-
Sem::API::Base.client.teams.list_for_org(
|
19
|
+
Sem::API::Base.client.teams.list_for_org!(username).map { |team| Sem::API::Team.new(username, team) }
|
22
20
|
end
|
23
21
|
|
24
22
|
def projects
|
25
|
-
Sem::API::Base.client.projects.list_for_org(
|
23
|
+
Sem::API::Base.client.projects.list_for_org!(username).map { |project| Sem::API::Project.new(username, project) }
|
24
|
+
end
|
25
|
+
|
26
|
+
def shared_configs
|
27
|
+
Sem::API::Base.client.shared_configs.list_for_org!(username).map { |config| Sem::API::SharedConfig.new(username, config) }
|
26
28
|
end
|
27
29
|
|
28
30
|
end
|
data/lib/sem/api/project.rb
CHANGED
@@ -2,31 +2,32 @@ class Sem::API::Project < SimpleDelegator
|
|
2
2
|
extend Sem::API::Base
|
3
3
|
|
4
4
|
def self.all
|
5
|
-
Sem::API::Org.all.map
|
6
|
-
client.projects.list_for_org(org.username).map { |project| new(org.username, project) }
|
7
|
-
end.flatten
|
5
|
+
Sem::API::Org.all.map(&:projects).flatten
|
8
6
|
end
|
9
7
|
|
10
8
|
def self.find!(project_srn)
|
11
9
|
org_name, project_name = Sem::SRN.parse_project(project_srn)
|
12
10
|
|
13
|
-
|
11
|
+
projects = client.projects.list_for_org!(org_name, :name => project_name)
|
12
|
+
project = projects.to_a.first
|
14
13
|
|
15
|
-
project
|
16
|
-
|
17
|
-
|
14
|
+
if project.nil?
|
15
|
+
raise Sem::Errors::ResourceNotFound.new("Project", [org_name, project_name])
|
16
|
+
end
|
18
17
|
|
19
18
|
new(org_name, project)
|
19
|
+
rescue SemaphoreClient::Exceptions::NotFound
|
20
|
+
raise Sem::Errors::ResourceNotFound.new("Project", [org_name, project_name])
|
20
21
|
end
|
21
22
|
|
22
23
|
def self.create!(project_srn, args)
|
23
24
|
org_name, name = Sem::SRN.parse_project(project_srn)
|
24
25
|
|
25
|
-
project = client.projects.create_for_org(org_name, args.merge(:name => name))
|
26
|
-
|
27
|
-
raise Sem::Errors::ResourceNotCreated.new("Project", [org_name, name]) if project.nil?
|
26
|
+
project = client.projects.create_for_org!(org_name, args.merge(:name => name))
|
28
27
|
|
29
28
|
new(org_name, project)
|
29
|
+
rescue SemaphoreClient::Exceptions::NotFound
|
30
|
+
raise Sem::Errors::ResourceNotFound.new("Organization", [org_name])
|
30
31
|
end
|
31
32
|
|
32
33
|
attr_reader :org_name
|
@@ -41,36 +42,36 @@ class Sem::API::Project < SimpleDelegator
|
|
41
42
|
"#{@org_name}/#{name}"
|
42
43
|
end
|
43
44
|
|
44
|
-
def teams
|
45
|
-
client.teams.list_for_project(id).map { |team| Sem::API::Team.new(org_name, team) }
|
46
|
-
end
|
47
|
-
|
48
45
|
def shared_configs
|
49
|
-
Sem::API::Base.client.shared_configs.list_for_project(id).map { |config| Sem::API::SharedConfig.new(org_name, config) }
|
46
|
+
Sem::API::Base.client.shared_configs.list_for_project!(id).map { |config| Sem::API::SharedConfig.new(org_name, config) }
|
50
47
|
end
|
51
48
|
|
52
49
|
def add_shared_config(shared_config)
|
53
|
-
Sem::API::Base.client.shared_configs.attach_to_project(shared_config.id, id)
|
50
|
+
Sem::API::Base.client.shared_configs.attach_to_project!(shared_config.id, id)
|
51
|
+
rescue SemaphoreClient::Exceptions::NotFound
|
52
|
+
raise Sem::Errors::ResourceNotFound.new("Shared Configuration", [shared_config.full_name])
|
54
53
|
end
|
55
54
|
|
56
55
|
def remove_shared_config(shared_config)
|
57
|
-
Sem::API::Base.client.shared_configs.detach_from_project(shared_config.id, id)
|
56
|
+
Sem::API::Base.client.shared_configs.detach_from_project!(shared_config.id, id)
|
57
|
+
rescue SemaphoreClient::Exceptions::NotFound
|
58
|
+
raise Sem::Errors::ResourceNotFound.new("Shared Configuration", [shared_config.full_name])
|
58
59
|
end
|
59
60
|
|
60
61
|
def config_files
|
61
|
-
Sem::API::Base.client.config_files.list_for_project(id).map { |file| Sem::API::File.new(file) }
|
62
|
+
Sem::API::Base.client.config_files.list_for_project!(id).map { |file| Sem::API::File.new(file) }
|
62
63
|
end
|
63
64
|
|
64
65
|
def env_vars
|
65
|
-
Sem::API::Base.client.env_vars.list_for_project(id).map { |var| Sem::API::EnvVar.new(var) }
|
66
|
+
Sem::API::Base.client.env_vars.list_for_project!(id).map { |var| Sem::API::EnvVar.new(var) }
|
66
67
|
end
|
67
68
|
|
68
69
|
def add_env_var(env_var)
|
69
|
-
Sem::API::Base.client.env_vars.attach_to_project(env_var.id, id)
|
70
|
+
Sem::API::Base.client.env_vars.attach_to_project!(env_var.id, id)
|
70
71
|
end
|
71
72
|
|
72
73
|
def add_config_file(config_file)
|
73
|
-
Sem::API::Base.client.config_files.attach_to_project(config_file.id, id)
|
74
|
+
Sem::API::Base.client.config_files.attach_to_project!(config_file.id, id)
|
74
75
|
end
|
75
76
|
|
76
77
|
end
|
@@ -2,15 +2,13 @@ class Sem::API::SharedConfig < SimpleDelegator
|
|
2
2
|
extend Sem::API::Base
|
3
3
|
|
4
4
|
def self.all
|
5
|
-
Sem::API::Org.all.pmap
|
6
|
-
client.shared_configs.list_for_org(org.username).map { |config| new(org.username, config) }
|
7
|
-
end.flatten
|
5
|
+
Sem::API::Org.all.pmap(&:shared_configs).flatten
|
8
6
|
end
|
9
7
|
|
10
8
|
def self.find!(shared_config_srn)
|
11
9
|
org_name, shared_config_name = Sem::SRN.parse_shared_config(shared_config_srn)
|
12
10
|
|
13
|
-
configs = client.shared_configs.list_for_org(org_name)
|
11
|
+
configs = client.shared_configs.list_for_org!(org_name)
|
14
12
|
config = configs.find { |c| c.name == shared_config_name }
|
15
13
|
|
16
14
|
if config.nil?
|
@@ -18,12 +16,14 @@ class Sem::API::SharedConfig < SimpleDelegator
|
|
18
16
|
end
|
19
17
|
|
20
18
|
new(org_name, config)
|
19
|
+
rescue SemaphoreClient::Exceptions::NotFound
|
20
|
+
raise Sem::Errors::ResourceNotFound.new("Shared Configuration", [org_name, shared_config_name])
|
21
21
|
end
|
22
22
|
|
23
23
|
def self.create!(shared_config_srn, args = {})
|
24
24
|
org_name, shared_config_name = Sem::SRN.parse_shared_config(shared_config_srn)
|
25
25
|
|
26
|
-
shared_config = client.shared_configs.create_for_org(org_name, args.merge(:name => shared_config_name))
|
26
|
+
shared_config = client.shared_configs.create_for_org!(org_name, args.merge(:name => shared_config_name))
|
27
27
|
|
28
28
|
if shared_config.nil?
|
29
29
|
raise Sem::Errors::ResourceNotCreated.new("Shared Configuration", [org_name, shared_config_name])
|
@@ -45,7 +45,7 @@ class Sem::API::SharedConfig < SimpleDelegator
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def add_config_file(args)
|
48
|
-
file = Sem::API::Base.client.config_files.create_for_shared_config(id, args)
|
48
|
+
file = Sem::API::Base.client.config_files.create_for_shared_config!(id, args)
|
49
49
|
|
50
50
|
if file.nil?
|
51
51
|
raise Sem::Errors::ResourceNotCreated.new("Configuration File", [org_name, path])
|
@@ -61,11 +61,11 @@ class Sem::API::SharedConfig < SimpleDelegator
|
|
61
61
|
raise Sem::Errors::ResourceNotCreated.new("Configuration File", [org_name, path])
|
62
62
|
end
|
63
63
|
|
64
|
-
Sem::API::Base.client.config_files.delete(file.id)
|
64
|
+
Sem::API::Base.client.config_files.delete!(file.id)
|
65
65
|
end
|
66
66
|
|
67
67
|
def add_env_var(args)
|
68
|
-
env_var = Sem::API::Base.client.env_vars.create_for_shared_config(id, args)
|
68
|
+
env_var = Sem::API::Base.client.env_vars.create_for_shared_config!(id, args)
|
69
69
|
|
70
70
|
if env_var.nil?
|
71
71
|
raise Sem::Errors::ResourceNotCreated.new("Environment Variable", [org_name, args[:name]])
|
@@ -81,11 +81,11 @@ class Sem::API::SharedConfig < SimpleDelegator
|
|
81
81
|
raise Sem::Errors::ResourceNotFound.new("Environment Variable", [org_name, name])
|
82
82
|
end
|
83
83
|
|
84
|
-
Sem::API::Base.client.env_vars.delete(env_var.id)
|
84
|
+
Sem::API::Base.client.env_vars.delete!(env_var.id)
|
85
85
|
end
|
86
86
|
|
87
87
|
def update!(args)
|
88
|
-
shared_config = Sem::API::Base.client.shared_configs.update(id, args)
|
88
|
+
shared_config = Sem::API::Base.client.shared_configs.update!(id, args)
|
89
89
|
|
90
90
|
if shared_config.nil?
|
91
91
|
raise Sem::Errors::ResourceNotUpdated.new("Shared Configuration", [org_name, name])
|
@@ -95,15 +95,15 @@ class Sem::API::SharedConfig < SimpleDelegator
|
|
95
95
|
end
|
96
96
|
|
97
97
|
def delete!
|
98
|
-
Sem::API::Base.client.shared_configs.delete(id)
|
98
|
+
Sem::API::Base.client.shared_configs.delete!(id)
|
99
99
|
end
|
100
100
|
|
101
101
|
def files
|
102
|
-
Sem::API::Base.client.config_files.list_for_shared_config(id).map { |file| Sem::API::File.new(file) }
|
102
|
+
Sem::API::Base.client.config_files.list_for_shared_config!(id).map { |file| Sem::API::File.new(file) }
|
103
103
|
end
|
104
104
|
|
105
105
|
def env_vars
|
106
|
-
Sem::API::Base.client.env_vars.list_for_shared_config(id).map { |env_var| Sem::API::EnvVar.new(env_var) }
|
106
|
+
Sem::API::Base.client.env_vars.list_for_shared_config!(id).map { |env_var| Sem::API::EnvVar.new(env_var) }
|
107
107
|
end
|
108
108
|
|
109
109
|
end
|
data/lib/sem/api/team.rb
CHANGED
@@ -2,29 +2,31 @@ class Sem::API::Team < SimpleDelegator
|
|
2
2
|
extend Sem::API::Base
|
3
3
|
|
4
4
|
def self.all
|
5
|
-
Sem::API::Org.all.pmap
|
6
|
-
client.teams.list_for_org(org.username).map { |team| new(org.username, team) }
|
7
|
-
end.flatten
|
5
|
+
Sem::API::Org.all.pmap(&:teams).flatten
|
8
6
|
end
|
9
7
|
|
10
8
|
def self.find!(team_srn)
|
11
9
|
org_name, team_name = Sem::SRN.parse_team(team_srn)
|
12
10
|
|
13
|
-
team = client.teams.list_for_org(org_name).find { |t| t.name == team_name }
|
11
|
+
team = client.teams.list_for_org!(org_name).find { |t| t.name == team_name }
|
14
12
|
|
15
|
-
|
13
|
+
if team.nil?
|
14
|
+
raise Sem::Errors::ResourceNotFound.new("Team", [org_name, team_name])
|
15
|
+
end
|
16
16
|
|
17
17
|
new(org_name, team)
|
18
|
+
rescue SemaphoreClient::Exceptions::NotFound
|
19
|
+
raise Sem::Errors::ResourceNotFound.new("Team", [org_name, team_name])
|
18
20
|
end
|
19
21
|
|
20
22
|
def self.create!(team_srn, args)
|
21
23
|
org_name, team_name = Sem::SRN.parse_team(team_srn)
|
22
24
|
|
23
|
-
team = client.teams.create_for_org(org_name, args.merge(:name => team_name))
|
24
|
-
|
25
|
-
raise Sem::Errors::ResourceNotCreated.new("Team", [org_name, team_name]) if team.nil?
|
25
|
+
team = client.teams.create_for_org!(org_name, args.merge(:name => team_name))
|
26
26
|
|
27
27
|
new(org_name, team)
|
28
|
+
rescue SemaphoreClient::Exceptions::NotFound
|
29
|
+
raise Sem::Errors::ResourceNotFound.new("Organization", [org_name])
|
28
30
|
end
|
29
31
|
|
30
32
|
attr_reader :org_name
|
@@ -39,52 +41,62 @@ class Sem::API::Team < SimpleDelegator
|
|
39
41
|
"#{org_name}/#{name}"
|
40
42
|
end
|
41
43
|
|
42
|
-
def update(args)
|
43
|
-
new_team = Sem::API::Base.client.teams.update(id, args)
|
44
|
-
|
45
|
-
raise Sem::Errors::ResourceNotUpdated.new("Team", [@org_name, name]) unless new_team
|
44
|
+
def update!(args)
|
45
|
+
new_team = Sem::API::Base.client.teams.update!(id, args)
|
46
46
|
|
47
47
|
self.class.new(@org_name, new_team)
|
48
48
|
end
|
49
49
|
|
50
50
|
def add_user(username)
|
51
|
-
Sem::API::Base.client.users.attach_to_team(username, id)
|
51
|
+
Sem::API::Base.client.users.attach_to_team!(username, id)
|
52
|
+
rescue SemaphoreClient::Exceptions::NotFound
|
53
|
+
raise Sem::Errors::ResourceNotFound.new("User", [username])
|
52
54
|
end
|
53
55
|
|
54
56
|
def remove_user(username)
|
55
|
-
Sem::API::Base.client.users.detach_from_team(username, id)
|
57
|
+
Sem::API::Base.client.users.detach_from_team!(username, id)
|
58
|
+
rescue SemaphoreClient::Exceptions::NotFound
|
59
|
+
raise Sem::Errors::ResourceNotFound.new("User", [username])
|
56
60
|
end
|
57
61
|
|
58
62
|
def add_project(project)
|
59
|
-
Sem::API::Base.client.projects.attach_to_team(project.id, id)
|
63
|
+
Sem::API::Base.client.projects.attach_to_team!(project.id, id)
|
64
|
+
rescue SemaphoreClient::Exceptions::NotFound
|
65
|
+
raise Sem::Errors::ResourceNotFound.new("Project", [project.full_name])
|
60
66
|
end
|
61
67
|
|
62
68
|
def remove_project(project)
|
63
|
-
Sem::API::Base.client.projects.detach_from_team(project.id, id)
|
69
|
+
Sem::API::Base.client.projects.detach_from_team!(project.id, id)
|
70
|
+
rescue SemaphoreClient::Exceptions::NotFound
|
71
|
+
raise Sem::Errors::ResourceNotFound.new("Project", [project.full_name])
|
64
72
|
end
|
65
73
|
|
66
74
|
def add_shared_config(config)
|
67
|
-
Sem::API::Base.client.shared_configs.attach_to_team(config.id, id)
|
75
|
+
Sem::API::Base.client.shared_configs.attach_to_team!(config.id, id)
|
76
|
+
rescue SemaphoreClient::Exceptions::NotFound
|
77
|
+
raise Sem::Errors::ResourceNotFound.new("Shared Configuration", [config.full_name])
|
68
78
|
end
|
69
79
|
|
70
80
|
def remove_shared_config(config)
|
71
|
-
Sem::API::Base.client.shared_configs.detach_from_team(config.id, id)
|
81
|
+
Sem::API::Base.client.shared_configs.detach_from_team!(config.id, id)
|
82
|
+
rescue SemaphoreClient::Exceptions::NotFound
|
83
|
+
raise Sem::Errors::ResourceNotFound.new("Shared Configuration", [config.full_name])
|
72
84
|
end
|
73
85
|
|
74
86
|
def delete!
|
75
|
-
Sem::API::Base.client.teams.delete(id)
|
87
|
+
Sem::API::Base.client.teams.delete!(id)
|
76
88
|
end
|
77
89
|
|
78
90
|
def users
|
79
|
-
Sem::API::Base.client.users.list_for_team(id).map { |user| Sem::API::User.new(user) }
|
91
|
+
Sem::API::Base.client.users.list_for_team!(id).map { |user| Sem::API::User.new(user) }
|
80
92
|
end
|
81
93
|
|
82
94
|
def projects
|
83
|
-
Sem::API::Base.client.projects.list_for_team(id).map { |project| Sem::API::Project.new(org_name, project) }
|
95
|
+
Sem::API::Base.client.projects.list_for_team!(id).map { |project| Sem::API::Project.new(org_name, project) }
|
84
96
|
end
|
85
97
|
|
86
98
|
def shared_configs
|
87
|
-
Sem::API::Base.client.shared_configs.list_for_team(id).map { |config| Sem::API::SharedConfig.new(org_name, config) }
|
99
|
+
Sem::API::Base.client.shared_configs.list_for_team!(id).map { |config| Sem::API::SharedConfig.new(org_name, config) }
|
88
100
|
end
|
89
101
|
|
90
102
|
end
|
data/lib/sem/api/user.rb
CHANGED
data/lib/sem/cli/teams.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
class Sem::CLI::Teams < Dracula
|
2
2
|
|
3
|
+
ALLOWED_PERMISSIONS = ["admin", "edit", "read"].freeze
|
4
|
+
|
3
5
|
desc "list", "list teams"
|
4
6
|
def list
|
5
7
|
teams = Sem::API::Team.all
|
@@ -23,7 +25,13 @@ class Sem::CLI::Teams < Dracula
|
|
23
25
|
:aliases => "p",
|
24
26
|
:desc => "Permission level of the team in the organization"
|
25
27
|
def create(team_name)
|
26
|
-
|
28
|
+
permission = options[:permission]
|
29
|
+
|
30
|
+
unless ALLOWED_PERMISSIONS.include?(permission)
|
31
|
+
abort "Permission must be one of [#{ALLOWED_PERMISSIONS.join(", ")}]"
|
32
|
+
end
|
33
|
+
|
34
|
+
team = Sem::API::Team.create!(team_name, :permission => permission)
|
27
35
|
|
28
36
|
Sem::Views::Teams.info(team)
|
29
37
|
end
|
@@ -36,7 +44,7 @@ class Sem::CLI::Teams < Dracula
|
|
36
44
|
abort "Team can't change its organization" unless new_org_name == old_org_name
|
37
45
|
|
38
46
|
team = Sem::API::Team.find!(old_team_name)
|
39
|
-
team = team.update(:name => new_name)
|
47
|
+
team = team.update!(:name => new_name)
|
40
48
|
|
41
49
|
Sem::Views::Teams.info(team)
|
42
50
|
end
|
@@ -47,8 +55,14 @@ class Sem::CLI::Teams < Dracula
|
|
47
55
|
:aliases => "p",
|
48
56
|
:desc => "Permission level of the team in the organization"
|
49
57
|
def set_permission(team_name) # rubocop:disable Style/AccessorMethodName
|
58
|
+
permission = options[:permission]
|
59
|
+
|
60
|
+
unless ALLOWED_PERMISSIONS.include?(permission)
|
61
|
+
abort "Permission must be one of [#{ALLOWED_PERMISSIONS.join(", ")}]"
|
62
|
+
end
|
63
|
+
|
50
64
|
team = Sem::API::Team.find!(team_name)
|
51
|
-
team = team.update(:permission =>
|
65
|
+
team = team.update!(:permission => permission)
|
52
66
|
|
53
67
|
Sem::Views::Teams.info(team)
|
54
68
|
end
|
data/lib/sem/cli.rb
CHANGED
@@ -15,7 +15,7 @@ module Sem
|
|
15
15
|
desc "login", "Log in to semaphore from the command line"
|
16
16
|
option "auth-token", :required => true
|
17
17
|
long_desc <<-DESC
|
18
|
-
You can find your
|
18
|
+
You can find your auth-token on the bottom of the users settings page https://semaphoreci.com/users/edit.
|
19
19
|
DESC
|
20
20
|
def login
|
21
21
|
auth_token = options["auth-token"]
|
data/lib/sem/errors.rb
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
module Sem::Errors
|
2
2
|
Base = Class.new(StandardError)
|
3
3
|
|
4
|
-
InvalidSRN
|
4
|
+
class InvalidSRN < StandardError
|
5
|
+
def message
|
6
|
+
[
|
7
|
+
"[ERROR] Invalid parameter formatting.",
|
8
|
+
"",
|
9
|
+
super
|
10
|
+
].join("\n")
|
11
|
+
end
|
12
|
+
end
|
5
13
|
|
6
14
|
class ResourceException < Base
|
7
15
|
def initialize(resource, path)
|
@@ -35,7 +43,24 @@ module Sem::Errors
|
|
35
43
|
end
|
36
44
|
|
37
45
|
module Auth
|
38
|
-
NoCredentials
|
39
|
-
|
46
|
+
class NoCredentials < Sem::Errors::Base
|
47
|
+
def message
|
48
|
+
[
|
49
|
+
"[ERROR] You are not logged in.",
|
50
|
+
"",
|
51
|
+
"Log in with '#{Sem::CLI.program_name} login --auth-token <token>'"
|
52
|
+
].join("\n")
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
class InvalidCredentials < Sem::Errors::Base
|
57
|
+
def message
|
58
|
+
[
|
59
|
+
"[ERROR] Your credentials are invalid.",
|
60
|
+
"",
|
61
|
+
"Log in with '#{Sem::CLI.program_name} login --auth-token <token>'"
|
62
|
+
].join("\n")
|
63
|
+
end
|
64
|
+
end
|
40
65
|
end
|
41
66
|
end
|
data/lib/sem/version.rb
CHANGED
data/lib/sem/views/env_vars.rb
CHANGED
@@ -4,7 +4,9 @@ class Sem::Views::EnvVars < Sem::Views::Base
|
|
4
4
|
header = ["ID", "NAME", "ENCRYPTED?", "CONTENT"]
|
5
5
|
|
6
6
|
body = env_vars.map do |var|
|
7
|
-
|
7
|
+
content = var.encrypted? ? "*encrypted*" : var.content
|
8
|
+
|
9
|
+
[var.id, var.name, var.encrypted?, content]
|
8
10
|
end
|
9
11
|
|
10
12
|
print_table([header, *body])
|
data/lib/sem.rb
CHANGED
@@ -21,75 +21,55 @@ module Sem
|
|
21
21
|
@trace_mode == true
|
22
22
|
end
|
23
23
|
|
24
|
+
def run_in_trace_mode!
|
25
|
+
@trace_mode = true
|
26
|
+
end
|
27
|
+
|
24
28
|
# Returns exit status as a number.
|
29
|
+
# rubocop:disable Metrics/AbcSize
|
25
30
|
def start(args)
|
26
|
-
if args.include?("--trace")
|
27
|
-
@trace_mode = true
|
28
|
-
|
29
|
-
args.delete("--trace")
|
30
|
-
end
|
31
|
+
args.delete("--trace") && run_in_trace_mode! if args.include?("--trace")
|
31
32
|
|
32
33
|
Sem::CLI.start(args)
|
33
|
-
|
34
|
-
|
35
|
-
rescue
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
rescue
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
rescue Sem::Errors::InvalidSRN => e
|
44
|
-
on_invalid_srn(e)
|
45
|
-
|
46
|
-
1
|
47
|
-
rescue Sem::Errors::Auth::NoCredentials
|
48
|
-
on_no_credentials
|
49
|
-
|
50
|
-
1
|
51
|
-
rescue Sem::Errors::Auth::InvalidCredentials
|
52
|
-
on_invalid_credentials
|
53
|
-
|
54
|
-
1
|
34
|
+
rescue Sem::Errors::Base => e
|
35
|
+
abort e.message
|
36
|
+
rescue SemaphoreClient::Exceptions::Conflict, SemaphoreClient::Exceptions::NotAllowed => e
|
37
|
+
abort "[ERROR] #{e.message}"
|
38
|
+
rescue SemaphoreClient::Exceptions::Unauthorized => e
|
39
|
+
abort "[ERROR] #{e.message}. Check if your credentials are valid."
|
40
|
+
rescue SemaphoreClient::Exceptions::ServerError => e
|
41
|
+
abort on_server_error(e)
|
42
|
+
rescue SemaphoreClient::Exceptions::UnprocessableEntity => e
|
43
|
+
abort "[ERROR] #{e.message}"
|
55
44
|
rescue StandardError => e
|
56
|
-
on_unhandled_error(e)
|
57
|
-
|
58
|
-
1
|
45
|
+
abort on_unhandled_error(e)
|
59
46
|
end
|
60
47
|
|
61
48
|
private
|
62
49
|
|
63
|
-
def
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
puts ""
|
72
|
-
puts "Log in with '#{Sem::CLI.program_name} login --auth-token <token>'"
|
73
|
-
end
|
74
|
-
|
75
|
-
def on_invalid_credentials
|
76
|
-
puts "[ERROR] Your credentials are invalid."
|
77
|
-
puts ""
|
78
|
-
puts "Log in with '#{Sem::CLI.program_name} login --auth-token <token>'"
|
50
|
+
def on_server_error(exception)
|
51
|
+
[
|
52
|
+
"[ERROR] Semaphore API returned status #{exception.code}.",
|
53
|
+
"",
|
54
|
+
exception.message,
|
55
|
+
"",
|
56
|
+
"Please report this issue to https://semaphoreci.com/support."
|
57
|
+
].join("\n")
|
79
58
|
end
|
80
59
|
|
81
60
|
def on_unhandled_error(exception)
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
61
|
+
[
|
62
|
+
"[PANIC] Unhandled error.",
|
63
|
+
"",
|
64
|
+
"Well, this is embarrassing. An unknown error was detected.",
|
65
|
+
"",
|
66
|
+
"#{exception.class.name}: #{exception.message}",
|
67
|
+
"",
|
68
|
+
"Backtrace: ",
|
69
|
+
exception.backtrace,
|
70
|
+
"",
|
71
|
+
"Please report this issue to https://semaphoreci.com/support."
|
72
|
+
].join("\n")
|
93
73
|
end
|
94
74
|
end
|
95
75
|
|
data/sem.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
|
24
|
-
spec.add_dependency "semaphore_client", "2.
|
24
|
+
spec.add_dependency "semaphore_client", "2.8.1"
|
25
25
|
spec.add_dependency "dracula", "~> 0.4.0"
|
26
26
|
spec.add_dependency "pmap", "~> 1.1.1"
|
27
27
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sem
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor Šarčević
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: semaphore_client
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 2.
|
19
|
+
version: 2.8.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 2.
|
26
|
+
version: 2.8.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: dracula
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|