Attempt to get specs running with new active-record design

This commit is contained in:
Jonathan Claudius 2018-01-23 10:30:41 -05:00
Родитель 3a363e1ad5
Коммит ae0e88778b
8 изменённых файлов: 28 добавлений и 42 удалений

Просмотреть файл

@ -1,25 +1,6 @@
development:
adapter: postgresql
encoding: unicode
database: ssh_observatory
host: localhost
username: sshobs
port: 5432
test:
adapter: postgresql
encoding: unicode
database: ssh_observatory
pool: 5
host: localhost
username: sshobs
port: 5432
production:
adapter: postgresql
encoding: unicode
database: ssh_observatory
pool: 5
host: sshobservatory_database.mozilla.org
username: sshobs
port: 5432
adapter: postgresql
database: ssh_observatory
username: sshobs
host: 127.0.0.1
pool: 5
timeout: 5000

Просмотреть файл

@ -1,6 +1,4 @@
#!/bin/bash
set -e
createuser sshobs --no-password
createdb -O sshobs ssh_observatory
psql -U sshobs -d ssh_observatory < /app/schema.sql
createuser sshobs --no-password --superuser

Просмотреть файл

@ -1,6 +1,5 @@
#!/bin/bash
set -e
createuser sshobs --no-password
createdb -O sshobs ssh_observatory
psql -U sshobs -d ssh_observatory < ./database/schema.sql
createuser sshobs --no-password --superuser
rake db:drop && rake db:create && rake db:migrate

Просмотреть файл

@ -12,6 +12,9 @@
ActiveRecord::Schema.define(version: 20180120054652) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
create_table "scans", force: :cascade do |t|
t.string "scan_id"
t.datetime "creation_time"

Просмотреть файл

@ -1,4 +1,3 @@
FROM postgres AS database
MAINTAINER Jonathan Claudius
ADD ./database/schema.sql /app/schema.sql
ADD ./database/init-user-db-docker.sh /docker-entrypoint-initdb.d/

Просмотреть файл

@ -6,14 +6,15 @@ require 'secure_headers'
require 'ssh_scan_api/models/scan'
require 'ssh_scan_api/target_validator'
require 'ssh_scan_api/authenticator'
require 'pg'
enable :logging
set :database, {adapter: "sqlite3", database: "foo.sqlite3"}
set :database_file, "../../config/database/database.yml"
set :server, 'thin'
set :logger, Logger.new(STDOUT)
set :target_validator, SSHScan::TargetValidator.new("./config/api/config.yml")
set :authenticator, SSHScan::Authenticator.new("./config/api/config.yml")
set :environment, :production
set :environment, :test
set :allowed_ports, [22]
set :protection, false

Просмотреть файл

@ -3,8 +3,6 @@ require 'ssh_scan_api/version'
require 'ssh_scan_api/models/scan'
require 'logger'
class SSHScan::Worker
def initialize()
@worker_id = SecureRandom.uuid
@ -37,19 +35,27 @@ class SSHScan::Worker
scan.state = "COMPLETED"
scan.worker_id = @worker_id
if results.first["compliance"]
scan.grade = results.first["compliance"]["grade"]
end
scan.raw_scan = results.first.to_json
scan.save
else
@log.info("No work available")
sleep @poll_interval
end
end
def run!
setup_db_connection
loop do
do_work
sleep @poll_interval
#begin
do_work
#rescue
#end
end
end
end

Просмотреть файл

@ -27,11 +27,10 @@ Gem::Specification.new do |s|
s.homepage = 'http://rubygems.org/gems/ssh_scan_api'
s.add_dependency('ssh_scan', '0.0.32')
s.add_dependency('sinatra-activerecord')
s.add_dependency('sqlite3')
s.add_dependency('pg')
s.add_dependency('sinatra')
s.add_dependency('sinatra-contrib')
s.add_dependency('sinatra-activerecord')
s.add_dependency('pg', '~> 0.21')
s.add_dependency('thin')
s.add_dependency('haml')
s.add_dependency('secure_headers', '3.6.4')