diff --git a/Gemfile b/Gemfile index 526576f..7bb31a4 100644 --- a/Gemfile +++ b/Gemfile @@ -1,8 +1,8 @@ source "https://rubygems.org" -git_source(:github) { |repo| "https://github.com/#{repo}.git" } gem "aws-sdk-s3", "~> 1.136" gem "bagit", "~> 0.4.6" +gem "canister" gem "faraday", "~> 2.9" gem "faraday-retry", "~> 2.2" gem "minitar", "~> 0.9" @@ -10,7 +10,6 @@ gem "mysql2", "~> 0.5.6" gem "rexml", "~> 3.2.6" gem "semantic_logger", "~> 4.15" gem "sequel", "~> 5.77" -gem "canister" gem "sftp", git: "https://github.com/mlibrary/sftp", diff --git a/Rakefile b/Rakefile index edc0579..86f88ee 100644 --- a/Rakefile +++ b/Rakefile @@ -1,4 +1,3 @@ -$LOAD_PATH.unshift(File.dirname(__FILE__)) require "minitest/test_task" Minitest::TestTask.create @@ -10,16 +9,15 @@ namespace :db do task :migrate, [:version] do |t, args| require "sequel/core" require_relative "db/database_error" - require "services" + require_relative "services" Sequel.extension :migration - db_config = Config::ConfigService.database_config_from_env - if !db_config + if !S.db_config raise DatabaseError, "Migration failed. A database connection is not configured." end version = args[:version].to_i if args[:version] - Sequel::Migrator.run(dbconnect, "db/migrations", target: version) + Sequel::Migrator.run(S.dbconnect, "db/migrations", target: version) end end diff --git a/example.env b/example.env index 96c436b..f071250 100644 --- a/example.env +++ b/example.env @@ -34,7 +34,8 @@ ARCHIVEMATICA_DEV_REPOSITORY_NAME= # REST API ARCHIVEMATICA_DEV_API_USERNAME= ARCHIVEMATICA_DEV_API_API_KEY= -ARCHIVEMATICA_DEV_BASE_URL= +ARCHIVEMATICA_DEV_API_BASE_URL= +ARCHIVEMATICA_DEV_API_LOCATION_UUID= # Remote ARCHIVEMATICA_DEV_REMOTE_TYPE=file_system ARCHIVEMATICA_DEV_REMOTE_SETTINGS_FILE_SYSTEM_REMOTE_PATH= diff --git a/lib/aptrust.rb b/lib/aptrust.rb index ecb227f..fc0c377 100644 --- a/lib/aptrust.rb +++ b/lib/aptrust.rb @@ -1,8 +1,6 @@ -$LOAD_PATH.unshift(File.dirname(__FILE__)) -require "services" - require_relative "api_backend" require_relative "bag_status" +require_relative "../services" module APTrust module IngestStatus diff --git a/lib/archivematica.rb b/lib/archivematica.rb index fca7514..73c2a79 100644 --- a/lib/archivematica.rb +++ b/lib/archivematica.rb @@ -1,8 +1,6 @@ -$LOAD_PATH.unshift(File.dirname(__FILE__)) -require "services" - require_relative "api_backend" require_relative "repository_data" +require_relative "../services" module Archivematica Package = Struct.new( diff --git a/lib/bag_adapter.rb b/lib/bag_adapter.rb index d306446..f577df9 100644 --- a/lib/bag_adapter.rb +++ b/lib/bag_adapter.rb @@ -1,6 +1,5 @@ -$LOAD_PATH.unshift(File.dirname(__FILE__)) require "bagit" -require "services" +require_relative "../services" module BagAdapter class BagAdapter diff --git a/lib/bag_courier.rb b/lib/bag_courier.rb index e8e77b6..b2526f3 100644 --- a/lib/bag_courier.rb +++ b/lib/bag_courier.rb @@ -1,10 +1,9 @@ -$LOAD_PATH.unshift(File.dirname(__FILE__)) require "minitar" -require "services" require_relative "bag_adapter" require_relative "bag_status" require_relative "remote_client" +require_relative "../services" module BagCourier class BagId diff --git a/lib/bag_repository.rb b/lib/bag_repository.rb index 2dc0c56..0ae28a2 100644 --- a/lib/bag_repository.rb +++ b/lib/bag_repository.rb @@ -1,7 +1,5 @@ -$LOAD_PATH.unshift(File.dirname(__FILE__)) -require "services" - require_relative "../db/database_schema" if DB +require_relative "../services" module BagRepository Bag = Struct.new( diff --git a/lib/bag_validator.rb b/lib/bag_validator.rb index 939f37b..cb114ac 100644 --- a/lib/bag_validator.rb +++ b/lib/bag_validator.rb @@ -5,6 +5,7 @@ def validate(path) raise NotImplementedError, "subclass must implement the validate method" end end + class InnerBagValidator < BagValidator def initialize(inner_bag_name) @inner_bag_name = inner_bag_name @@ -20,9 +21,9 @@ def validate(data_path) validity = @bag.valid? if !validity - raise BagValidationError, "Inner bag is not valid: #{@bag.errors.full_messages.join(', ')}" + raise BagValidationError, "Inner bag is not valid: #{@bag.errors.full_messages.join(", ")}" else - return validity + validity end end end diff --git a/lib/config.rb b/lib/config.rb index 649d0a0..2f97f61 100644 --- a/lib/config.rb +++ b/lib/config.rb @@ -313,4 +313,4 @@ def self.from_env create_config(ENV.to_hash) end end -end \ No newline at end of file +end diff --git a/lib/remote_client.rb b/lib/remote_client.rb index 9dba46b..7ae95a8 100644 --- a/lib/remote_client.rb +++ b/lib/remote_client.rb @@ -1,10 +1,10 @@ -$LOAD_PATH.unshift(File.dirname(__FILE__)) require "bundler/setup" require "aws-sdk-s3" -require "services" require "sftp" +require_relative "../services" + module RemoteClient class RemoteClientError < StandardError end diff --git a/lib/repository_package_repository.rb b/lib/repository_package_repository.rb index 3b16446..054d9d3 100644 --- a/lib/repository_package_repository.rb +++ b/lib/repository_package_repository.rb @@ -1,7 +1,5 @@ -$LOAD_PATH.unshift(File.dirname(__FILE__)) -require "services" - require_relative "../db/database_schema" if DB +require_relative "../services" module RepositoryPackageRepository RepositoryPackage = Struct.new( diff --git a/lib/status_event_repository.rb b/lib/status_event_repository.rb index f22840b..56faf68 100644 --- a/lib/status_event_repository.rb +++ b/lib/status_event_repository.rb @@ -1,7 +1,5 @@ -$LOAD_PATH.unshift(File.dirname(__FILE__)) -require "services" - require_relative "bag_status" +require_relative "../services" require_relative "../db/database_schema" if DB diff --git a/run_dark_blue.rb b/run_dark_blue.rb index 653f103..d0a0bfa 100644 --- a/run_dark_blue.rb +++ b/run_dark_blue.rb @@ -1,24 +1,11 @@ -$LOAD_PATH.unshift(File.dirname(__FILE__)) require "optparse" - require "sequel" -require "services" -require_relative "lib/config" +require_relative "services" -SemanticLogger.add_appender(io: $stderr, formatter: :color) -config = Config::ConfigService.from_env -SemanticLogger.default_level = config.settings.log_level +config = S.config -DB = config.database && Sequel.connect( - adapter: "mysql2", - host: config.database.host, - port: config.database.port, - database: config.database.database, - user: config.database.user, - password: config.database.password, - fractional_seconds: true -) +DB = config.database && S.dbconnect require_relative "lib/archivematica" require_relative "lib/bag_repository" @@ -33,8 +20,8 @@ class DarkBlueError < StandardError end class DarkBlueJob - include SemanticLogger::Loggable - + include DarkBlueLogger + module ExtraBagInfoData CONTENT_TYPE_KEY = "Dark-Blue-Content-Type" LOCATION_UUID_KEY = "Archivematica-Location-UUID" @@ -207,4 +194,4 @@ def self.parse(options) dark_blue_job.redeliver_packages(options.packages) else dark_blue_job.process -end \ No newline at end of file +end diff --git a/services.rb b/services.rb index 9007a31..393cee0 100644 --- a/services.rb +++ b/services.rb @@ -1,6 +1,7 @@ require "canister" require "semantic_logger" require "sequel" + require_relative "lib/config" Services = Canister.new @@ -9,20 +10,13 @@ # Config S.register(:config) do - Config::ConfigService.from_file(ENV.fetch("CONFIG_YML_PATH", File.join(".", "config", "config.yml"))) + Config::ConfigService.from_env end S.register(:db_config) do - Config::ConfigService.database_config_from_file(ENV.fetch("CONFIG_YML_PATH", File.join(".", "config", "config.yml"))) -end - -def config - S.config + Config::ConfigService.database_config_from_env end -def db_config - S.db_config -end # Logger module DarkBlueLogger @@ -32,13 +26,13 @@ def self.included(klass) include SemanticLogger::Loggable SemanticLogger[klass] S.register(:log_stream) do - $stdout.sync = true - $stdout + $stderr.sync = true + $stderr end S.register(:logger) do if !SemanticLogger::Logger.processor.appenders.console_output? SemanticLogger.add_appender(io: S.log_stream, formatter: :color) - SemanticLogger.default_level = config.settings.log_level + SemanticLogger.default_level = S.config.settings.log_level end end end @@ -49,14 +43,10 @@ def self.included(klass) # Database Connection S.register(:dbconnect) do Sequel.connect(adapter: "mysql2", - host: config.database.host, - port: config.database.port, - database: config.database.database, - user: config.database.user, - password: config.database.password, + host: S.config.database.host, + port: S.config.database.port, + database: S.config.database.database, + user: S.config.database.user, + password: S.config.database.password, fractional_seconds: true) end - -def dbconnect - S.dbconnect -end diff --git a/verify_aptrust.rb b/verify_aptrust.rb index d87ce54..d39e7cc 100644 --- a/verify_aptrust.rb +++ b/verify_aptrust.rb @@ -1,22 +1,10 @@ -$LOAD_PATH.unshift(File.dirname(__FILE__)) -require "services" require "sequel" -require_relative "lib/config" - -SemanticLogger.add_appender(io: $stderr, formatter: :color) -config = Config::ConfigService.from_env -SemanticLogger.default_level = config.settings.log_level - -DB = config.database && Sequel.connect( - adapter: "mysql2", - host: config.database.host, - port: config.database.port, - database: config.database.database, - user: config.database.user, - password: config.database.password, - fractional_seconds: true -) +require_relative "services" + +config = S.config + +DB = config.database && S.dbconnect require_relative "lib/aptrust" require_relative "lib/bag_repository"