legion-data 0.2.0 → 1.1.2
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/.circleci/config.yml +95 -72
- data/.gitignore +0 -1
- data/.rubocop.yml +5 -2
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +99 -0
- data/legion-data.gemspec +1 -0
- data/lib/legion/data.rb +10 -13
- data/lib/legion/data/connection.rb +15 -17
- 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_users.rb +1 -1
- data/lib/legion/data/migrations/003_add_groups.rb +1 -1
- data/lib/legion/data/migrations/004_add_chains.rb +1 -1
- data/lib/legion/data/migrations/005_add_envs.rb +1 -1
- data/lib/legion/data/migrations/006_add_dcs.rb +1 -1
- data/lib/legion/data/migrations/007_add_nodes.rb +1 -1
- data/lib/legion/data/migrations/008_add_settings.rb +1 -1
- data/lib/legion/data/migrations/009_add_extensions.rb +1 -1
- data/lib/legion/data/migrations/010_add_runners.rb +1 -1
- data/lib/legion/data/migrations/011_add_functions.rb +1 -1
- data/lib/legion/data/migrations/012_add_tasks.rb +5 -2
- data/lib/legion/data/migrations/013_add_task_logs.rb +8 -2
- data/lib/legion/data/migrations/014_add_relationships.rb +1 -1
- data/lib/legion/data/migrations/015_add_default_extensions.rb +24 -0
- data/lib/legion/data/migrations/016_change_task_args.rb +7 -0
- data/lib/legion/data/migrations/017_add_payload_task.rb +7 -0
- data/lib/legion/data/model.rb +4 -1
- data/lib/legion/data/models/chain.rb +0 -2
- data/lib/legion/data/models/datacenter.rb +0 -2
- data/lib/legion/data/models/environment.rb +0 -2
- data/lib/legion/data/models/extension.rb +0 -2
- data/lib/legion/data/models/function.rb +0 -2
- data/lib/legion/data/models/relationship.rb +0 -2
- data/lib/legion/data/models/runner.rb +0 -2
- data/lib/legion/data/models/task.rb +0 -2
- data/lib/legion/data/settings.rb +14 -8
- data/lib/legion/data/version.rb +1 -1
- data/sonar-project.properties +12 -0
- metadata +12 -13
- 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/models/namespace.rb +0 -14
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 7edc1b56e433f1136ad04bb1ddb6c989493a516bc46ca928fe81439428616fd1
         | 
| 4 | 
            +
              data.tar.gz: 2d67b54b7de9c5aa798e941cd700381df89ef87fda8fcbd272aacb017a6af1da
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 224c4962335f385131dc6e50fe9ffe952edb4e52a0c6f3b7cdc30164cc6b668de1a9ab37778c097a0e9c790430ef62ba26af70ff2e88352a4cadf32abf35b3f9
         | 
| 7 | 
            +
              data.tar.gz: da68881cbdcaa3b021e523064f0a9d784702d69cc98c713ed7f76b24ca994eef2295d77e6e6425f093bd68e0e9cac1139a40ff7d18cf4839b4ab1dfac6cde8f1
         | 
    
        data/.circleci/config.yml
    CHANGED
    
    | @@ -1,21 +1,24 @@ | |
| 1 | 
            -
            version: 2 | 
| 1 | 
            +
            version: 2.1
         | 
| 2 | 
            +
            orbs:
         | 
| 3 | 
            +
              ruby: circleci/ruby@0.2.1
         | 
| 4 | 
            +
              sonarcloud: sonarsource/sonarcloud@1.0.1
         | 
| 5 | 
            +
             | 
| 2 6 | 
             
            jobs:
         | 
| 3 7 | 
             
              "rubocop":
         | 
| 4 8 | 
             
                docker:
         | 
| 5 | 
            -
                  - image: circleci/ruby:2. | 
| 9 | 
            +
                  - image: circleci/ruby:2.7-node
         | 
| 6 10 | 
             
                steps:
         | 
| 7 11 | 
             
                  - checkout
         | 
| 8 | 
            -
                  -  | 
| 9 | 
            -
                  -  | 
| 12 | 
            +
                  - ruby/load-cache
         | 
| 13 | 
            +
                  - ruby/install-deps
         | 
| 10 14 | 
             
                  - run:
         | 
| 11 15 | 
             
                      name: Run Rubocop
         | 
| 12 | 
            -
                      command: rubocop
         | 
| 13 | 
            -
                  -  | 
| 14 | 
            -
             | 
| 15 | 
            -
              "ruby-2.3":
         | 
| 16 | 
            +
                      command: bundle exec rubocop
         | 
| 17 | 
            +
                  - ruby/save-cache
         | 
| 18 | 
            +
              "ruby-two-five":
         | 
| 16 19 | 
             
                docker:
         | 
| 17 | 
            -
                  - image: circleci/ruby:2. | 
| 18 | 
            -
                  - image: mysql:5.7
         | 
| 20 | 
            +
                  - image: circleci/ruby:2.5
         | 
| 21 | 
            +
                  - image: circleci/mysql:5.7
         | 
| 19 22 | 
             
                    environment:
         | 
| 20 23 | 
             
                      MYSQL_DATABASE: 'legion'
         | 
| 21 24 | 
             
                      MYSQL_ROOT_PASSWORD: 'legion'
         | 
| @@ -23,20 +26,20 @@ jobs: | |
| 23 26 | 
             
                      MYSQL_PASSWORD: 'legion'
         | 
| 24 27 | 
             
                steps:
         | 
| 25 28 | 
             
                  - checkout
         | 
| 29 | 
            +
                  - ruby/load-cache
         | 
| 26 30 | 
             
                  - run:
         | 
| 27 | 
            -
                      name:  | 
| 28 | 
            -
                      command:  | 
| 31 | 
            +
                      name: update bundler
         | 
| 32 | 
            +
                      command: gem update bundler
         | 
| 33 | 
            +
                  - ruby/install-deps
         | 
| 29 34 | 
             
                  - run:
         | 
| 30 | 
            -
                      name:  | 
| 31 | 
            -
                      command:  | 
| 32 | 
            -
             | 
| 33 | 
            -
                  -  | 
| 34 | 
            -
             | 
| 35 | 
            -
             | 
| 36 | 
            -
              "ruby-2.4":
         | 
| 35 | 
            +
                      name: update max connections
         | 
| 36 | 
            +
                      command: 'sudo apt-get install default-mysql-client && mysql -h 127.0.0.1 -u root --password=legion --execute="set global max_connections = 100000;"'
         | 
| 37 | 
            +
                  - ruby/run-tests
         | 
| 38 | 
            +
                  - ruby/save-cache
         | 
| 39 | 
            +
              "ruby-two-six":
         | 
| 37 40 | 
             
                docker:
         | 
| 38 | 
            -
                  - image: circleci/ruby:2. | 
| 39 | 
            -
                  - image: mysql:5.7
         | 
| 41 | 
            +
                  - image: circleci/ruby:2.6
         | 
