mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-07 21:48:16 -08:00
ECP-170 Remove login requirement for Trition. Switch to using predefined passwords stored in the database for district login.
This commit is contained in:
parent
72e38f5ee8
commit
2068758ae4
15 changed files with 146 additions and 16 deletions
45
app/services/credentials_loader.rb
Normal file
45
app/services/credentials_loader.rb
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
require "csv"
|
||||
|
||||
class CredentialsLoader
|
||||
def self.load_credentials(file:)
|
||||
credentials = []
|
||||
CSV.parse(file, headers: true) do |row|
|
||||
values = CredentialRowValues.new(row:)
|
||||
next unless values.district.present?
|
||||
|
||||
credentials << values.district
|
||||
end
|
||||
District.import(credentials, batch_size: 100, on_duplicate_key_update: [:username, :password, :login_required])
|
||||
end
|
||||
end
|
||||
|
||||
class CredentialRowValues
|
||||
attr_reader :row
|
||||
|
||||
def initialize(row:)
|
||||
@row = row
|
||||
end
|
||||
|
||||
def district
|
||||
@district ||= begin
|
||||
name = row["Districts"]&.strip
|
||||
district = District.find_or_initialize_by(name:)
|
||||
district.username = username
|
||||
district.password = password
|
||||
district.login_required = login_required?
|
||||
district
|
||||
end
|
||||
end
|
||||
|
||||
def username
|
||||
row["Username"]&.strip
|
||||
end
|
||||
|
||||
def password
|
||||
row["PW"]&.strip
|
||||
end
|
||||
|
||||
def login_required?
|
||||
row["Login Required"]&.strip == "Y"
|
||||
end
|
||||
end
|
||||
17
app/services/sftp/file.rb
Normal file
17
app/services/sftp/file.rb
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
require 'net/sftp'
|
||||
require 'uri'
|
||||
|
||||
module Sftp
|
||||
class File
|
||||
def self.open(filepath:, &block)
|
||||
sftp_url = ENV['SFTP_URL']
|
||||
uri = URI.parse(sftp_url)
|
||||
Net::SFTP.start(uri.host, uri.user, password: uri.password) do |sftp|
|
||||
sftp.file.open(filepath, 'r', &block)
|
||||
end
|
||||
rescue Net::SFTP::StatusException => e
|
||||
puts "Error opening file: #{e.message}"
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue