legion-data 0.2.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/rubocop-analysis.yml +28 -0
- data/.github/workflows/sourcehawk-scan.yml +20 -0
- data/.gitignore +4 -2
- data/.rubocop.yml +6 -14
- data/CHANGELOG.md +2 -9
- data/CODE_OF_CONDUCT.md +75 -0
- data/CONTRIBUTING.md +55 -0
- data/Gemfile +7 -1
- data/INDIVIDUAL_CONTRIBUTOR_LICENSE.md +30 -0
- data/LICENSE +201 -0
- data/NOTICE.txt +9 -0
- data/README.md +60 -23
- data/SECURITY.md +9 -0
- data/attribution.txt +1 -0
- data/legion-data.gemspec +22 -38
- data/lib/legion/data.rb +18 -21
- data/lib/legion/data/connection.rb +29 -26
- data/lib/legion/data/migration.rb +3 -3
- data/lib/legion/data/migrations/001_add_schema_columns.rb +1 -1
- data/lib/legion/data/migrations/002_add_nodes.rb +20 -0
- data/lib/legion/data/migrations/003_add_settings.rb +18 -0
- data/lib/legion/data/migrations/004_add_extensions.rb +25 -0
- data/lib/legion/data/migrations/005_add_runners.rb +21 -0
- data/lib/legion/data/migrations/006_add_functions.rb +23 -0
- data/lib/legion/data/migrations/007_add_default_extensions.rb +25 -0
- data/lib/legion/data/migrations/008_add_tasks.rb +29 -0
- data/lib/legion/data/model.rb +5 -2
- data/lib/legion/data/models/extension.rb +0 -2
- data/lib/legion/data/models/function.rb +2 -6
- data/lib/legion/data/models/node.rb +1 -3
- data/lib/legion/data/models/runner.rb +0 -2
- data/lib/legion/data/models/setting.rb +0 -0
- data/lib/legion/data/models/task.rb +0 -2
- data/lib/legion/data/models/task_log.rb +0 -0
- data/lib/legion/data/settings.rb +25 -19
- data/lib/legion/data/version.rb +1 -1
- data/sonar-project.properties +12 -0
- data/sourcehawk.yml +4 -0
- metadata +41 -189
- data/.circleci/config.yml +0 -148
- data/.rspec +0 -1
- data/Rakefile +0 -55
- data/bin/console +0 -14
- data/bin/setup +0 -8
- data/bitbucket-pipelines.yml +0 -26
- data/lib/legion/data/connections/base.rb +0 -61
- data/lib/legion/data/connections/jdbc.rb +0 -21
- data/lib/legion/data/connections/mysql.rb +0 -26
- data/lib/legion/data/connections/mysql2.rb +0 -11
- data/lib/legion/data/connections/mysql_base.rb +0 -19
- data/lib/legion/data/migrations/002_add_users.rb +0 -17
- data/lib/legion/data/migrations/003_add_groups.rb +0 -16
- data/lib/legion/data/migrations/004_add_chains.rb +0 -25
- data/lib/legion/data/migrations/005_add_envs.rb +0 -24
- data/lib/legion/data/migrations/006_add_dcs.rb +0 -24
- data/lib/legion/data/migrations/007_add_nodes.rb +0 -26
- data/lib/legion/data/migrations/008_add_settings.rb +0 -18
- data/lib/legion/data/migrations/009_add_extensions.rb +0 -25
- data/lib/legion/data/migrations/010_add_runners.rb +0 -21
- data/lib/legion/data/migrations/011_add_functions.rb +0 -29
- data/lib/legion/data/migrations/012_add_tasks.rb +0 -25
- data/lib/legion/data/migrations/013_add_task_logs.rb +0 -17
- data/lib/legion/data/migrations/014_add_relationships.rb +0 -27
- data/lib/legion/data/models/chain.rb +0 -13
- data/lib/legion/data/models/datacenter.rb +0 -13
- data/lib/legion/data/models/environment.rb +0 -13
- data/lib/legion/data/models/group.rb +0 -10
- data/lib/legion/data/models/namespace.rb +0 -14
- data/lib/legion/data/models/relationship.rb +0 -18
- data/lib/legion/data/models/user.rb +0 -10
data/.circleci/config.yml
DELETED
@@ -1,148 +0,0 @@
|
|
1
|
-
version: 2 # use CircleCI 2.0
|
2
|
-
jobs:
|
3
|
-
"rubocop":
|
4
|
-
docker:
|
5
|
-
- image: circleci/ruby:2.4-node
|
6
|
-
steps:
|
7
|
-
- checkout
|
8
|
-
- run: gem install rubocop
|
9
|
-
- run: bundle install
|
10
|
-
- run:
|
11
|
-
name: Run Rubocop
|
12
|
-
command: rubocop
|
13
|
-
- store_test_results:
|
14
|
-
path: test_results
|
15
|
-
"ruby-2.3":
|
16
|
-
docker:
|
17
|
-
- image: circleci/ruby:2.3
|
18
|
-
- image: mysql:5.7
|
19
|
-
environment:
|
20
|
-
MYSQL_DATABASE: 'legion'
|
21
|
-
MYSQL_ROOT_PASSWORD: 'legion'
|
22
|
-
MYSQL_USER: 'legion'
|
23
|
-
MYSQL_PASSWORD: 'legion'
|
24
|
-
steps:
|
25
|
-
- checkout
|
26
|
-
- run:
|
27
|
-
name: Bundle Install
|
28
|
-
command: bundle install
|
29
|
-
- run:
|
30
|
-
name: Run RSpec
|
31
|
-
command: bundle exec rspec --format progress --format RspecJunitFormatter -o test-results/rspec/results.xml
|
32
|
-
when: always
|
33
|
-
- store_test_results:
|
34
|
-
path: test-results
|
35
|
-
|
36
|
-
"ruby-2.4":
|
37
|
-
docker:
|
38
|
-
- image: circleci/ruby:2.4-node
|
39
|
-
- image: mysql:5.7
|
40
|
-
environment:
|
41
|
-
MYSQL_DATABASE: 'legion'
|
42
|
-
MYSQL_ROOT_PASSWORD: 'legion'
|
43
|
-
MYSQL_USER: 'legion'
|
44
|
-
MYSQL_PASSWORD: 'legion'
|
45
|
-
steps:
|
46
|
-
- checkout
|
47
|
-
- run:
|
48
|
-
name: Bundle Install
|
49
|
-
command: bundle install
|
50
|
-
- run:
|
51
|
-
name: Run RSpec
|
52
|
-
command: bundle exec rspec --format progress --format RspecJunitFormatter -o test-results/rspec/results.xml
|
53
|
-
when: always
|
54
|
-
- store_test_results:
|
55
|
-
path: test-results
|
56
|
-
"ruby-2.5":
|
57
|
-
docker:
|
58
|
-
- image: circleci/ruby:2.5-node
|
59
|
-
- image: mysql:5.7
|
60
|
-
environment:
|
61
|
-
MYSQL_DATABASE: 'legion'
|
62
|
-
MYSQL_ROOT_PASSWORD: 'legion'
|
63
|
-
MYSQL_USER: 'legion'
|
64
|
-
MYSQL_PASSWORD: 'legion'
|
65
|
-
steps:
|
66
|
-
- checkout
|
67
|
-
- run:
|
68
|
-
name: Bundle Install
|
69
|
-
command: bundle install
|
70
|
-
- run:
|
71
|
-
name: Run RSpec
|
72
|
-
command: bundle exec rspec --format progress --format RspecJunitFormatter -o test-results/rspec/results.xml
|
73
|
-
when: always
|
74
|
-
- store_test_results:
|
75
|
-
path: test-results
|
76
|
-
"ruby-2.6":
|
77
|
-
docker:
|
78
|
-
- image: circleci/ruby:2.6-node
|
79
|
-
- image: mysql:5.7
|
80
|
-
environment:
|
81
|
-
MYSQL_DATABASE: 'legion'
|
82
|
-
MYSQL_ROOT_PASSWORD: 'legion'
|
83
|
-
MYSQL_USER: 'legion'
|
84
|
-
MYSQL_PASSWORD: 'legion'
|
85
|
-
steps:
|
86
|
-
- checkout
|
87
|
-
- run:
|
88
|
-
name: Bundle Install
|
89
|
-
command: bundle install
|
90
|
-
- run:
|
91
|
-
name: Run RSpec
|
92
|
-
command: bundle exec rspec --format progress --format RspecJunitFormatter -o test-results/rspec/results.xml
|
93
|
-
when: always
|
94
|
-
- store_test_results:
|
95
|
-
path: test-results
|
96
|
-
"jruby-9.2":
|
97
|
-
docker:
|
98
|
-
- image: circleci/jruby:9.2
|
99
|
-
- image: mysql:5.7
|
100
|
-
environment:
|
101
|
-
MYSQL_DATABASE: 'legion'
|
102
|
-
MYSQL_ROOT_PASSWORD: 'legion'
|
103
|
-
MYSQL_USER: 'legion'
|
104
|
-
MYSQL_PASSWORD: 'legion'
|
105
|
-
steps:
|
106
|
-
- checkout
|
107
|
-
- run:
|
108
|
-
name: Bundle Install
|
109
|
-
command: bundle install
|
110
|
-
- run:
|
111
|
-
name: Run RSpec
|
112
|
-
command: bundle exec rspec --format progress --format RspecJunitFormatter -o test-results/rspec/results.xml
|
113
|
-
when: always
|
114
|
-
- store_test_results:
|
115
|
-
path: test-results
|
116
|
-
|
117
|
-
workflows:
|
118
|
-
version: 2
|
119
|
-
cop_rake_deploy:
|
120
|
-
jobs:
|
121
|
-
- rubocop
|
122
|
-
- ruby-2.3:
|
123
|
-
requires:
|
124
|
-
- ruby-2.4
|
125
|
-
filters:
|
126
|
-
branches:
|
127
|
-
only: /\bdevelop\b|\bmaster\b/
|
128
|
-
- ruby-2.4:
|
129
|
-
requires:
|
130
|
-
- rubocop
|
131
|
-
- ruby-2.5:
|
132
|
-
requires:
|
133
|
-
- ruby-2.4
|
134
|
-
filters:
|
135
|
-
branches:
|
136
|
-
only: /\bdevelop\b|\bmaster\b/
|
137
|
-
- ruby-2.6:
|
138
|
-
requires:
|
139
|
-
- ruby-2.4
|
140
|
-
filters:
|
141
|
-
branches:
|
142
|
-
only: /\bdevelop\b|\bmaster\b/
|
143
|
-
# - jruby-9.2:
|
144
|
-
# requires:
|
145
|
-
# - ruby-2.3
|
146
|
-
# - ruby-2.4
|
147
|
-
# - ruby-2.5
|
148
|
-
# - ruby-2.6
|
data/.rspec
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--color
|
data/Rakefile
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
require 'bundler/gem_tasks'
|
2
|
-
require 'rspec/core/rake_task'
|
3
|
-
require 'rubocop/rake_task'
|
4
|
-
|
5
|
-
RSpec::Core::RakeTask.new(:spec)
|
6
|
-
|
7
|
-
task default: :spec
|
8
|
-
|
9
|
-
task :dev do
|
10
|
-
end
|
11
|
-
|
12
|
-
RuboCop::RakeTask.new(:rubocop) do |t|
|
13
|
-
t.options = ['--display-cop-names']
|
14
|
-
end
|
15
|
-
|
16
|
-
RuboCop::RakeTask.new(:rubocop_fix) do |t|
|
17
|
-
# t.options = ['--display-cop-names -a']
|
18
|
-
t.options = ['--display-cop-names']
|
19
|
-
end
|
20
|
-
|
21
|
-
namespace :db do
|
22
|
-
require 'sequel'
|
23
|
-
require 'legion/logging'
|
24
|
-
Sequel.extension :migration
|
25
|
-
|
26
|
-
# desc 'Prints current schema version'
|
27
|
-
# task :version do
|
28
|
-
# version = DB[:schema_info].first[:version] # if DB.tables.include?(:schema_info) || true
|
29
|
-
#
|
30
|
-
# puts "Schema Version: #{version}"
|
31
|
-
# end
|
32
|
-
#
|
33
|
-
# desc 'Perform migration up to latest migration available'
|
34
|
-
# task :migrate do
|
35
|
-
# Sequel::Migrator.run(DB, 'lib/legion/data/migrations')
|
36
|
-
# Rake::Task['db:version'].execute
|
37
|
-
# end
|
38
|
-
#
|
39
|
-
# desc 'Perform rollback to specified target or full rollback as default'
|
40
|
-
# task :rollback, :target do |_t, args|
|
41
|
-
# args.with_defaults(target: 0)
|
42
|
-
#
|
43
|
-
# Sequel::Migrator.run(DB, 'lib/legion/data/migrations', target: args[:target].to_i)
|
44
|
-
# Rake::Task['db:version'].execute
|
45
|
-
# end
|
46
|
-
#
|
47
|
-
# desc 'Perform migration reset (full rollback and migration)'
|
48
|
-
# task :reset do
|
49
|
-
# Sequel::Migrator.run(DB, 'migrations', target: 0)
|
50
|
-
# Sequel::Migrator.run(DB, 'migrations')
|
51
|
-
# Rake::Task['db:version'].execute
|
52
|
-
# end
|
53
|
-
end
|
54
|
-
|
55
|
-
# RuboCop::RakeTask.new
|
data/bin/console
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'bundler/setup'
|
4
|
-
require 'legion/data'
|
5
|
-
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require 'irb'
|
14
|
-
IRB.start(__FILE__)
|
data/bin/setup
DELETED
data/bitbucket-pipelines.yml
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
image: ruby:2.4.0
|
2
|
-
|
3
|
-
pipelines:
|
4
|
-
branches:
|
5
|
-
master:
|
6
|
-
- step:
|
7
|
-
caches:
|
8
|
-
- bundler
|
9
|
-
script:
|
10
|
-
- gem install bundle rubocop
|
11
|
-
- bundle install
|
12
|
-
- rubocop
|
13
|
-
- rake
|
14
|
-
services:
|
15
|
-
- mysql
|
16
|
-
definitions:
|
17
|
-
services:
|
18
|
-
mysql:
|
19
|
-
image: mysql:5.7
|
20
|
-
environment:
|
21
|
-
MYSQL_DATABASE: 'legion'
|
22
|
-
MYSQL_ROOT_PASSWORD: 'legion'
|
23
|
-
MYSQL_USER: 'legion'
|
24
|
-
MYSQL_PASSWORD: 'legion'
|
25
|
-
caches:
|
26
|
-
bundler: vendor/bundle
|
@@ -1,61 +0,0 @@
|
|
1
|
-
module Legion
|
2
|
-
module Data
|
3
|
-
module Connections
|
4
|
-
class Base
|
5
|
-
attr_reader :sequel
|
6
|
-
def check_gem(gem = adapter)
|
7
|
-
Gem::Specification.find_by_name(gem)
|
8
|
-
rescue Gem::MissingSpecError, ArgumentError
|
9
|
-
false
|
10
|
-
end
|
11
|
-
|
12
|
-
def creds_builder(credentials = {}) # rubocop:disable Metrics/AbcSize
|
13
|
-
creds = {}
|
14
|
-
if Legion::Settings[:vault][:connected] && ::Vault.sys.mounts.key?(:database)
|
15
|
-
creds = Legion::Crypt.read('database/creds/legion')
|
16
|
-
Legion::Logging.info 'Grabbing database creds from vault'
|
17
|
-
end
|
18
|
-
|
19
|
-
creds = creds.merge(default_creds) if creds.is_a? Hash
|
20
|
-
creds = creds.merge(Legion::Settings[:data][:creds]) if Legion::Settings[:data][:creds].is_a? Hash
|
21
|
-
creds = creds.merge(credentials) if credentials.is_a? Hash
|
22
|
-
creds
|
23
|
-
end
|
24
|
-
|
25
|
-
def connect(adapter, creds, _options = {})
|
26
|
-
creds[:adapter] = adapter
|
27
|
-
@sequel = Sequel.connect(creds)
|
28
|
-
end
|
29
|
-
|
30
|
-
def settings(options, _connection = @connection)
|
31
|
-
raise ArgumentError unless options.is_a? Hash
|
32
|
-
end
|
33
|
-
|
34
|
-
def debug_logging(enabled = true, connection = @connection, _options = {})
|
35
|
-
if enabled
|
36
|
-
connection.logger = Legion::Logging
|
37
|
-
connection.sql_log_level = :debug
|
38
|
-
elsif enabled == false
|
39
|
-
connection.logger = nil
|
40
|
-
connection.sql_log_level = :debug
|
41
|
-
end
|
42
|
-
connection
|
43
|
-
end
|
44
|
-
|
45
|
-
def adapter
|
46
|
-
'mysql2'
|
47
|
-
end
|
48
|
-
|
49
|
-
def default_creds
|
50
|
-
{ data: { creds: {
|
51
|
-
host: '127.0.0.1',
|
52
|
-
user: 'legion',
|
53
|
-
password: 'legion',
|
54
|
-
max_connections: 1000,
|
55
|
-
database: 'legion'
|
56
|
-
} } }
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module Legion
|
2
|
-
module Data
|
3
|
-
module Connections
|
4
|
-
class JDBC
|
5
|
-
attr_accessor :connection
|
6
|
-
def initialize
|
7
|
-
Legion::Logging.debug('Connecting to MySQL with JBDC Connector')
|
8
|
-
connection_string = build_connection_string
|
9
|
-
@connection = Sequel.connect(connection_string, max_connetions: @args[:max_connections])
|
10
|
-
Legion::Logging.info("Legion is connected to database #{args[:database]}")
|
11
|
-
end
|
12
|
-
|
13
|
-
def build_connection_string
|
14
|
-
set = Legion::Settings[:data][:mysql]
|
15
|
-
con_string = "jdbc:mysql://#{set[:host]}/#{set[:database]}?user=#{set[:user]}&password=#{set[:password]}"
|
16
|
-
con_string
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'legion/data/connections/mysql_base'
|
2
|
-
|
3
|
-
module Legion
|
4
|
-
module Data
|
5
|
-
module Connections
|
6
|
-
class MySQL < Legion::Data::Connections::MySQLBase
|
7
|
-
attr_accessor :connection
|
8
|
-
def initialize(_options = {})
|
9
|
-
Legion::Logging.debug('Connecting to MySQL with MySQL2 Connector')
|
10
|
-
@connection = connect
|
11
|
-
|
12
|
-
Legion::Logging.info("Legion is connected to database #{Legion::Settings[:data][:mysql][:database]}")
|
13
|
-
Legion::Settings[:data][:connected] = true
|
14
|
-
end
|
15
|
-
|
16
|
-
def adapter
|
17
|
-
'mysql2'
|
18
|
-
end
|
19
|
-
|
20
|
-
def connect
|
21
|
-
super(adapter, creds_builder)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'legion/data/connections/base'
|
2
|
-
|
3
|
-
module Legion
|
4
|
-
module Data
|
5
|
-
module Connections
|
6
|
-
module MySQLBase
|
7
|
-
def default_creds
|
8
|
-
{ data: { mysql: {
|
9
|
-
host: '127.0.0.1',
|
10
|
-
user: 'legion',
|
11
|
-
password: 'legion',
|
12
|
-
max_connections: 100,
|
13
|
-
database: 'legion'
|
14
|
-
} } }
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
Sequel.migration do
|
2
|
-
up do
|
3
|
-
run "CREATE TABLE `users` (
|
4
|
-
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
|
5
|
-
`active` tinyint(1) unsigned DEFAULT '1',
|
6
|
-
`name` varchar(128) DEFAULT NULL,
|
7
|
-
`version` tinyint(5) unsigned NOT NULL DEFAULT '1',
|
8
|
-
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
9
|
-
`updated` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
|
10
|
-
PRIMARY KEY (`id`)
|
11
|
-
) ENGINE=InnoDB DEFAULT CHARSET=utf8;"
|
12
|
-
end
|
13
|
-
|
14
|
-
down do
|
15
|
-
drop :users
|
16
|
-
end
|
17
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
Sequel.migration do
|
2
|
-
up do
|
3
|
-
run "CREATE TABLE `groups` (
|
4
|
-
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
|
5
|
-
`name` varchar(128) DEFAULT NULL,
|
6
|
-
`active` tinyint(1) unsigned DEFAULT '1',
|
7
|
-
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
8
|
-
`updated` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
|
9
|
-
PRIMARY KEY (`id`)
|
10
|
-
) ENGINE=InnoDB DEFAULT CHARSET=utf8;"
|
11
|
-
end
|
12
|
-
|
13
|
-
down do
|
14
|
-
drop :groups
|
15
|
-
end
|
16
|
-
end
|