Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
maimux2x committed Jul 2, 2024
1 parent 4f9663b commit 180286b
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 23 deletions.
18 changes: 1 addition & 17 deletions api/app/models/database/dra.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,28 +92,12 @@ def submit(submission)
submitter_id:
)

host, user, key_data = ENV.fetch_values('DRA_SSH_HOST', 'DRA_SSH_USER', 'DRA_SSH_KEY_DATA')
host, user, key_data = ENV.values_at('DRA_SSH_HOST', 'DRA_SSH_USER', 'DRA_SSH_KEY_DATA')

Net::SSH.start host, user, key_data: [key_data] do |ssh|
ssh.exec! "sudo /usr/local/sbin/chroot-createdir.sh #{submitter_id} #{submission_id}"
end
end

private

def mkdir_p!(sftp, path)
components = path.split('/')

components.size.times.map {|i|
components[0..i].join('/')
}.each do |sub_path|
begin
sftp.mkdir! sub_path
rescue Net::SFTP::StatusException => e
raise unless e.code == 4
end
end
end
end
end
end
12 changes: 6 additions & 6 deletions api/db/dway/submitter_db/migrations/001_init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
create_table :login do
primary_key :usr_id, type: :bigint

text :submitter_id, null: false
text :password, null: false
integer :role, null: false, default: 0
boolean :usable, null: false, default: true
boolean :need_chgpasswd, default: true
timestamp :create_date, default: Sequel.lit("date_trunc('second'::text, now())")
text :submitter_id, null: false
text :password, null: false
integer :role, null: false, default: 0
boolean :usable, null: false, default: true
boolean :need_chgpasswd, default: true
timestamp :create_date, default: Sequel.lit("date_trunc('second'::text, now())")
end
end
end
23 changes: 23 additions & 0 deletions api/spec/models/database/dra/submitter_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require 'rails_helper'

RSpec.describe Database::DRA::Submitter, type: :model do
example do
submission = create(:submission)
submitter_db = Sequel.connect(ENV.fetch('SUBMITTER_DB_DATABASE_URL'))

user_id = submitter_db[:login].insert(
submitter_id: submission.validation.user.uid,
password: 'password',
)

expect(Net::SSH).to receive(:start)

Database::DRA::Submitter.new.submit submission

drmdb = Sequel.connect(ENV.fetch('DRMDB_DATABASE_URL'))

expect(drmdb[:submission].first).to include(usr_id: user_id, submitter_id: submission.validation.user.uid, serial: 1)

pp drmdb[:status_history]
end
end
21 changes: 21 additions & 0 deletions api/spec/support/dway.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require 'sequel/core'

ENV['DRMDB_DATABASE_URL'] = 'postgres://localhost/drmdb_test'
ENV['SUBMITTER_DB_DATABASE_URL'] = 'postgres://localhost/submitter_db_test'
ENV['DRA_SSH_HOST'] = 'localhost'
ENV['DRA_SSH_USER'] = 'alice'
ENV['DRA_SSH_KEY_DATA'] = 'KEY_DATA'

RSpec.configure do |config|
config.before :suite do
Sequel.extension :migration

Sequel.connect ENV.fetch('DRMDB_DATABASE_URL') do |db|
Sequel::Migrator.run db, 'db/dway/drmdb/migrations'
end

Sequel.connect ENV.fetch('SUBMITTER_DB_DATABASE_URL') do |db|
Sequel::Migrator.run db, 'db/dway/submitter_db/migrations'
end
end
end

0 comments on commit 180286b

Please sign in to comment.