| 42 | 
            +
                  - image: circleci/mysql:5.7
         | 
| 40 43 | 
             
                    environment:
         | 
| 41 44 | 
             
                      MYSQL_DATABASE: 'legion'
         | 
| 42 45 | 
             
                      MYSQL_ROOT_PASSWORD: 'legion'
         | 
| @@ -44,19 +47,38 @@ jobs: | |
| 44 47 | 
             
                      MYSQL_PASSWORD: 'legion'
         | 
| 45 48 | 
             
                steps:
         | 
| 46 49 | 
             
                  - checkout
         | 
| 50 | 
            +
                  - ruby/load-cache
         | 
| 47 51 | 
             
                  - run:
         | 
| 48 | 
            -
                      name:  | 
| 49 | 
            -
                      command:  | 
| 52 | 
            +
                      name: update bundler
         | 
| 53 | 
            +
                      command: gem update bundler
         | 
| 54 | 
            +
                  - ruby/install-deps
         | 
| 50 55 | 
             
                  - run:
         | 
| 51 | 
            -
                      name:  | 
| 52 | 
            -
                      command:  | 
| 53 | 
            -
             | 
| 54 | 
            -
                  -  | 
| 55 | 
            -
             | 
| 56 | 
            -
             | 
| 56 | 
            +
                      name: update max connections
         | 
| 57 | 
            +
                      command: 'sudo apt-get install default-mysql-client && mysql -h 127.0.0.1 -u root --password=legion --execute="set global max_connections = 100000;"'
         | 
| 58 | 
            +
                  - ruby/run-tests
         | 
| 59 | 
            +
                  - ruby/save-cache
         | 
| 60 | 
            +
              "ruby-two-seven":
         | 
| 61 | 
            +
                docker:
         | 
| 62 | 
            +
                  - image: circleci/ruby:2.7
         | 
| 63 | 
            +
                  - image: circleci/mysql:5.7
         | 
| 64 | 
            +
                    environment:
         | 
| 65 | 
            +
                      MYSQL_DATABASE: 'legion'
         | 
| 66 | 
            +
                      MYSQL_ROOT_PASSWORD: 'legion'
         | 
| 67 | 
            +
                      MYSQL_USER: 'legion'
         | 
| 68 | 
            +
                      MYSQL_PASSWORD: 'legion'
         | 
| 69 | 
            +
                steps:
         | 
| 70 | 
            +
                  - checkout
         | 
| 71 | 
            +
                  - ruby/load-cache
         | 
| 72 | 
            +
                  - ruby/install-deps
         | 
| 73 | 
            +
                  - run:
         | 
| 74 | 
            +
                      name: update max connections
         | 
| 75 | 
            +
                      command: 'sudo apt-get install default-mysql-client && mysql -h 127.0.0.1 -u root --password=legion --execute="set global max_connections = 100000;"'
         | 
| 76 | 
            +
                  - ruby/run-tests
         | 
| 77 | 
            +
                  - ruby/save-cache
         | 
| 78 | 
            +
              "jruby-nine-two":
         | 
| 57 79 | 
             
                docker:
         | 
| 58 | 
            -
                  - image: circleci/ | 
| 59 | 
            -
                  - image: mysql:5.7
         | 
| 80 | 
            +
                  - image: circleci/jruby:9.2-jre
         | 
| 81 | 
            +
                  - image: circleci/mysql:5.7
         | 
| 60 82 | 
             
                    environment:
         | 
| 61 83 | 
             
                      MYSQL_DATABASE: 'legion'
         | 
| 62 84 | 
             
                      MYSQL_ROOT_PASSWORD: 'legion'
         | 
| @@ -67,16 +89,18 @@ jobs: | |
| 67 89 | 
             
                  - run:
         | 
| 68 90 | 
             
                      name: Bundle Install
         | 
| 69 91 | 
             
                      command: bundle install
         | 
| 92 | 
            +
                  - run:
         | 
| 93 | 
            +
                      name: update max connections
         | 
| 94 | 
            +
                      command: 'sudo apt-get install default-mysql-client && mysql -h 127.0.0.1 -u root --password=legion --execute="set global max_connections = 100000;"'
         | 
| 70 95 | 
             
                  - run:
         | 
| 71 96 | 
             
                      name: Run RSpec
         | 
| 72 97 | 
             
                      command: bundle exec rspec --format progress --format RspecJunitFormatter -o test-results/rspec/results.xml
         | 
| 73 98 | 
             
                      when: always
         | 
| 74 | 
            -
                  -  | 
| 75 | 
            -
             | 
| 76 | 
            -
              "ruby-2.6":
         | 
| 99 | 
            +
                  - sonarcloud/scan
         | 
| 100 | 
            +
              "jruby-nine-two-e":
         | 
| 77 101 | 
             
                docker:
         | 
| 78 | 
            -
                  - image: circleci/ | 
| 79 | 
            -
                  - image: mysql:5.7
         | 
| 102 | 
            +
                  - image: circleci/jruby:9.2.11-jre
         | 
| 103 | 
            +
                  - image: circleci/mysql:5.7
         | 
| 80 104 | 
             
                    environment:
         | 
| 81 105 | 
             
                      MYSQL_DATABASE: 'legion'
         | 
| 82 106 | 
             
                      MYSQL_ROOT_PASSWORD: 'legion'
         | 
| @@ -87,16 +111,17 @@ jobs: | |
| 87 111 | 
             
                  - run:
         | 
| 88 112 | 
             
                      name: Bundle Install
         | 
| 89 113 | 
             
                      command: bundle install
         | 
| 114 | 
            +
                  - run:
         | 
| 115 | 
            +
                      name: update max connections
         | 
| 116 | 
            +
                      command: 'sudo apt-get install default-mysql-client && mysql -h 127.0.0.1 -u root --password=legion --execute="set global max_connections = 100000;"'
         | 
| 90 117 | 
             
                  - run:
         | 
| 91 118 | 
             
                      name: Run RSpec
         | 
| 92 119 | 
             
                      command: bundle exec rspec --format progress --format RspecJunitFormatter -o test-results/rspec/results.xml
         | 
| 93 120 | 
             
                      when: always
         | 
| 94 | 
            -
             | 
| 95 | 
            -
                      path: test-results
         | 
| 96 | 
            -
              "jruby-9.2":
         | 
| 121 | 
            +
              "sonarcloud":
         | 
| 97 122 | 
             
                docker:
         | 
| 98 | 
            -
                  - image: circleci/ | 
| 99 | 
            -
                  - image: mysql:5.7
         | 
| 123 | 
            +
                  - image: circleci/ruby:2.7
         | 
| 124 | 
            +
                  - image: circleci/mysql:5.7
         | 
| 100 125 | 
             
                    environment:
         | 
| 101 126 | 
             
                      MYSQL_DATABASE: 'legion'
         | 
| 102 127 | 
             
                      MYSQL_ROOT_PASSWORD: 'legion'
         | 
| @@ -104,45 +129,43 @@ jobs: | |
| 104 129 | 
             
                      MYSQL_PASSWORD: 'legion'
         | 
| 105 130 | 
             
                steps:
         | 
| 106 131 | 
             
                  - checkout
         | 
| 132 | 
            +
                  - ruby/load-cache
         | 
| 107 133 | 
             
                  - run:
         | 
| 108 | 
            -
                      name:  | 
| 109 | 
            -
                      command:  | 
| 134 | 
            +
                      name: update bundler
         | 
| 135 | 
            +
                      command: gem update bundler
         | 
| 136 | 
            +
                  - ruby/install-deps
         | 
| 110 137 | 
             
                  - run:
         | 
| 111 | 
            -
                      name:  | 
| 112 | 
            -
                      command:  | 
| 113 | 
            -
             | 
| 114 | 
            -
                  -  | 
| 115 | 
            -
                       | 
| 138 | 
            +
                      name: update max connections
         | 
| 139 | 
            +
                      command: 'sudo apt-get install default-mysql-client && mysql -h 127.0.0.1 -u root --password=legion --execute="set global max_connections = 100000;"'
         | 
| 140 | 
            +
                  - ruby/run-tests
         | 
| 141 | 
            +
                  - run:
         | 
| 142 | 
            +
                      name: Run Rubocop
         | 
| 143 | 
            +
                      command: bundle exec rubocop --format=json --out=rubocop-result.json
         | 
| 144 | 
            +
                  - sonarcloud/scan
         | 
| 145 | 
            +
                  - ruby/save-cache
         | 
| 116 146 |  | 
| 117 147 | 
             
            workflows:
         | 
| 118 148 | 
             
              version: 2
         | 
| 119 | 
            -
               | 
| 149 | 
            +
              rubocop-rspec:
         | 
| 120 150 | 
             
                jobs:
         | 
| 121 151 | 
             
                  - rubocop
         | 
| 122 | 
            -
                  - ruby- | 
| 123 | 
            -
                      requires:
         | 
| 124 | 
            -
                        - ruby-2.4
         | 
| 125 | 
            -
                      filters:
         | 
| 126 | 
            -
                        branches:
         | 
| 127 | 
            -
                          only: /\bdevelop\b|\bmaster\b/
         | 
| 128 | 
            -
                  - ruby-2.4:
         | 
| 152 | 
            +
                  - ruby-two-five:
         | 
| 129 153 | 
             
                      requires:
         | 
| 130 154 | 
             
                        - rubocop
         | 
| 131 | 
            -
                  - ruby- | 
| 155 | 
            +
                  - ruby-two-six:
         | 
| 156 | 
            +
                      requires:
         | 
| 157 | 
            +
                        - ruby-two-five
         | 
| 158 | 
            +
                  - ruby-two-seven:
         | 
| 159 | 
            +
                      requires:
         | 
| 160 | 
            +
                        - ruby-two-five
         | 
| 161 | 
            +
                  - sonarcloud:
         | 
| 162 | 
            +
                      requires:
         | 
| 163 | 
            +
                        - ruby-two-seven
         | 
| 164 | 
            +
                        - ruby-two-six
         | 
| 165 | 
            +
                  - jruby-nine-two:
         | 
| 132 166 | 
             
                      requires:
         | 
| 133 | 
            -
                        - ruby- | 
| 134 | 
            -
             | 
| 135 | 
            -
             | 
| 136 | 
            -
                          only: /\bdevelop\b|\bmaster\b/
         | 
| 137 | 
            -
                  - ruby-2.6:
         | 
| 167 | 
            +
                        - ruby-two-seven
         | 
| 168 | 
            +
                        - ruby-two-six
         | 
| 169 | 
            +
                  - jruby-nine-two-e:
         | 
| 138 170 | 
             
                      requires:
         | 
| 139 | 
            -
                        -  | 
| 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
         | 
| 171 | 
            +
                        - jruby-nine-two
         | 
    
        data/.gitignore
    CHANGED
    
    
    
        data/.rubocop.yml
    CHANGED
    
    | @@ -3,7 +3,7 @@ require: | |
| 3 3 | 
             
              - rubocop-md
         | 
| 4 4 | 
             
              - rubocop-performance
         | 
| 5 5 |  | 
| 6 | 
            -
             | 
| 6 | 
            +
            Layout/LineLength:
         | 
| 7 7 | 
             
              Max: 120
         | 
| 8 8 | 
             
              Exclude:
         | 
| 9 9 | 
             
                - 'lib/legion/data/migrations/*.rb'
         | 
| @@ -11,6 +11,8 @@ Metrics/MethodLength: | |
| 11 11 | 
             
              Max: 30
         | 
| 12 12 | 
             
            Metrics/ClassLength:
         | 
| 13 13 | 
             
              Max: 1500
         | 
| 14 | 
            +
            Metrics/AbcSize:
         | 
| 15 | 
            +
              Max: 34
         | 
| 14 16 | 
             
            Metrics/BlockLength:
         | 
| 15 17 | 
             
              Max: 50
         | 
| 16 18 | 
             
              Exclude:
         | 
| @@ -25,6 +27,7 @@ Layout/HashAlignment: | |
| 25 27 | 
             
            Style/Documentation:
         | 
| 26 28 | 
             
              Enabled: false
         | 
| 27 29 | 
             
            AllCops:
         | 
| 28 | 
            -
              TargetRubyVersion: 2. | 
| 30 | 
            +
              TargetRubyVersion: 2.5
         | 
| 31 | 
            +
              NewCops: enable
         | 
| 29 32 | 
             
            Style/FrozenStringLiteralComment:
         | 
| 30 33 | 
             
              Enabled: false
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    
    
        data/Gemfile.lock
    ADDED
    
    | @@ -0,0 +1,99 @@ | |
| 1 | 
            +
            PATH
         | 
| 2 | 
            +
              remote: .
         | 
| 3 | 
            +
              specs:
         | 
| 4 | 
            +
                legion-data (1.1.2)
         | 
| 5 | 
            +
                  legion-logging
         | 
| 6 | 
            +
                  legion-settings
         | 
| 7 | 
            +
                  mysql2
         | 
| 8 | 
            +
                  sequel
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            GEM
         | 
| 11 | 
            +
              remote: https://rubygems.org/
         | 
| 12 | 
            +
              specs:
         | 
| 13 | 
            +
                ast (2.4.1)
         | 
| 14 | 
            +
                codecov (0.2.8)
         | 
| 15 | 
            +
                  json
         | 
| 16 | 
            +
                  simplecov
         | 
| 17 | 
            +
                diff-lcs (1.4.4)
         | 
| 18 | 
            +
                docile (1.3.2)
         | 
| 19 | 
            +
                json (2.3.1)
         | 
| 20 | 
            +
                json (2.3.1-java)
         | 
| 21 | 
            +
                json_pure (2.3.1)
         | 
