Skip to content

Commit 9c0d645

Browse files
committed
add sast & lint check workflows
1 parent 390f5a1 commit 9c0d645

31 files changed

+543
-406
lines changed

.github/actions/linter_ruby.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
on:
2+
workflow_call:
3+
secrets:
4+
token:
5+
required: true
6+
7+
jobs:
8+
rubocop:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v4
14+
15+
- name: Set up Ruby versions
16+
uses: ruby/setup-ruby@v1
17+
with:
18+
bundler-cache: false
19+
20+
- name: Install Rubocop
21+
run: |
22+
gem install rubocop-rails-omakase -N
23+
gem install rubocop-rspec -N
24+
25+
- name: Run Rubocop
26+
run: rubocop --lint

.github/actions/sast_ruby.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: SAST
2+
3+
on:
4+
workflow_call:
5+
secrets:
6+
token:
7+
required: true
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
brakeman:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
20+
- name: Set up Ruby
21+
uses: ruby/setup-ruby@v1
22+
with:
23+
bundler-cache: false
24+
25+
- name: Install Brakeman
26+
run: gem install brakeman -N
27+
28+
- name: Run brakeman
29+
run: brakeman --force
30+
31+
bearer:
32+
runs-on: ubuntu-latest
33+
34+
steps:
35+
- uses: actions/checkout@v4
36+
37+
- name: Set up Ruby versions
38+
uses: ruby/setup-ruby@v1
39+
40+
- name: Bearer
41+
uses: bearer/bearer-action@v2

.github/workflows/linter_ruby.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ on:
66

77
jobs:
88
lint:
9-
uses: anynines/int-gitops/.github/workflows/linter_ruby.yml@master
9+
uses: ./.github/actions/linter_ruby.yml
1010
secrets:
1111
token: ${{ secrets.GITHUB_TOKEN }}
1212

1313
sast:
14-
uses: anynines/int-gitops/.github/workflows/sast_ruby.yml@master
14+
uses: ./.github/actions/sast_ruby.yml
1515
secrets:
1616
token: ${{ secrets.GITHUB_TOKEN }}

.rubocop.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
plugins:
2+
- rubocop-performance
3+
- rubocop-rails
4+
- rubocop-rspec
5+
6+
AllCops:
7+
# Insert your target ruby version
8+
TargetRubyVersion: 3.1.x
9+
NewCops: enable
10+
11+
# Overwrite or add rules to create your own house style
12+
#
13+
# # Use `[a, [b, c]]` not `[ a, [ b, c ] ]`
14+
# Layout/SpaceInsideArrayLiteralBrackets:
15+
# Enabled: false
16+
17+
Layout/IndentationConsistency:
18+
Enabled: true
19+
20+
Layout/IndentationWidth:
21+
Enabled: true
22+
23+
Bundler:
24+
Enabled: true
25+
Gemspec:
26+
Enabled: true
27+
Layout:
28+
Enabled: true
29+
Lint:
30+
Enabled: true
31+
Metrics:
32+
Enabled: true
33+
Naming:
34+
Enabled: true
35+
Performance:
36+
Enabled: true
37+
Exclude:
38+
- "spec/**/*"
39+
Rails:
40+
Enabled: true
41+
Security:
42+
Enabled: true
43+
Style:
44+
Enabled: true

Gemfile

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,29 @@ ruby '3.1.3'
44

55
gem 'rails', '~> 7.0.0'
66

7-
gem 'eventmachine'
87
gem 'amqp'
9-
gem 'honeybadger'
108
gem 'erubis'
9+
gem 'eventmachine'
10+
gem 'honeybadger'
1111
gem 'listen'
1212

1313
gem 'net-smtp'
14-
gem 'webrick', '~> 1.7'
1514
gem 'psych', '< 4'
15+
gem 'webrick', '~> 1.7'
1616

1717
gem 'hashie'
1818

1919
gem 'pg'
2020

2121
gem 'nokogiri', '~> 1.18.4'
22-
gem "rack", "~> 2.2.13"
22+
gem 'rack', '~> 2.2.13'
2323

