api-clients 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 27349b1c4e24b1f6365753c40b8c6d4eb45808bd77e56af4e2a4452f170a6463
4
- data.tar.gz: f3c817aa66b949ffd78d98650eb2f85d59522e0080c6888a70dbf7a036f4727c
3
+ metadata.gz: 2d616c505ee1bc25f860ef1a86d70cbb3baf409bc22ce13c75c70029bd818501
4
+ data.tar.gz: 7e391a9af590565ae767849c76856b4af26c205b96ae7a917914b73a228baddf
5
5
  SHA512:
6
- metadata.gz: 642b69d625d514bc5d61f7ba4537c76798b508911ecf3adab5cab54486b4ef71d6fbcdf481873d2bddcbe170e8e1a355fdd183ffb0475077dcdeeec11d159ab2
7
- data.tar.gz: 71a573c26f8c602e190174f85b8c6d27c92ace795d0b076b61d178a9cade88dd00c993999ad3596281538a44aae0295832fb15217c42ac985e0be8f288c3b03f
6
+ metadata.gz: 5801e1db200707dcddace32ea0f5e9e0562bda0b59adbb37f05b2e43e03326d9a140d045b3d8e71407f2a767bb12e269b9fa2af2c42840516ea11153ecfb849b
7
+ data.tar.gz: f2d1b64e4fed0c5820cf7e9bec9c93f4a575f901576453ca5cbe6919815f5eeb5e28fedade8b9510e125b128ef13e322a6f5e0867a50b4fcc0a50ae814da828c
data/README.md CHANGED
@@ -1,30 +1,207 @@
1
- # Api::Clients
1
+ # CI jobs to tag projects in code tools
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
3
+ Adds jobs for cortex, mend and sonarqube to the pipelines, the jobs add the gitlab url of the hosting repository as a project tag on Mend, a project link in Sonarqube or open-api info in Cortex so that reporting can correlate tools by use of the gitlab url as the key.
4
4
 
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/api/clients`. To experiment with that code, run `bin/console` for an interactive prompt.
5
+ ## Use jobs in your pipelines
6
6
 
7
- ## Installation
7
+ Add the following lines to your .gitlab-ci.yml file:
8
8
 
9
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
9
+ ```
10
+ include: # add to your includes
11
+ - project: j.rivera/api-tools
12
+ file: gitlab-ci-includes.yml
13
+ ref: 53444d03851ffed62f457b8ad2aa6950f894d3aa
10
14
 