| 22 | 
            +
                legion-json (1.1.2)
         | 
| 23 | 
            +
                  json_pure
         | 
| 24 | 
            +
                  multi_json
         | 
| 25 | 
            +
                legion-logging (1.1.0)
         | 
| 26 | 
            +
                  rainbow (~> 3)
         | 
| 27 | 
            +
                legion-settings (1.1.1)
         | 
| 28 | 
            +
                  legion-json
         | 
| 29 | 
            +
                  legion-logging
         | 
| 30 | 
            +
                multi_json (1.15.0)
         | 
| 31 | 
            +
                mysql2 (0.5.3)
         | 
| 32 | 
            +
                parallel (1.19.2)
         | 
| 33 | 
            +
                parser (2.7.1.4)
         | 
| 34 | 
            +
                  ast (~> 2.4.1)
         | 
| 35 | 
            +
                rainbow (3.0.0)
         | 
| 36 | 
            +
                rake (13.0.1)
         | 
| 37 | 
            +
                regexp_parser (1.7.1)
         | 
| 38 | 
            +
                rexml (3.2.4)
         | 
| 39 | 
            +
                rspec (3.9.0)
         | 
| 40 | 
            +
                  rspec-core (~> 3.9.0)
         | 
| 41 | 
            +
                  rspec-expectations (~> 3.9.0)
         | 
| 42 | 
            +
                  rspec-mocks (~> 3.9.0)
         | 
| 43 | 
            +
                rspec-core (3.9.2)
         | 
| 44 | 
            +
                  rspec-support (~> 3.9.3)
         | 
| 45 | 
            +
                rspec-expectations (3.9.2)
         | 
| 46 | 
            +
                  diff-lcs (>= 1.2.0, < 2.0)
         | 
| 47 | 
            +
                  rspec-support (~> 3.9.0)
         | 
| 48 | 
            +
                rspec-mocks (3.9.1)
         | 
| 49 | 
            +
                  diff-lcs (>= 1.2.0, < 2.0)
         | 
| 50 | 
            +
                  rspec-support (~> 3.9.0)
         | 
| 51 | 
            +
                rspec-support (3.9.3)
         | 
| 52 | 
            +
                rspec_junit_formatter (0.4.1)
         | 
| 53 | 
            +
                  rspec-core (>= 2, < 4, != 2.12.0)
         | 
| 54 | 
            +
                rubocop (0.89.1)
         | 
| 55 | 
            +
                  parallel (~> 1.10)
         | 
| 56 | 
            +
                  parser (>= 2.7.1.1)
         | 
| 57 | 
            +
                  rainbow (>= 2.2.2, < 4.0)
         | 
| 58 | 
            +
                  regexp_parser (>= 1.7)
         | 
| 59 | 
            +
                  rexml
         | 
| 60 | 
            +
                  rubocop-ast (>= 0.3.0, < 1.0)
         | 
| 61 | 
            +
                  ruby-progressbar (~> 1.7)
         | 
| 62 | 
            +
                  unicode-display_width (>= 1.4.0, < 2.0)
         | 
| 63 | 
            +
                rubocop-ast (0.3.0)
         | 
| 64 | 
            +
                  parser (>= 2.7.1.4)
         | 
| 65 | 
            +
                rubocop-md (0.4.0)
         | 
| 66 | 
            +
                  rubocop (~> 0.60)
         | 
| 67 | 
            +
                rubocop-performance (1.7.1)
         | 
| 68 | 
            +
                  rubocop (>= 0.82.0)
         | 
| 69 | 
            +
                rubocop-rspec (1.43.2)
         | 
| 70 | 
            +
                  rubocop (~> 0.87)
         | 
| 71 | 
            +
                rubocop-sequel (0.0.6)
         | 
| 72 | 
            +
                  rubocop (~> 0.55, >= 0.55)
         | 
| 73 | 
            +
                ruby-progressbar (1.10.1)
         | 
| 74 | 
            +
                sequel (5.35.0)
         | 
| 75 | 
            +
                simplecov (0.19.0)
         | 
| 76 | 
            +
                  docile (~> 1.1)
         | 
| 77 | 
            +
                  simplecov-html (~> 0.11)
         | 
| 78 | 
            +
                simplecov-html (0.12.2)
         | 
| 79 | 
            +
                unicode-display_width (1.7.0)
         | 
| 80 | 
            +
             | 
| 81 | 
            +
            PLATFORMS
         | 
| 82 | 
            +
              java
         | 
| 83 | 
            +
              ruby
         | 
| 84 | 
            +
             | 
| 85 | 
            +
            DEPENDENCIES
         | 
| 86 | 
            +
              bundler
         | 
| 87 | 
            +
              codecov
         | 
| 88 | 
            +
              legion-data!
         | 
| 89 | 
            +
              rake
         | 
| 90 | 
            +
              rspec
         | 
| 91 | 
            +
              rspec_junit_formatter
         | 
| 92 | 
            +
              rubocop
         | 
| 93 | 
            +
              rubocop-md
         | 
| 94 | 
            +
              rubocop-performance
         | 
| 95 | 
            +
              rubocop-rspec
         | 
| 96 | 
            +
              rubocop-sequel
         | 
| 97 | 
            +
             | 
| 98 | 
            +
            BUNDLED WITH
         | 
| 99 | 
            +
               2.1.4
         | 
    
        data/legion-data.gemspec
    CHANGED
    
    | @@ -11,6 +11,7 @@ Gem::Specification.new do |spec| | |
| 11 11 | 
             
              spec.summary       = 'Used by Legion to connect to the database'
         | 
| 12 12 | 
             
              spec.description   = 'The Legion connect gem'
         | 
| 13 13 | 
             
              spec.homepage = 'https://bitbucket.org/legion-io/legion-data'
         | 
| 14 | 
            +
              spec.required_ruby_version = Gem::Requirement.new('>= 2.5.0')
         | 
| 14 15 |  | 
| 15 16 | 
             
              spec.metadata['bug_tracker_uri'] = 'https://bitbucket.org/legion-io/legion-data/issues?status=new&status=open'
         | 
| 16 17 | 
             
              spec.metadata['changelog_uri'] = 'https://bitbucket.org/legion-io/legion-data/src/CHANGELOG.md'
         | 
    
        data/lib/legion/data.rb
    CHANGED
    
    | @@ -1,10 +1,10 @@ | |
| 1 1 | 
             
            require 'legion/data/version'
         | 
| 2 | 
            -
             | 
| 2 | 
            +
            require 'legion/data/settings'
         | 
| 3 3 | 
             
            require 'sequel'
         | 
| 4 4 |  | 
| 5 | 
            -
             | 
| 6 | 
            -
             | 
| 7 | 
            -
             | 
| 5 | 
            +
            require 'legion/data/connection'
         | 
| 6 | 
            +
            require 'legion/data/model'
         | 
| 7 | 
            +
            require 'legion/data/migration'
         | 