2424
group :test do
2525
gem 'byebug'
26-
gem 'rspec-rails'
27-
gem "factory_bot_rails", "~> 4.0"
28-
gem 'mocha', :require => false
2926
gem 'database_cleaner'
27+
gem 'factory_bot_rails', '~> 4.0'
28+
gem 'mocha', require: false
29+
gem 'rspec-rails'
30+
gem 'rubocop-rails-omakase', require: false
31+
gem 'rubocop-rspec'
3032
end

Gemfile.lock

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ GEM
7070
amqp (1.8.0)
7171
amq-protocol (>= 2.2.0)
7272
eventmachine
73+
ast (2.4.3)
7374
base64 (0.2.0)
7475
builder (3.3.0)
7576
byebug (11.1.3)
@@ -98,6 +99,9 @@ GEM
9899
honeybadger (5.0.2)
99100
i18n (1.14.7)
100101
concurrent-ruby (~> 1.0)
102+
json (2.17.1)
103+
language_server-protocol (3.17.0.5)
104+
lint_roller (1.1.0)
101105
listen (3.7.1)
102106
rb-fsevent (~> 0.10, >= 0.10.3)
103107
rb-inotify (~> 0.9, >= 0.9.10)
@@ -129,7 +133,12 @@ GEM
129133
racc (~> 1.4)
130134
nokogiri (1.18.7-x86_64-darwin)
131135
racc (~> 1.4)
136+
parallel (1.27.0)
137+
parser (3.3.10.0)
138+
ast (~> 2.4.1)
139+
racc
132140
pg (1.4.4)
141+
prism (1.6.0)
133142
psych (3.3.4)
134143
racc (1.8.1)
135144
rack (2.2.13)
@@ -163,10 +172,12 @@ GEM
163172
rake (>= 12.2)
164173
thor (~> 1.0)
165174
zeitwerk (~> 2.5)
175+
rainbow (3.1.1)
166176
rake (13.2.1)
167177
rb-fsevent (0.11.2)
168178
rb-inotify (0.10.1)
169179
ffi (~> 1.0)
180+
regexp_parser (2.11.3)
170181
rspec-core (3.12.0)
171182
rspec-support (~> 3.12.0)
172183
rspec-expectations (3.12.0)
@@ -184,11 +195,46 @@ GEM
184195
rspec-mocks (~> 3.11)
185196
rspec-support (~> 3.11)
186197
rspec-support (3.12.0)
198+
rubocop (1.81.7)
199+
json (~> 2.3)
200+
language_server-protocol (~> 3.17.0.2)
201+
lint_roller (~> 1.1.0)
202+
parallel (~> 1.10)
203+
parser (>= 3.3.0.2)
204+
rainbow (>= 2.2.2, < 4.0)
205+
regexp_parser (>= 2.9.3, < 3.0)
206+
rubocop-ast (>= 1.47.1, < 2.0)
207+
ruby-progressbar (~> 1.7)
208+
unicode-display_width (>= 2.4.0, < 4.0)
209+
rubocop-ast (1.48.0)
210+
parser (>= 3.3.7.2)
211+
prism (~> 1.4)
212+
rubocop-performance (1.26.1)
213+
lint_roller (~> 1.1)
214+
rubocop (>= 1.75.0, < 2.0)
215+
rubocop-ast (>= 1.47.1, < 2.0)
216+
rubocop-rails (2.34.2)
217+
activesupport (>= 4.2.0)
218+
lint_roller (~> 1.1)
219+
rack (>= 1.1)
220+
rubocop (>= 1.75.0, < 2.0)
221+
rubocop-ast (>= 1.44.0, < 2.0)
222+
rubocop-rails-omakase (1.1.0)
223+
rubocop (>= 1.72)
224+
rubocop-performance (>= 1.24)
225+
rubocop-rails (>= 2.30)
226+
rubocop-rspec (3.8.0)
227+
lint_roller (~> 1.1)
228+
rubocop (~> 1.81)
229+
ruby-progressbar (1.13.0)
187230
ruby2_keywords (0.0.5)
188231
thor (1.3.2)
189232
timeout (0.4.3)
190233
tzinfo (2.0.6)
191234
concurrent-ruby (~> 1.0)
235+
unicode-display_width (3.2.0)
236+
unicode-emoji (~> 4.1)
237+
unicode-emoji (4.1.0)
192238
webrick (1.9.1)
193239
websocket-driver (0.7.7)
194240
base64
@@ -219,6 +265,8 @@ DEPENDENCIES
219265
rack (~> 2.2.13)
220266
rails (~> 7.0.0)
221267
rspec-rails
268+
rubocop-rails-omakase
269+
rubocop-rspec
222270
webrick (~> 1.7)
223271