11
- Install the gem and add to the application's Gemfile by executing:
15
+ stages:
16
+ - code_tools # add to your stages
17
+ ```
12
18
 
13
- $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
19
+ That will add under the stage `code_tools` the jobs for Cortex (`cortex_project`), Mend (`mend_project`) and Sonarqube (`sonarqube_project`) to decorate those tools' projects with the url of the gitlab repository.
14
20
 
15
- If bundler is not being used to manage dependencies, install the gem by executing:
21
+ Next add environment variables needed by the jobs. Ask for help on it on slack channel #bet-tribe-odds-devops:
16
22
 
17
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
23
+ - `APICLIENTS_TOKEN` a gitlab access token for the repository [Api Clients](https://gitlab.sportradar.ag/j.rivera/api-tools)
24
+ - `CORTEX_API_KEY` Cortex API key
25
+ - `MEND_ORG_TOKEN` Mend organization token. Defaults to value of variable `WHITESOURCE_ORG_TOKEN`
26
+ - `MEND_PRODUCT` Mend product name. Defaults to value of `WHITESOURCE_PRODUCT`
27
+ - `MEND_PROJECT` Mend project name. Defaults to value of `WHITESOURCE_PROJECT_NAME`
28
+ - `MEND_USER_KEY` Mend user key. Defaults to value of `WHITESOURCE_USER_KEY`
29
+ - `SQ_PROJECT` Sonarqube project key. Defaults to value of `SONAR_PROJECT_KEY`
30
+ - `SQ_TOKEN` Sonarqube token
31
+ - `SQ_USER` Sonarqube user
18
32
 
19
- ## Usage
33
+ ### Adjust jobs to your pipeline
20
34
 
21
- TODO: Write usage instructions here
35
+ To override the jobs declare them in your `.gitlab-ci.yml`, in the examples below other variables' values are passed to the jobs:
36
+
37
+ ```
38
+ cortex-project:
39
+ extends: .cortex-project-decoration
40
+ variables:
41
+ CORTEX_API_KEY: $CORTEX_TOKEN
42
+
43
+ mend-project:
44
+ extends: .mend-project-decoration
45
+ variables:
46
+ MEND_ORG_TOKEN: $MEND_ORG_TOKEN
47
+ MEND_PRODUCT: $MEND_PRODUCT
48
+ MEND_PROJECT: $MEND_PROJECT_NAME
49
+ MEND_USER_KEY: $MEND_USER_KEY
50
+
51
+ sq-project:
52
+ extends: .sq-project-decoration
53
+ variables:
54
+ SQ_PROJECT: $SONARQUBE_PROJECT_KEY
55
+ SQ_TOKEN: $SONARQUBE_TOKEN
56
+ SQ_USER: $SONARQUBE_USER
57
+ ```
58
+
59
+ ## Ruby gem installation
60
+
61
+ Install the ruby gem with:
62
+
63
+ ```
64
+ $ gem install api-clients
65
+ ```
66
+
67
+ Or add to your application's Gemfile by executing:
68
+
69
+ ```
70
+ $ bundle add api-clients
71
+ $ bundle install
72
+ ```
73
+
74
+ Or install it from code, for that read below.
75
+
76
+ ## Ruby code usage
77
+
78
+ To play with the ruby code first install the gem.
79
+
80
+ ### For Cortex
81
+
82
+ To use cortex:
83
+
84
+ ```
85
+ $ bundle exec bin/console
86
+
87
+ irb > cortex = Api::Clients::Cortex.new gitlab_url: "https://gitlab.example.com/j.rivera/my-test-service"
88
+ =>
89
+ #<Api::Clients::Cortex:0x00005629f898d488
90
+ ...
91
+
92
+ irb > cortex.update_service!
93
+ => nil
94
+
95
+ irb > cortex.service_info
96
+ =>
97
+ {"info"=>
98
+ {"title"=>"odds-devops-test-service",
99
+ "description"=>"Test service for Odds devops tasks",
100
+ "x-cortex-git"=>
101
+ {"gitlab"=>
102
+ {"repository"=>"j.rivera/my-test-service"}},
103
+ "x-cortex-tag"=>
104
+ "oddsdevops_jrivera-my-test-service"},
105
+ "openapi"=>"3.0.1",
106
+ "servers"=>[{"url"=>"/"}]}
107
+ ```
108
+
109
+ ## Mend
110
+
111
+ To use Mend:
112
+
113
+ ```
114
+ export MEND_ORG_TOKEN=...
115
+ export MEND_USER_KEY=...
116
+
117
+ $ bundle exec bin/console
118
+
119
+ irb > mend = Api::Clients::Mend.new gitlab_url: "https://gitlab.example.com/j.rivera/my-test-service", product: "devops", project: "jrivera_my-test-service"
120
+ =>
121
+ #<Api::Clients::Mend:0x00005629f897ca48
122
+ ...
123
+
124
+ irb(main):010:0> mend.tag_project!
125
+ =>
126
+ {"projectTagsInfo"=>
127
+ {"name"=>"jrivera_my-test-service",
128
+ "token"=>
129
+ "1da9c170adeb421a89a9c4157acba3b30fe5856c02114536990eee8f17c87c7d",
130
+ "tags"=>
131
+ {"gitlab-url"=>
132
+ "https://gitlab.example.com/j.rivera/my-test-service"}}}
133
+
134
+ irb > mend.project_tags
135
+ =>
136
+ {"gitlab-url"=>
137
+ ["https://gitlab.example.com/j.rivera/my-test-service"]}
138
+ ```
139
+
140
+ ## Sonarqube
141
+
142
+ To use Sonarqube:
143
+
144
+ ```
145
+ export SQ_TOKEN=...
146
+ export SQ_USER=...
147
+
148
+ $ bundle exec bin/console
149
+
150
+ irb > sq = Api::Clients::Sonarqube.new gitlab_url: "https://gitlab.example.com/j.rivera/my-test-service", project: "jrivera_my-test-service"
151
+ =>
152
+ #<Api::Clients::Sonarqube:0x00005629f8248830
153
+ ...
154
+
155
+ irb > sq.link_project!
156
+ => nil
157
+
158
+ irb > sq.project
159
+ => "jrivera_my-test-service"
160
+
161
+ irb(main):005:0> sq.project_links
162
+ =>
163
+ [...
164
+ {"id"=>"AYmrhzwtxhyS1ZWWXNJ5",
165
+ "name"=>"gitlab-url",
166
+ "type"=>"gitlab-url",
167
+ "url"=>
168
+ "https://gitlab.example.com/j.rivera/my-test-service"}]
169
+ ```
22
170
 
23
171
  ## Development
24
172
 
25
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
173
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bundle exec bin/console` for an interactive prompt that will allow you to experiment.
174
+
175
+ TODO test instructions
176
+ To install this gem onto your local machine, run `bundle exec rake install`.
177
+
178
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
179
+
180
+ Update ruby code in directory `lib/api/`, in file `lib/api/clients/version.rb` increase version (0.0.1 in the example), then build it with:
181
+
182
+ ```
183
+ bundle
184
+ gem build api-clients.gemspec
185
+ ```
186
+
187
+ Install it locally to test:
188
+
189
+ ```
190
+ sudo gem install --local api-clients-0.0.1.gem
191
+ ```
192
+
193
+ Push it to rubygems for usage in pipelines:
194
+
195
+ ```
196
+ gem push api-clients-0.0.1.gem
197
+ ```
198
+
199
+ Tag the version:
26
200
 