| 8 8 |  | 
| 9 9 | 
             
            module Legion
         | 
| 10 10 | 
             
              module Data
         | 
| @@ -13,7 +13,7 @@ module Legion | |
| 13 13 | 
             
                    connection_setup
         | 
| 14 14 | 
             
                    migrate
         | 
| 15 15 | 
             
                    load_models
         | 
| 16 | 
            -
                     | 
| 16 | 
            +
                    setup_cache
         | 
| 17 17 | 
             
                  end
         | 
| 18 18 |  | 
| 19 19 | 
             
                  def connection_setup
         | 
| @@ -34,20 +34,17 @@ module Legion | |
| 34 34 | 
             
                    Legion::Data::Connection.sequel
         | 
| 35 35 | 
             
                  end
         | 
| 36 36 |  | 
| 37 | 
            -
                  def setup_cache | 
| 38 | 
            -
                    return if Legion::Settings[:data][:cache][: | 
| 37 | 
            +
                  def setup_cache
         | 
| 38 | 
            +
                    return if Legion::Settings[:data][:cache][:enabled]
         | 
| 39 39 |  | 
| 40 | 
            -
                    unless Legion:: | 
| 41 | 
            -
                      Legion::Logging.warn 'Legion::Data has caching enabled but Legion::Cache is not started'
         | 
| 42 | 
            -
                    end
         | 
| 43 | 
            -
                    return unless Legion::Settings[:cache][:connected]
         | 
| 40 | 
            +
                    return unless defined?(::Legion::Cache)
         | 
| 44 41 |  | 
| 45 | 
            -
                     | 
| 42 | 
            +
                    Legion::Data::Model::Relationship.plugin :caching, Legion::Cache, ttl: 10
         | 
| 46 43 | 
             
                    Legion::Data::Model::Chain.plugin :caching, Legion::Cache, ttl: 60
         | 
| 47 44 | 
             
                    Legion::Data::Model::Datacenter.plugin :caching, Legion::Cache, ttl: 120
         | 
| 48 45 | 
             
                    Legion::Data::Model::Extension.plugin :caching, Legion::Cache, ttl: 120
         | 
| 49 46 | 
             
                    Legion::Data::Model::Function.plugin :caching, Legion::Cache, ttl: 120
         | 
| 50 | 
            -
                    Legion::Data::Model:: | 
| 47 | 
            +
                    Legion::Data::Model::Extension.plugin :caching, Legion::Cache, ttl: 120
         | 
| 51 48 | 
             
                    Legion::Data::Model::Node.plugin :caching, Legion::Cache, ttl: 10
         | 
| 52 49 | 
             
                    Legion::Data::Model::TaskLog.plugin :caching, Legion::Cache, ttl: 12
         | 
| 53 50 | 
             
                    Legion::Data::Model::Task.plugin :caching, Legion::Cache, ttl: 10
         | 
| @@ -4,33 +4,35 @@ module Legion | |
| 4 4 | 
             
              module Data
         | 
| 5 5 | 
             
                module Connection
         | 
| 6 6 | 
             
                  class << self
         | 
| 7 | 
            -
                     | 
| 8 | 
            -
             | 
| 9 | 
            -
             | 
| 10 | 
            -
                       | 
| 11 | 
            -
                    else
         | 
| 12 | 
            -
                      require_relative 'connections/mysql2'
         | 
| 13 | 
            -
                      include Legion::Data::Connections::MySQL2
         | 
| 7 | 
            +
                    attr_accessor :sequel
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                    def adapter
         | 
| 10 | 
            +
                      @adapter ||= RUBY_ENGINE == 'jruby' ? :jdbc : :mysql2
         | 
| 14 11 | 
             
                    end
         | 
| 15 12 |  | 
| 16 13 | 
             
                    def setup
         | 
| 17 | 
            -
                      @sequel =  | 
| 14 | 
            +
                      @sequel = if adapter == :mysql2
         | 
| 15 | 
            +
                                  ::Sequel.connect(adapter: adapter, **creds_builder)
         | 
| 16 | 
            +
                                else
         | 
| 17 | 
            +
                                  ::Sequel.connect("jdbc:mysql://#{creds_builder[:host]}:#{creds_builder[:port]}/#{creds_builder[:database]}?user=#{creds_builder[:username]}&password=#{creds_builder[:password]}&serverTimezone=UTC") # rubocop:disable Layout/LineLength
         | 
| 18 | 
            +
                                end
         | 
| 18 19 | 
             
                      Legion::Settings[:data][:connected] = true
         | 
| 19 | 
            -
                      return  | 
| 20 | 
            +
                      return if Legion::Settings[:data][:connection].nil? || Legion::Settings[:data][:connection][:log].nil?
         | 
| 20 21 |  | 
| 21 | 
            -
                      @sequel.logger = Legion::Logging | 
| 22 | 
            +
                      @sequel.logger = Legion::Logging
         | 
| 22 23 | 
             
                      @sequel.sql_log_level = Legion::Settings[:data][:connection][:sql_log_level]
         | 
| 23 24 | 
             
                      @sequel.log_warn_duration = Legion::Settings[:data][:connection][:log_warn_duration]
         | 
| 24 25 | 
             
                    end
         | 
| 25 26 |  | 
| 26 27 | 
             
                    def shutdown
         | 
| 27 | 
            -
                      @sequel | 
| 28 | 
            +
                      @sequel&.disconnect
         | 
| 29 | 
            +
                      Legion::Settings[:data][:connected] = false
         | 
| 28 30 | 
             
                    end
         | 
| 29 31 |  | 
| 30 | 
            -
                    def creds_builder | 
| 32 | 
            +
                    def creds_builder
         | 
| 31 33 | 
             
                      final_creds = {}
         | 
| 32 34 | 
             
                      final_creds.merge! default_creds
         | 
| 33 | 
            -
                      final_creds.merge! Legion::Settings[:data][:creds]
         | 
| 35 | 
            +
                      final_creds.merge! Legion::Settings[:data][:creds] if Legion::Settings[:data][:creds].is_a? Hash
         | 
| 34 36 | 
             
                      return final_creds if Legion::Settings[:vault].nil?
         | 
| 35 37 |  | 
| 36 38 | 
             
                      if Legion::Settings[:vault][:connected] && ::Vault.sys.mounts.key?(:database)
         | 
| @@ -53,10 +55,6 @@ module Legion | |
| 53 55 | 
             
                        preconnect:      'concurrently'
         | 
| 54 56 | 
             
                      }
         | 
| 55 57 | 
             
                    end
         | 
| 56 | 
            -
             | 
| 57 | 
            -
                    def adapter
         | 
| 58 | 
            -
                      'mysql2'
         | 
| 59 | 
            -
                    end
         | 
| 60 58 | 
             
                  end
         | 
| 61 59 | 
             
                end
         | 
| 62 60 | 
             
              end
         | 
| @@ -4,9 +4,9 @@ module Legion | |
| 4 4 | 
             
              module Data
         | 
| 5 5 | 
             
                module Migration
         | 
| 6 6 | 
             
                  class << self
         | 
| 7 | 
            -
                    def migrate(connection = Legion::Data.connection, path = __dir__ | 
| 8 | 
            -
                      Legion::Settings[:data][:migrations][:version] = Sequel::Migrator.run(connection, path)
         | 
| 9 | 
            -
                      Legion::Logging.info | 
| 7 | 
            +
                    def migrate(connection = Legion::Data.connection, path = "#{__dir__}/migrations", **opts)
         | 
| 8 | 
            +
                      Legion::Settings[:data][:migrations][:version] = Sequel::Migrator.run(connection, path, **opts)
         | 
| 9 | 
            +
                      Legion::Logging.info("Legion::Data::Migration ran successfully to version #{Legion::Settings[:data][:migrations][:version]}") # rubocop:disable Layout/LineLength
         | 
| 10 10 | 
             
                      Legion::Settings[:data][:migrations][:ran] = true
         | 
| 11 11 | 
             
                    end
         | 
| 12 12 | 
             
                  end
         | 
| @@ -2,7 +2,8 @@ Sequel.migration do | |
| 2 2 | 
             
              up do
         | 
| 3 3 | 
             
                run "CREATE TABLE `tasks` (
         | 
| 4 4 | 
             
              `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
         | 
| 5 | 
            -
              `relationship_id` int(11) unsigned  | 
| 5 | 
            +
              `relationship_id` int(11) unsigned DEFAULT NULL,
         | 
| 6 | 
            +
              `function_id` int(11) unsigned DEFAULT NULL,
         | 
| 6 7 | 
             
              `status` varchar(255) NOT NULL,
         | 
| 7 8 | 
             
              `parent_id` int(11) unsigned DEFAULT NULL,
         | 
| 8 9 | 
             
              `master_id` int(11) unsigned DEFAULT NULL,
         | 
| @@ -14,12 +15,14 @@ Sequel.migration do | |
| 14 15 | 
             
              KEY `status` (`status`),
         | 
| 15 16 | 
             
              KEY `parent_id` (`parent_id`),
         | 
| 16 17 | 
             
              KEY `master_id` (`master_id`),
         | 
| 18 | 
            +
              KEY `relationship_id` (`relationship_id`),
         | 
| 19 | 
            +
              KEY `function_id` (`function_id`),
         | 
| 17 20 | 
             
              CONSTRAINT `parent_id` FOREIGN KEY (`parent_id`) REFERENCES `tasks` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
         | 
| 18 21 | 
             
              CONSTRAINT `master_id` FOREIGN KEY (`master_id`) REFERENCES `tasks` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
         | 
| 19 22 | 
             
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"
         | 
| 20 23 | 
             
              end
         | 
| 21 24 |  | 
| 22 25 | 
             
              down do
         | 
| 23 | 
            -
                 | 
| 26 | 
            +
                drop_table :tasks
         | 
| 24 27 | 
             
              end
         | 
| 25 28 | 
             
            end
         | 
| @@ -3,15 +3,21 @@ Sequel.migration do | |
| 3 3 | 
             
                run "CREATE TABLE `task_logs` (
         | 
| 4 4 | 
             
              `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
         | 
| 5 5 | 
             
              `task_id` int(11) unsigned NOT NULL,
         | 
| 6 | 
            +
              `function_id` int(11) unsigned,
         | 
| 7 | 
            +
              `node_id` int(11) unsigned,
         | 
| 6 8 | 
             
              `entry` text NOT NULL,
         | 
| 7 9 | 
             
              `created` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
         | 
| 8 10 | 
             
              `updated` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
         | 
| 9 11 | 
             
              PRIMARY KEY (`id`),
         | 
| 10 | 
            -
               | 
| 12 | 
            +
              KEY (`created`),
         | 
| 13 | 
            +
              KEY (`updated`),
         | 
| 14 | 
            +
              CONSTRAINT `task_log_task_id` FOREIGN KEY (`task_id`) REFERENCES `tasks` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
         | 
| 15 | 
            +
              CONSTRAINT `task_log_functions` FOREIGN KEY (`function_id`) REFERENCES `functions` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
         | 
| 16 | 
            +
              CONSTRAINT `task_log_nodes` FOREIGN KEY (`node_id`) REFERENCES `nodes` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
         | 
| 11 17 | 
             
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"
         | 
| 12 18 | 
             
              end
         | 
| 13 19 |  | 
| 14 20 | 
             
              down do
         | 
| 15 | 
            -
                 | 
| 21 | 
            +
                drop_table :task_logs
         | 
| 16 22 | 
             
              end
         | 
| 17 23 | 
             
            end
         | 
| @@ -0,0 +1,24 @@ | |
| 1 | 
            +
            Sequel.migration do
         | 
| 2 | 
            +
              up do
         | 
| 3 | 
            +
                lex = from(:extensions).insert(namespace: 'Legion::Extensions::Lex', name: 'lex', exchange: 'lex', uri: 'lex')
         | 
| 4 | 
            +
                [
         | 
| 5 | 
            +
                  { extension_id: lex, namespace: 'Legion::Extensions::Lex::Runners::Register', name: 'register', queue: 'register', uri: 'register' },
         | 
| 6 | 
            +
                  { extension_id: lex, namespace: 'Legion::Extensions::Lex::Runners::Function', name: 'function', queue: 'function', uri: 'function' },
         | 
| 7 | 
            +
                  { extension_id: lex, namespace: 'Legion::Extensions::Lex::Runners::Runner', name: 'runner', queue: 'runner', uri: 'runner' },
         | 
| 8 | 
            +
                  { extension_id: lex, namespace: 'Legion::Extensions::Lex::Runners::Extension', name: 'extension', queue: 'extension', uri: 'extension' }
         | 
| 9 | 
            +
                ].each do |row|
         | 
| 10 | 
            +
                  from(:runners).insert row
         | 
| 11 | 
            +
                end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                lex = from(:extensions).insert(namespace: 'Legion::Extensions::Node', name: 'node', exchange: 'node', uri: 'node')
         | 
| 14 | 
            +
                [
         | 
| 15 | 
            +
                  { extension_id: lex, namespace: 'Legion::Extensions::Node::Runners::Crypt', name: 'crypt', queue: 'crypt', uri: 'crypt' }
         | 
| 16 | 
            +
                ].each do |row|
         | 
| 17 | 
            +
                  from(:runners).insert row
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
              down do
         | 
| 21 | 
            +
                from(:extensions).where(namespace: 'Legion::Extensions::Lex').delete
         | 
| 22 | 
            +
                from(:extensions).where(namespace: 'Legion::Extensions::Node').delete
         | 
| 23 | 
            +
              end
         | 
| 24 | 
            +
            end
         | 
    
        data/lib/legion/data/model.rb
    CHANGED
    
    | @@ -3,6 +3,7 @@ module Legion | |
| 3 3 | 
             
                module Models
         | 
| 4 4 | 
             
                  class << self
         | 
| 5 5 | 
             
                    attr_reader :loaded_models
         | 
| 6 | 
            +
             | 
| 6 7 | 
             
                    def models
         | 
| 7 8 | 
             
                      %w[user group extension chain relationship function task runner task_log datacenter environment node setting]
         | 
| 8 9 | 
             
                    end
         | 
| @@ -11,10 +12,11 @@ module Legion | |
| 11 12 | 
             
                      Legion::Logging.info 'Loading Legion::Data::Models'
         | 
| 12 13 | 
             
                      @loaded_models ||= []
         | 
| 13 14 | 
             
                      require_sequel_models(models)
         | 
| 15 | 
            +
                      Legion::Settings[:data][:models][:loaded] = true
         | 
| 14 16 | 
             
                    end
         | 
| 15 17 |  | 
| 16 18 | 
             
                    def require_sequel_models(files = models)
         | 
| 17 | 
            -
                      Dir[File.dirname(__FILE__) | 
| 19 | 
            +
                      Dir["#{File.dirname(__FILE__)}models/*.rb"].each { |file| puts file }
         | 
| 18 20 | 
             
                      files.each { |file| load_sequel_model(file) }
         | 
| 19 21 | 
             
                    end
         | 
| 20 22 |  | 
| @@ -23,6 +25,7 @@ module Legion | |
| 23 25 | 
             
                      require_relative "models/#{model}"
         | 
| 24 26 | 
             
                      @loaded_models << model
         | 
| 25 27 | 
             
                      Legion::Logging.debug("Successfully loaded #{model}")
         | 
| 28 | 
            +
                      model
         | 
| 26 29 | 
             
                    rescue LoadError => e
         | 
| 27 30 | 
             
                      Legion::Logging.fatal("Failed to load #{model}")
         | 
| 28 31 | 
             
                      raise e unless Legion::Settings[:data][:models][:continue_on_fail]
         | 
| @@ -9,8 +9,6 @@ module Legion | |
| 9 9 | 
             
                    many_to_one :runner
         | 
| 10 10 | 
             
                    one_to_many :trigger_relationships, class: 'Legion::Data::Model::Relationship', key: :trigger_id
         | 
| 11 11 | 
             
                    one_to_many :action_relationships, class: 'Legion::Data::Model::Relationship', key: :action_id
         | 
| 12 | 
            -
                    many_to_one :user_owner, class: Legion::Data::Model::User
         | 
| 13 | 
            -
                    many_to_one :group_owner, class: Legion::Data::Model::Group
         | 
| 14 12 | 
             
                  end
         | 
| 15 13 | 
             
                end
         | 
| 16 14 | 
             
              end
         | 
| @@ -10,8 +10,6 @@ module Legion | |
| 10 10 | 
             
                    one_to_many :task
         | 
| 11 11 | 
             
                    many_to_one :trigger, class: Legion::Data::Model::Function
         | 
| 12 12 | 
             
                    many_to_one :action, class: Legion::Data::Model::Function
         | 
| 13 | 
            -
                    many_to_one :user_owner, class: Legion::Data::Model::User
         | 
| 14 | 
            -
                    many_to_one :group_owner, class: Legion::Data::Model::Group
         | 
| 15 13 | 
             
                  end
         | 
| 16 14 | 
             
                end
         | 
| 17 15 | 
             
              end
         | 
| @@ -10,8 +10,6 @@ module Legion | |
| 10 10 | 
             
                    one_to_many :children, key: :parent_id, class: self
         | 
| 11 11 | 
             
                    many_to_one :master, class: self
         | 
| 12 12 | 
             
                    one_to_many :slave, key: :master_id, class: self
         | 
| 13 | 
            -
                    many_to_one :user_owner, class: Legion::Data::Model::User
         | 
| 14 | 
            -
                    many_to_one :group_owner, class: Legion::Data::Model::Group
         | 
| 15 13 | 
             
                  end
         | 
| 16 14 | 
             
                end
         | 
| 17 15 | 
             
              end
         | 
    
        data/lib/legion/data/settings.rb
    CHANGED
    
    | @@ -3,13 +3,13 @@ module Legion | |
| 3 3 | 
             
                module Settings
         | 
| 4 4 | 
             
                  def self.default
         | 
| 5 5 | 
             
                    {
         | 
| 6 | 
            -
                      connected: | 
| 7 | 
            -
                      cache: | 
| 8 | 
            -
                      connection: | 
| 9 | 
            -
                      creds: | 
| 10 | 
            -
                      migrations: | 
| 11 | 
            -
                      models: | 
| 12 | 
            -
             | 
| 6 | 
            +
                      connected:        false,
         | 
| 7 | 
            +
                      cache:            cache,
         | 
| 8 | 
            +
                      connection:       connection,
         | 
| 9 | 
            +
                      creds:            creds,
         | 
| 10 | 
            +
                      migrations:       migrations,
         | 
| 11 | 
            +
                      models:           models,
         | 
| 12 | 
            +
                      connect_on_start: true
         | 
| 13 13 | 
             
                    }
         | 
| 14 14 | 
             
                  end
         | 
| 15 15 |  | 
| @@ -35,7 +35,7 @@ module Legion | |
| 35 35 | 
             
                      log_connection_info: false,
         | 
| 36 36 | 
             
                      log_warn_duration:   1,
         | 
| 37 37 | 
             
                      sql_log_level:       'debug',
         | 
| 38 | 
            -
                      max_connections:      | 
| 38 | 
            +
                      max_connections:     10
         | 
| 39 39 | 
             
                    }
         | 
| 40 40 | 
             
                  end
         | 
| 41 41 |  | 
| @@ -60,3 +60,9 @@ module Legion | |
| 60 60 | 
             
                end
         | 
| 61 61 | 
             
              end
         | 
| 62 62 | 
             
            end
         | 
| 63 | 
            +
             | 
| 64 | 
            +
            begin
         | 
| 65 | 
            +
              Legion::Settings.merge_settings('data', Legion::Data::Settings.default) if Legion.const_defined?('Settings')
         | 
| 66 | 
            +
            rescue StandardError => e
         | 
| 67 | 
            +
              Legion::Logging.fatal(e.message) if Legion::Logging.method_defined?(:fatal)
         | 
| 68 | 
            +
            end
         | 
    
        data/lib/legion/data/version.rb
    CHANGED
    
    
| @@ -0,0 +1,12 @@ | |
| 1 | 
            +
            sonar.projectKey=legion-io_legion-data
         | 
| 2 | 
            +
            sonar.organization=legion-io
         | 
| 3 | 
            +
            sonar.projectName=Legion::Data
         | 
| 4 | 
            +
            sonar.sources=.
         | 
| 5 | 
            +
            sonar.exclusions=vendor/**
         | 
| 6 | 
            +
            sonar.coverage.exclusions=spec/**
         | 
| 7 | 
            +
            sonar.ruby.coverage.reportPath=coverage/.resultset.json
         | 
| 8 | 
            +
            sonar.ruby.file.suffixes=rb,ruby
         | 
| 9 | 
            +
            sonar.ruby.coverage.framework=RSpec
         | 
| 10 | 
            +
            sonar.ruby.rubocopConfig=.rubocop.yml
         | 
| 11 | 
            +
            sonar.ruby.rubocop.reportPath=rubocop-result.json
         | 
| 12 | 
            +
            sonar.ruby.rubocop.filePath=.
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: legion-data
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version:  | 
| 4 | 
            +
              version: 1.1.2
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Esity
         | 
| 8 | 
            -
            autorequire: | 
| 8 | 
            +
            autorequire:
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2020- | 
| 11 | 
            +
            date: 2020-08-25 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: bundler
         | 
| @@ -219,6 +219,7 @@ files: | |
| 219 219 | 
             
            - ".rubocop.yml"
         | 
| 220 220 | 
             
            - CHANGELOG.md
         | 
| 221 221 | 
             
            - Gemfile
         | 
| 222 | 
            +
            - Gemfile.lock
         | 
| 222 223 | 
             
            - README.md
         | 
| 223 224 | 
             
            - Rakefile
         | 
| 224 225 | 
             
            - bin/console
         | 
| @@ -227,11 +228,6 @@ files: | |
| 227 228 | 
             
            - legion-data.gemspec
         | 
| 228 229 | 
             
            - lib/legion/data.rb
         | 
| 229 230 | 
             
            - lib/legion/data/connection.rb
         | 
| 230 | 
            -
            - lib/legion/data/connections/base.rb
         | 
| 231 | 
            -
            - lib/legion/data/connections/jdbc.rb
         | 
| 232 | 
            -
            - lib/legion/data/connections/mysql.rb
         | 
| 233 | 
            -
            - lib/legion/data/connections/mysql2.rb
         | 
| 234 | 
            -
            - lib/legion/data/connections/mysql_base.rb
         | 
| 235 231 | 
             
            - lib/legion/data/migration.rb
         | 
| 236 232 | 
             
            - lib/legion/data/migrations/001_add_schema_columns.rb
         | 
| 237 233 | 
             
            - lib/legion/data/migrations/002_add_users.rb
         | 
| @@ -247,6 +243,9 @@ files: | |
| 247 243 | 
             
            - lib/legion/data/migrations/012_add_tasks.rb
         | 
| 248 244 | 
             
            - lib/legion/data/migrations/013_add_task_logs.rb
         | 
| 249 245 | 
             
            - lib/legion/data/migrations/014_add_relationships.rb
         | 
| 246 | 
            +
            - lib/legion/data/migrations/015_add_default_extensions.rb
         | 
| 247 | 
            +
            - lib/legion/data/migrations/016_change_task_args.rb
         | 
| 248 | 
            +
            - lib/legion/data/migrations/017_add_payload_task.rb
         | 
| 250 249 | 
             
            - lib/legion/data/model.rb
         | 
| 251 250 | 
             
            - lib/legion/data/models/chain.rb
         | 
| 252 251 | 
             
            - lib/legion/data/models/datacenter.rb
         | 
| @@ -254,7 +253,6 @@ files: | |
| 254 253 | 
             
            - lib/legion/data/models/extension.rb
         | 
| 255 254 | 
             
            - lib/legion/data/models/function.rb
         | 
| 256 255 | 
             
            - lib/legion/data/models/group.rb
         | 
| 257 | 
            -
            - lib/legion/data/models/namespace.rb
         | 
| 258 256 | 
             
            - lib/legion/data/models/node.rb
         | 
| 259 257 | 
             
            - lib/legion/data/models/relationship.rb
         | 
| 260 258 | 
             
            - lib/legion/data/models/runner.rb
         | 
| @@ -264,6 +262,7 @@ files: | |
| 264 262 | 
             
            - lib/legion/data/models/user.rb
         | 
| 265 263 | 
             
            - lib/legion/data/settings.rb
         | 
| 266 264 | 
             
            - lib/legion/data/version.rb
         | 
| 265 | 
            +
            - sonar-project.properties
         | 
| 267 266 | 
             
            homepage: https://bitbucket.org/legion-io/legion-data
         | 
| 268 267 | 
             
            licenses: []
         | 
| 269 268 | 
             
            metadata:
         | 
| @@ -273,7 +272,7 @@ metadata: | |
| 273 272 | 
             
              homepage_uri: https://bitbucket.org/legion-io/legion-data
         | 
| 274 273 | 
             
              source_code_uri: https://bitbucket.org/legion-io/legion-data
         | 
| 275 274 | 
             
              wiki_uri: https://bitbucket.org/legion-io/legion-data/wiki/Home
         | 
| 276 | 
            -
            post_install_message: | 
| 275 | 
            +
            post_install_message:
         | 
| 277 276 | 
             
            rdoc_options: []
         | 
| 278 277 | 
             
            require_paths:
         | 
| 279 278 | 
             
            - lib
         | 
| @@ -281,15 +280,15 @@ required_ruby_version: !ruby/object:Gem::Requirement | |
| 281 280 | 
             
              requirements:
         | 
| 282 281 | 
             
              - - ">="
         | 
| 283 282 | 
             
                - !ruby/object:Gem::Version
         | 
| 284 | 
            -
                  version:  | 
| 283 | 
            +
                  version: 2.5.0
         | 
| 285 284 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 286 285 | 
             
              requirements:
         | 
| 287 286 | 
             
              - - ">="
         | 
| 288 287 | 
             
                - !ruby/object:Gem::Version
         | 
| 289 288 | 
             
                  version: '0'
         | 
| 290 289 | 
             
            requirements: []
         | 
| 291 | 
            -
            rubygems_version: 3. | 
| 292 | 
            -
            signing_key: | 
| 290 | 
            +
            rubygems_version: 3.1.2
         | 
| 291 | 
            +
            signing_key:
         | 
| 293 292 | 
             
            specification_version: 4
         | 
| 294 293 | 
             
            summary: Used by Legion to connect to the database
         | 
| 295 294 | 
             
            test_files: []
         | 
| @@ -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,14 +0,0 @@ | |
| 1 | 
            -
            # frozen_string_literal: true
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            module Legion
         | 
| 4 | 
            -
              module Data
         | 
| 5 | 
            -
                module Model
         | 
| 6 | 
            -
                  class Namespace < Sequel::Model
         | 
| 7 | 
            -
                    one_to_many :function
         | 
| 8 | 
            -
                    many_to_one :extension
         | 
| 9 | 
            -
                    many_to_one :user_owner, class: Legion::Data::Model::User
         | 
| 10 | 
            -
                    many_to_one :group_owner, class: Legion::Data::Model::Group
         | 
| 11 | 
            -
                  end
         | 
| 12 | 
            -
                end
         | 
| 13 | 
            -
              end
         | 
| 14 | 
            -
            end
         |