224272
RUBY VERSION

Rakefile

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
# Add your own tasks in files placed in lib/tasks ending in .rake,
33
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
44

5-
require File.expand_path('../config/application', __FILE__)
5+
require File.expand_path('config/application', __dir__)
66

77
VirtualHostService::Application.load_tasks
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
class ApplicationController < ActionController::API
2-
32
before_action :authorize!
4-
3+
54
protected
6-
5+
76
##
87
# Every Request needs an access token wich authorizes to use the api.
98
# No action will be performed if no access token is specified in the request params.
109
def authorize!
1110
api_key = ApiKey.find_by_access_token(params[:access_token])
1211
head :unauthorized unless api_key
13-
return false
12+
false
1413
end
15-
end
14+
end
Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,37 @@
11
class VHostsController < ApplicationController
2-
32
def create
43
vhost = VHost.new(vhost_params)
54
if vhost.save
6-
render :json => vhost
5+
render json: vhost
76
else
8-
render :json => {:errors => vhost.errors.full_messages}, :status => 422
7+
render json: { errors: vhost.errors.full_messages }, status: :unprocessable_entity
98
end
10-
11-
rescue AMQP::TCPConnectionFailed => ex
12-
render :json => {:errors => ['Could not establish TCP connection to the amqp broker']}, :status => 500
9+
rescue AMQP::TCPConnectionFailed => e
10+
Rails.logger.error(e)
11+
render json: { errors: ['Could not establish TCP connection to the amqp broker'] }, status: :internal_server_error
1312
end
1413

1514
def destroy_by_server_name
16-
17-
vhost = VHost.where(:server_name => params['server_name']).first
15+
vhost = VHost.where(server_name: params['server_name']).first
1816

1917
if vhost.destroy
20-
render :json => 'ok'
18+
render json: 'ok'
2119
else
22-
render :json => {:errors => 'error on deleting vhost'}, :status => 422
20+
render json: { errors: 'error on deleting vhost' }, status: :unprocessable_entity
2321
end
24-
25-
rescue AMQP::TCPConnectionFailed => ex
26-
render :json => {:errors => ['Could not establish TCP connection to the amqp broker']}, :status => 500
22+
rescue AMQP::TCPConnectionFailed => e
23+
Rails.logger.error(e)
24+
render json: { errors: ['Could not establish TCP connection to the amqp broker'] }, status: :internal_server_error
2725
end
2826

2927
def by_organization
30-
render :json => VHost.where(:organization_guid => params['guid'])
28+
render json: VHost.where(organization_guid: params['guid'])
3129
end
3230

3331
private
3432

3533
def vhost_params
36-
params.require(:v_host).permit(:organization_guid, :server_name, :ssl_ca_certificate, :ssl_certificate, :ssl_key, :server_aliases)
34+
params.require(:v_host).permit(:organization_guid, :server_name, :ssl_ca_certificate, :ssl_certificate, :ssl_key,
35+
:server_aliases)
3736
end
38-
3937
end

app/models/api_key.rb

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
1-
##
1+
##
22
# Every client which wants to perform actions through this api needs a API key
33
# otherwise every request will rejektet with a 401 status. API keys can be added
44
# in the application.yml.
55
class ApiKey
6-
76
def initialize(name, access_token)
87
@name = name
98
@access_token = access_token
109
end
11-
10+
1211
def self.find_by_access_token(access_token)
13-
14-
APP_CONFIG['api_keys'].each do |k,v|
12+
APP_CONFIG['api_keys'].each do |k, v|
1513
return ApiKey.new(k, v) if access_token == v
1614
end
17-
18-
return nil
19-
15+
16+
nil
2017
end
2118
end

0 commit comments

Comments
 (0)