27
- 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
201
+ ```
202
+ git tag 0.0.1
203
+ git push --tags
204
+ ``
28
205
 
29
206
  ## Contributing
30
207
 
data/Rakefile CHANGED
@@ -9,8 +9,4 @@ Rake::TestTask.new(:test) do |t|
9
9
  t.test_files = FileList["test/**/test_*.rb"]
10
10
  end
11
11
 
12
- require "rubocop/rake_task"
13
-
14
- RuboCop::RakeTask.new
15
-
16
- task default: %i[test rubocop]
12
+ task default: %i[test]
@@ -0,0 +1,50 @@
1
+ # Pipeline jobs to add gitlab-url to cortex, mend and sonarqube
2
+
3
+ .cortex-project-decoration:
4
+ image: ruby:latest
5
+ script:
6
+ - gem install api-clients
7
+ - git clone https://dummy:$APICLIENTS_TOKEN@gitlab.sportradar.ag/j.rivera/api-tools.git api-clients
8
+ - api-clients/scripts/cortex.rb
9
+
10
+ cortex-project:
11
+ extends: .cortex-project-decoration
12
+ stage: code_tools
13
+ variables:
14
+ CORTEX_API_KEY: $CORTEX_API_KEY
15
+ GITLAB_URL: $CI_PROJECT_URL
16
+
17
+
18
+ .mend-project-decoration:
19
+ image: ruby:latest
20
+ script:
21
+ - gem install api-clients
22
+ - git clone https://dummy:$APICLIENTS_TOKEN@gitlab.sportradar.ag/j.rivera/api-tools.git api-clients
23
+ - api-clients/scripts/mend.rb
24
+
25
+ mend-project:
26
+ extends: .mend-project-decoration
27
+ stage: code_tools
28
+ variables:
29
+ GITLAB_URL: $CI_PROJECT_URL
30
+ MEND_ORG_TOKEN: $WHITESOURCE_ORG_TOKEN
31
+ MEND_PRODUCT: $WHITESOURCE_PRODUCT
32
+ MEND_PROJECT: $WHITESOURCE_PROJECT_NAME
33
+ MEND_USER_KEY: $WHITESOURCE_USER_KEY
34
+
35
+
36
+ .sq-project-decoration:
37
+ image: ruby:latest
38
+ script:
39
+ - gem install api-clients
40
+ - git clone https://dummy:$APICLIENTS_TOKEN@gitlab.sportradar.ag/j.rivera/api-tools.git api-clients
41
+ - api-clients/scripts/sonarqube.rb
42
+
43
+ sq-project:
44
+ extends: .sq-project-decoration
45
+ stage: code_tools
46
+ variables:
47
+ GITLAB_URL: $CI_PROJECT_URL
48
+ SQ_PROJECT: $SONAR_PROJECT_KEY
49
+ SQ_TOKEN: $SQ_TOKEN
50
+ SQ_USER: $SQ_USER
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- # Public: Add gitlab path as info.x-cortex-tag to Cortex service
3
+ # Public: Will check whether gitlab path is added as info.x-cortex-tag to Cortex service
4
4
 
5
5
  require 'httparty'
6
6
  require 'json'
@@ -32,10 +32,10 @@ module Api
32
32
  @service_info ||= get_call(get_service_url)
33
33
  end
34
34
 
35
- # Public: add gitlab info to cortex service
36
- def update_service!
37
- return if service_has_gitlab_info?
38
- post_call post_service_url, post_body
35
+ # Public: check gitlab info in cortex service
36
+ def check_service
37
+ service_has_gitlab_info?
38
+ # post_call post_service_url, post_body
39
39
  end
40
40
 
41
41
  private
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Api
4
4
  module Clients
5
- VERSION = "0.0.1"
5
+ VERSION = "0.0.2"
6
6
  end
7
7
  end
data/scripts/cortex.rb ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Public: Add gitlab path as info.x-cortex-tag to Cortex service
4
+
5
+ require 'api/clients/cortex'
6
+ cortex = Api::Clients::Cortex.new(gitlab_url: ENV["GITLAB_URL"])
7
+ puts cortex.service_info
8
+ if cortex.check_service
9
+ puts "Cortex service has correct gitlab path"
10
+ else
11
+ puts "Cortex service has incorrect gitlab path! Please update your cortex.yaml with the gitlab path"
12
+ exit 1
13
+ end
data/scripts/mend.rb ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Public: Add gitlab url as tags to Mend project
4
+
5
+ require 'api/clients/mend'
6
+ mend = Api::Clients::Mend.new(product: ENV["MEND_PRODUCT"],
7
+ project: ENV["MEND_PROJECT"],
8
+ gitlab_url: ENV["GITLAB_URL"])
9
+ mend.tag_project!
10
+ puts "Project: #{mend.project}"
11
+ puts "Project tags:"
12
+ puts mend.project_tags
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Public: Add gitlab url as link to Sonarqube project
4
+
5
+ require 'api/clients/sonarqube'
6
+ sq = Api::Clients::Sonarqube.new(project: ENV["SQ_PROJECT"],
7
+ gitlab_url: ENV["GITLAB_URL"])
8
+ sq.link_project!
9
+ puts "Project: #{sq.project}"
10
+ puts "Project links:"
11
+ puts sq.project_links
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api-clients
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joaquin Rivera Padron
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-07-31 00:00:00.000000000 Z
11
+ date: 2023-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -39,11 +39,15 @@ files:
39
39
  - README.md
40
40
  - Rakefile
41
41
  - api-clients.gemspec
42
+ - gitlab-ci-includes.yml
42
43
  - lib/api/clients.rb
43
44
  - lib/api/clients/cortex.rb
44
45
  - lib/api/clients/mend.rb
45
46
  - lib/api/clients/sonarqube.rb
46
47
  - lib/api/clients/version.rb
48
+ - scripts/cortex.rb
49
+ - scripts/mend.rb
50
+ - scripts/sonarqube.rb
47
51
  - sig/api/clients.rbs
48
52
  homepage:
49
53
  licenses: