bizside 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/app/assets/images/jquery-treeTable/images/toggle-collapse-dark.png +0 -0
- data/app/assets/images/jquery-treeTable/images/toggle-collapse-light.png +0 -0
- data/app/assets/images/jquery-treeTable/images/toggle-expand-dark.png +0 -0
- data/app/assets/images/jquery-treeTable/images/toggle-expand-light.png +0 -0
- data/app/assets/javascripts/bizside.js +1 -0
- data/app/assets/javascripts/jquery-treeTable/jquery.treeTable.js +400 -0
- data/app/assets/stylesheets/bizside.css +3 -0
- data/app/assets/stylesheets/jquery-treeTable/jquery.treeTable.css.erb +55 -0
- data/lib/bizside/acl/access_control_utils.rb +36 -0
- data/lib/bizside/acl/available_helper.rb +65 -0
- data/lib/bizside/acl/controller_helper.rb +15 -0
- data/lib/bizside/acl.rb +6 -0
- data/lib/bizside/active_record_logger.rb +3 -0
- data/lib/bizside/audit/job_logger.rb +14 -0
- data/lib/bizside/audit/logger.rb +35 -0
- data/lib/bizside/audit_log.rb +158 -0
- data/lib/bizside/cache/entry.rb +112 -0
- data/lib/bizside/cache/file_store.rb +167 -0
- data/lib/bizside/cache/store.rb +237 -0
- data/lib/bizside/cache_util.rb +47 -0
- data/lib/bizside/cache_utils.rb +10 -0
- data/lib/bizside/carrierwave.rb +48 -0
- data/lib/bizside/config.rb +63 -0
- data/lib/bizside/configurations/mail.rb +37 -0
- data/lib/bizside/configurations/prefix.rb +25 -0
- data/lib/bizside/configurations/storage.rb +28 -0
- data/lib/bizside/coverage/launch.rb +25 -0
- data/lib/bizside/coverage/rcov_formatter.rb +13 -0
- data/lib/bizside/cron_validator.rb +62 -0
- data/lib/bizside/cucumber.rb +1 -0
- data/lib/bizside/engine.rb +4 -0
- data/lib/bizside/file_converter.rb +56 -0
- data/lib/bizside/file_uploader.rb +71 -0
- data/lib/bizside/gengou.rb +46 -0
- data/lib/bizside/gengou.yml +5 -0
- data/lib/bizside/hanaita_conf.rb +88 -0
- data/lib/bizside/implicit_ftps.rb +29 -0
- data/lib/bizside/itamae_conf.rb +186 -0
- data/lib/bizside/job_utils.rb +285 -0
- data/lib/bizside/log_analyzer.rb +122 -0
- data/lib/bizside/mailer.rb +56 -0
- data/lib/bizside/query_builder.rb +78 -0
- data/lib/bizside/railtie.rb +80 -0
- data/lib/bizside/record_has_warnings.rb +4 -0
- data/lib/bizside/resque.rb +141 -0
- data/lib/bizside/rsync.rb +40 -0
- data/lib/bizside/safe_pty.rb +17 -0
- data/lib/bizside/shib_utils.rb +18 -0
- data/lib/bizside/show_exceptions.rb +18 -0
- data/lib/bizside/sql_utils.rb +45 -0
- data/lib/bizside/string_io.rb +39 -0
- data/lib/bizside/string_utils.rb +157 -0
- data/lib/bizside/task_helper.rb +263 -0
- data/lib/bizside/tasks.rb +6 -0
- data/lib/bizside/test_help.rb +17 -0
- data/lib/bizside/uploader/content_type_validator.rb +39 -0
- data/lib/bizside/uploader/default_extensions.yml +15 -0
- data/lib/bizside/uploader/exif.rb +43 -0
- data/lib/bizside/uploader/extension_whitelist.rb +26 -0
- data/lib/bizside/uploader/filename_validator.rb +31 -0
- data/lib/bizside/user_agent/action_view/action_view_4.rb +56 -0
- data/lib/bizside/user_agent/action_view/use_variant.rb +4 -0
- data/lib/bizside/user_agent/action_view.rb +10 -0
- data/lib/bizside/user_agent/controller_helper.rb +51 -0
- data/lib/bizside/user_agent.rb +108 -0
- data/lib/bizside/validations.rb +8 -0
- data/lib/bizside/version.rb +3 -0
- data/lib/bizside/view_helper.rb +10 -0
- data/lib/bizside/warning.rb +24 -0
- data/lib/bizside/yes.rb +16 -0
- data/lib/bizside.rb +96 -0
- data/lib/cron_validator.rb +3 -0
- data/lib/gengou.rb +3 -0
- data/lib/job_utils.rb +3 -0
- data/lib/query_builder.rb +3 -0
- data/lib/record_has_warnings.rb +3 -0
- data/lib/sql_utils.rb +3 -0
- data/lib/string_utils.rb +3 -0
- data/lib/user_agent.rb +3 -0
- data/lib/yes.rb +3 -0
- data/rails/locales/ja.yml +12 -0
- data/validations/collection_presence_validator.rb +15 -0
- data/validations/email_validator.rb +1 -0
- data/validations/ip_address_validator.rb +22 -0
- data/validations/tel_validator.rb +28 -0
- data/validations/url_validator.rb +30 -0
- data/validations/zip_validator.rb +35 -0
- metadata +467 -0
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'carrierwave'
|
2
|
+
|
3
|
+
# 日本語ファイル名のまま保存
|
4
|
+
CARRIERWAVE_SANITIZE_REGEXP = /[^[:word:]①-⑨【】「」()・&、 \(\)\.\-\+]/
|
5
|
+
CarrierWave::SanitizedFile.sanitize_regexp = CARRIERWAVE_SANITIZE_REGEXP
|
6
|
+
|
7
|
+
module Bizside
|
8
|
+
class CarrierwaveStringIO < StringIO
|
9
|
+
attr_accessor :original_filename
|
10
|
+
attr_accessor :content_type
|
11
|
+
attr_accessor :file_size
|
12
|
+
|
13
|
+
def path
|
14
|
+
original_filename
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
unless Bizside.config.within_bizside_namespace?
|
20
|
+
# 後方互換性の維持
|
21
|
+
CarrierwaveStringIO = Bizside::CarrierwaveStringIO
|
22
|
+
end
|
23
|
+
|
24
|
+
CarrierWave.configure do |config|
|
25
|
+
database_yml = ERB.new(File.read(File.join('config', 'database.yml')), 0, '-').result
|
26
|
+
database = YAML.load(database_yml)[Bizside.env]['database']
|
27
|
+
|
28
|
+
config.root = File.join('/data', Bizside.config.add_on_name, database)
|
29
|
+
|
30
|
+
if Bizside.config.storage.fog?
|
31
|
+
require 'carrierwave/storage/fog'
|
32
|
+
require 'fog/aws'
|
33
|
+
|
34
|
+
# fog の場合は、相対パス
|
35
|
+
config.root = config.root[1..-1]
|
36
|
+
|
37
|
+
credentials = Bizside.config.storage.fog.credentials.to_h.symbolize_keys
|
38
|
+
if credentials[:use_iam_profile]
|
39
|
+
credentials = credentials.merge(role_session_name: Bizside.config.add_on_name)
|
40
|
+
end
|
41
|
+
config.fog_credentials = credentials
|
42
|
+
|
43
|
+
config.fog_directory = Bizside.config.storage.fog.container
|
44
|
+
config.fog_public = false
|
45
|
+
config.storage = :fog
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require_relative 'configurations/mail'
|
2
|
+
require_relative 'configurations/prefix'
|
3
|
+
require_relative 'configurations/storage'
|
4
|
+
|
5
|
+
module Bizside
|
6
|
+
class Config
|
7
|
+
include Bizside::Configurations::Mail
|
8
|
+
include Bizside::Configurations::Prefix
|
9
|
+
include Bizside::Configurations::Storage
|
10
|
+
|
11
|
+
def initialize(hash = {})
|
12
|
+
@hash = hash || {}
|
13
|
+
end
|
14
|
+
|
15
|
+
def [](key)
|
16
|
+
key = key.to_s
|
17
|
+
return (@hash[key[0..-2]] ? true : false) if key.end_with?('?')
|
18
|
+
|
19
|
+
ret = @hash[key]
|
20
|
+
if ret.nil?
|
21
|
+
ret = self.class.new
|
22
|
+
elsif ret.is_a?(Hash)
|
23
|
+
ret = self.class.new(ret)
|
24
|
+
end
|
25
|
+
|
26
|
+
ret
|
27
|
+
end
|
28
|
+
|
29
|
+
def []=(key, value)
|
30
|
+
value = self.class.new(value) if value.is_a?(Hash)
|
31
|
+
@hash[key.to_s] = value
|
32
|
+
end
|
33
|
+
|
34
|
+
def to_h
|
35
|
+
@hash.dup
|
36
|
+
end
|
37
|
+
|
38
|
+
# Hash継承時代での互換維持のために実装
|
39
|
+
def empty?
|
40
|
+
@hash.empty?
|
41
|
+
end
|
42
|
+
|
43
|
+
# オブジェクトの Hash への暗黙の変換が必要なときに内部で呼ばれるメソッド
|
44
|
+
# Hash継承時代での互換維持のために実装。
|
45
|
+
# なお、Hashの継承時代でも @hash を活用していたので、空ハッシュを返す
|
46
|
+
# @see https://docs.ruby-lang.org/ja/latest/method/Object/i/to_hash.html
|
47
|
+
def to_hash
|
48
|
+
warn "DEPRECATION WARNING: #{__method__} is deprecated and will be removed."
|
49
|
+
{}
|
50
|
+
end
|
51
|
+
|
52
|
+
def method_missing(name, *args)
|
53
|
+
ret = self[name]
|
54
|
+
|
55
|
+
if ret.is_a?(Hash) and not args[0].nil?
|
56
|
+
ret = args[0]
|
57
|
+
end
|
58
|
+
|
59
|
+
ret
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Bizside
|
2
|
+
module Configurations
|
3
|
+
module Mail
|
4
|
+
|
5
|
+
def mail
|
6
|
+
if @mail.nil?
|
7
|
+
configfile = File.join('config', 'mail.yml')
|
8
|
+
|
9
|
+
if File.exist?(configfile)
|
10
|
+
@mail = Bizside::Config.new(YAML.load_file(configfile)[Bizside.env])
|
11
|
+
else
|
12
|
+
@mail = Bizside::Config.new
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
@mail
|
17
|
+
end
|
18
|
+
|
19
|
+
def default_url_options
|
20
|
+
{:protocol => 'https', :host => mail.app_host, :script_name => prefix}
|
21
|
+
end
|
22
|
+
|
23
|
+
def smtp_settings
|
24
|
+
ret = {}
|
25
|
+
ret[:address] = mail.smtp.host if mail.smtp.host?
|
26
|
+
ret[:port] = mail.smtp.port if mail.smtp.port?
|
27
|
+
ret[:enable_starttls_auto] = mail.smtp.enable_starttls_auto if mail.smtp.enable_starttls_auto?
|
28
|
+
ret[:openssl_verify_mode] = mail.smtp.openssl_verify_mode if mail.smtp.openssl_verify_mode?
|
29
|
+
ret[:authentication] = mail.smtp.authentication if mail.smtp.authentication?
|
30
|
+
ret[:user_name] = mail.smtp.username if mail.smtp.username?
|
31
|
+
ret[:password] = mail.smtp.password if mail.smtp.password?
|
32
|
+
ret
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Bizside
|
2
|
+
module Configurations
|
3
|
+
module Prefix
|
4
|
+
|
5
|
+
def prefix(ending_slash = false)
|
6
|
+
ret = ENV['X-BIZSIDE-PREFIX']
|
7
|
+
|
8
|
+
if ret.to_s.empty?
|
9
|
+
ret = self.prefix? ? self['prefix'] : '/'
|
10
|
+
end
|
11
|
+
|
12
|
+
if ret != '/'
|
13
|
+
if ending_slash
|
14
|
+
ret = ret + '/' unless ret.end_with?('/')
|
15
|
+
else
|
16
|
+
ret = ret[0..-2] if ret.end_with?('/')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
ret
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Bizside
|
2
|
+
module Configurations
|
3
|
+
module Storage
|
4
|
+
|
5
|
+
def storage
|
6
|
+
if @storage.nil?
|
7
|
+
configfile = ENV['STORAGE_CONFIG_FILE'] ? ENV['STORAGE_CONFIG_FILE'] : default_configfile
|
8
|
+
|
9
|
+
if File.exist?(configfile)
|
10
|
+
config = ERB.new(File.read(configfile), 0, '-').result
|
11
|
+
@storage = Bizside::Config.new(YAML.load(config)[Bizside.env])
|
12
|
+
else
|
13
|
+
@storage = Bizside::Config.new
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
@storage
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def default_configfile
|
23
|
+
File.join('config', 'aws.yml')
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Bizside
|
2
|
+
class CoverageLaunch
|
3
|
+
def self.setup
|
4
|
+
require 'simplecov'
|
5
|
+
require 'simplecov-rcov'
|
6
|
+
require_relative 'rcov_formatter'
|
7
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
|
8
|
+
SimpleCov::Formatter::HTMLFormatter,
|
9
|
+
Coverage::RcovFormatter
|
10
|
+
])
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
if ENV["COVERAGE"].to_s.downcase == 'true' and ENV['ACCEPTANCE_TEST'].to_s.downcase == 'true'
|
16
|
+
Bizside::CoverageLaunch.setup()
|
17
|
+
|
18
|
+
SimpleCov.start 'rails' do
|
19
|
+
SimpleCov.command_name(ENV['COMMAND_NAME']) if ENV['COMMAND_NAME']
|
20
|
+
SimpleCov.merge_timeout(7200)
|
21
|
+
end
|
22
|
+
elsif ENV["COVERAGE"]
|
23
|
+
Bizside::CoverageLaunch.setup()
|
24
|
+
SimpleCov.start 'rails'
|
25
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Coverage
|
2
|
+
class RcovFormatter < SimpleCov::Formatter::RcovFormatter
|
3
|
+
|
4
|
+
private
|
5
|
+
|
6
|
+
def write_file(template, output_filename, binding)
|
7
|
+
rcov_result = template.result( binding ).force_encoding('UTF-8')
|
8
|
+
File.open( output_filename, "w" ) do |file_result|
|
9
|
+
file_result.write rcov_result
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module Bizside
|
2
|
+
class CronValidator
|
3
|
+
MIN_MINUTE = 0
|
4
|
+
MAX_MINUTE = 59
|
5
|
+
MIN_HOUR = 0
|
6
|
+
MAX_HOUR = 23
|
7
|
+
MIN_DAY = 1
|
8
|
+
MAX_DAY = 31
|
9
|
+
MIN_MONTH = 1
|
10
|
+
MAX_MONTH = 12
|
11
|
+
MIN_WEEKDAY = 0
|
12
|
+
MAX_WEEKDAY = 7
|
13
|
+
CRON_ATTR = %w(minute hour day month weekday)
|
14
|
+
|
15
|
+
def initialize(cron)
|
16
|
+
@minute, @hour, @day, @month, @weekday = cron.split
|
17
|
+
end
|
18
|
+
|
19
|
+
def valid?
|
20
|
+
valid_minute? &&
|
21
|
+
valid_hour? &&
|
22
|
+
valid_day? &&
|
23
|
+
valid_month? &&
|
24
|
+
valid_weekday?
|
25
|
+
end
|
26
|
+
|
27
|
+
CRON_ATTR.each do |attr|
|
28
|
+
class_eval <<-EOS
|
29
|
+
private
|
30
|
+
|
31
|
+
def valid_#{attr}?
|
32
|
+
valid_format?(@#{attr}) &&
|
33
|
+
valid_range?(MIN_#{attr.upcase}, MAX_#{attr.upcase}, @#{attr})
|
34
|
+
end
|
35
|
+
EOS
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def valid_format?(value)
|
41
|
+
value =~ /\A(\*(\/\d+)?|\d+(,\d+)*(-\d+)*(\/\d+)*)\Z/
|
42
|
+
end
|
43
|
+
|
44
|
+
def valid_range?(min, max, value)
|
45
|
+
validate_values = remove_to_ignore_value(value).split(",")
|
46
|
+
validate_values.reject do |v|
|
47
|
+
if v.include?("-")
|
48
|
+
range_v = v.split("-")
|
49
|
+
(min..max).include?(range_v[0].to_i) &&
|
50
|
+
(min..max).include?(range_v[1].to_i) &&
|
51
|
+
range_v[0].to_i < range_v[1].to_i
|
52
|
+
else
|
53
|
+
(min..max).include? v.to_i
|
54
|
+
end
|
55
|
+
end.empty?
|
56
|
+
end
|
57
|
+
|
58
|
+
def remove_to_ignore_value(value)
|
59
|
+
value.gsub(/(\/\d*|\*)/, "")
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
raise LoadError.new('Cucumber関係は bizside_tools.gem に移行しました。 bizside/cucumber の替わりに bizisde_tools/cucumber を require してください')
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'rmagick'
|
2
|
+
|
3
|
+
module Bizside
|
4
|
+
module FileConverter
|
5
|
+
EXT_IMAGE = ['.gif', '.jpg', '.jpeg', '.png']
|
6
|
+
EXT_OFFICE = ['.doc', '.docx', '.ppt', '.pptx', '.xls', '.xlsx']
|
7
|
+
EXT_PDF = ['.pdf']
|
8
|
+
|
9
|
+
def self.convert_to_pdf(file)
|
10
|
+
dest = file.path + '.pdf'
|
11
|
+
|
12
|
+
case File.extname(file.path)
|
13
|
+
when *EXT_OFFICE
|
14
|
+
unless system("java -Xmx512m -jar /opt/jodconverter/lib/jodconverter-core.jar #{file.path} #{dest}")
|
15
|
+
raise "オフィス文書からPDFに変換できませんでした。file=#{file.path}"
|
16
|
+
end
|
17
|
+
when *EXT_PDF
|
18
|
+
unless system("cp #{file.path} #{dest}")
|
19
|
+
raise "PDFをコピーできませんでした。file=#{file.path}"
|
20
|
+
end
|
21
|
+
else
|
22
|
+
raise "サポートしていない拡張子です。file=#{file.path}"
|
23
|
+
end
|
24
|
+
|
25
|
+
File.new(dest)
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.convert_to_image(file)
|
29
|
+
|
30
|
+
case File.extname(file.path)
|
31
|
+
when *EXT_IMAGE
|
32
|
+
dest = file.path + File.extname(file.path)
|
33
|
+
unless system("cp #{file.path} #{dest}")
|
34
|
+
raise "画像をコピーできませんでした。file=#{file.path}"
|
35
|
+
end
|
36
|
+
ret = File.new(dest)
|
37
|
+
when *EXT_OFFICE
|
38
|
+
pdf = convert_to_pdf(file)
|
39
|
+
ret = convert_to_image(pdf)
|
40
|
+
when *EXT_PDF
|
41
|
+
dest = file.path + '.png'
|
42
|
+
images = Magick::ImageList.new(file.path) do
|
43
|
+
self.quality = 100
|
44
|
+
self.density = 96
|
45
|
+
end
|
46
|
+
images.first.write(dest)
|
47
|
+
ret = File.new(dest)
|
48
|
+
else
|
49
|
+
raise "サポートしていない拡張子です。file=#{file.path}"
|
50
|
+
end
|
51
|
+
|
52
|
+
ret
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'carrierwave'
|
2
|
+
require_relative 'carrierwave'
|
3
|
+
|
4
|
+
require_relative 'uploader/extension_whitelist'
|
5
|
+
require_relative 'uploader/filename_validator'
|
6
|
+
require_relative 'uploader/content_type_validator'
|
7
|
+
|
8
|
+
if defined?(Rails) && Rails.application.class.parent_name.eql?('BizsideTestApp')
|
9
|
+
# not require 'uploader/exif'
|
10
|
+
else
|
11
|
+
require_relative 'uploader/exif'
|
12
|
+
end
|
13
|
+
|
14
|
+
module Bizside
|
15
|
+
# === storage.yml
|
16
|
+
# storage.yml に fog エントリが定義されている場合、fog 参照先
|
17
|
+
# のストレージの fog.container に保存します。
|
18
|
+
#
|
19
|
+
# storage.yml が存在しない・又は fog エントリがない場合はローカルに保存します。
|
20
|
+
class FileUploader < CarrierWave::Uploader::Base
|
21
|
+
|
22
|
+
include Bizside::Uploader::ExtensionWhitelist
|
23
|
+
include Bizside::Uploader::FilenameValidator
|
24
|
+
include Bizside::Uploader::ContentTypeValidator
|
25
|
+
|
26
|
+
begin
|
27
|
+
require 'mini_magick'
|
28
|
+
include CarrierWave::MiniMagick
|
29
|
+
include Bizside::Uploader::Exif
|
30
|
+
rescue LoadError
|
31
|
+
begin
|
32
|
+
require 'rmagick'
|
33
|
+
include CarrierWave::RMagick
|
34
|
+
include Bizside::Uploader::Exif
|
35
|
+
rescue LoadError
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
if CarrierWave::SanitizedFile.sanitize_regexp != CARRIERWAVE_SANITIZE_REGEXP
|
40
|
+
raise 'CarrierWave::SanitizedFile.sanitize_regexpの変更は禁止されました。'
|
41
|
+
end
|
42
|
+
CarrierWave::SanitizedFile.sanitize_regexp = /[\n\r]/ # CarrierWaveに自動でサニタイズさせず、別途 filename_validator でチェックする
|
43
|
+
|
44
|
+
def downloaded_file
|
45
|
+
Bizside.config.storage.fog? ? downloaded_file_from_fog(file.path) : file.path
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def downloaded_file_from_fog(path)
|
51
|
+
Bizside.config.storage.fog.cache? ? download_file_from_fog_with_cache(path) : download_file_from_fog(path)
|
52
|
+
end
|
53
|
+
|
54
|
+
def download_file_from_fog(path)
|
55
|
+
tmp_path = "/tmp/#{Bizside.config.add_on_name}-#{Bizside::StringUtils.current_time_string}-#{File.basename(path)}"
|
56
|
+
system("curl '#{file.url}' -o '#{tmp_path}'")
|
57
|
+
tmp_path
|
58
|
+
end
|
59
|
+
|
60
|
+
def download_file_from_fog_with_cache(path)
|
61
|
+
cache_path = "/" + path
|
62
|
+
unless File.exist?(cache_path)
|
63
|
+
FileUtils.mkdir_p(File.dirname(cache_path))
|
64
|
+
tmp_path = download_file_from_fog(path)
|
65
|
+
system("mv '#{tmp_path}' '#{cache_path}'")
|
66
|
+
end
|
67
|
+
cache_path
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module Bizside
|
4
|
+
class Gengou
|
5
|
+
@@_gengou = YAML.load_file(File.join(File.dirname(__FILE__), 'gengou.yml'))
|
6
|
+
|
7
|
+
def self.to_seireki(gengou, year_jp)
|
8
|
+
# 引数 year_jpには年度の値が入る
|
9
|
+
target_gengou = nil
|
10
|
+
@@_gengou.invert.keys.each do |start_gengou|
|
11
|
+
if start_gengou == gengou.to_s
|
12
|
+
target_gengou = start_gengou
|
13
|
+
break
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
return nil unless target_gengou
|
18
|
+
|
19
|
+
start_year = @@_gengou.invert[target_gengou].to_s
|
20
|
+
return (start_year.to_i + year_jp.to_i - 1).to_s
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.to_wareki(date)
|
24
|
+
return if date.to_s.empty?
|
25
|
+
|
26
|
+
match = /^(\d{4})(\d{2})?(\d{2})?$/.match(date.to_s)
|
27
|
+
match ||= /^(\d{4})(?:[-\/](\d{1,2}))?(?:[-\/](\d{1,2}))?$/.match(date.to_s)
|
28
|
+
match ||= /^(\d{4})年(?:(\d{1,2})月)?(?:(\d{1,2})日)?$/.match(date.to_s)
|
29
|
+
if match
|
30
|
+
year, month, day = match.to_a[1..3].map { |m| m&.to_i }
|
31
|
+
return unless Date.valid_date?(year, month || 1, day || 1)
|
32
|
+
date = Date.new(year, month || 1, day || 1)
|
33
|
+
date = date.end_of_month if day.nil?
|
34
|
+
date = date.end_of_year if month.nil?
|
35
|
+
|
36
|
+
start_date, gengou = @@_gengou.sort { |a, b| b[0] <=> a[0] }.detect { |k, _| k <= date }
|
37
|
+
|
38
|
+
return if start_date.nil?
|
39
|
+
|
40
|
+
year = date.year - start_date.year
|
41
|
+
"#{gengou}#{(year.zero? ? "元" : year + 1)}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
module Bizside
|
5
|
+
# hanaita_conf をテストするため、 singleton 以前のクラスを定義
|
6
|
+
#
|
7
|
+
# TODO: ItamaeConf に移行が済んだ段階でこちらは削除。
|
8
|
+
class HanaitaConfSub
|
9
|
+
CONF_FILE = '/etc/bizside/hanaita.yml'
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
conf_file = ENV['HANAITA_CONF'] || CONF_FILE
|
13
|
+
@_conf = YAML.load_file(conf_file) if File.exist?(conf_file)
|
14
|
+
end
|
15
|
+
|
16
|
+
def conf
|
17
|
+
@_conf
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# /etc/bizside/hanaita.yml の on-memory モデル
|
22
|
+
#
|
23
|
+
# == SYNOPSIS
|
24
|
+
# require 'itamae_plugin_recipe_bizside'
|
25
|
+
# hanaita_conf(:a, :b, ...) # Or
|
26
|
+
# hanaita_conf('a.b...')
|
27
|
+
#
|
28
|
+
# == DESCRIPTION
|
29
|
+
# /etc/bizside/hanaita.yml の hash に対するキー検索を行います。
|
30
|
+
#
|
31
|
+
# ファイルが存在しない場合は nil を返します。
|
32
|
+
#
|
33
|
+
# hanaita_conf(:a, :b) は意味的に hanaita.yml のハッシュに対する
|
34
|
+
# アクセスhanaita_conf['a']['b'] と同等です。
|
35
|
+
#
|
36
|
+
# hanaita_conf(:a) が ハッシュでない場合(未定義または文字列や数値など)、
|
37
|
+
# hanaita_conf(:a, :b) は単に nil を返します('undefined method `[]'
|
38
|
+
# for nil:NilClass' とはなりません)。
|
39
|
+
#
|
40
|
+
# I18n#t と同様、'a.b' と言った文字列指定も可能です。
|
41
|
+
#
|
42
|
+
# == FILES
|
43
|
+
# /etc/bizside/hanaita.yml:: 設定ファイル
|
44
|
+
class HanaitaConf < HanaitaConfSub
|
45
|
+
include Singleton
|
46
|
+
end
|
47
|
+
|
48
|
+
# 各フェーズで hanaita_conf メソッド経由でアクセスできるようにするための
|
49
|
+
# ユーティリティ。node メソッドと同様。
|
50
|
+
module HanaitaConfAccessorMixin
|
51
|
+
# 必要に応じて上書き
|
52
|
+
def hanaita_conf_factory
|
53
|
+
Bizside::HanaitaConf.instance
|
54
|
+
end
|
55
|
+
|
56
|
+
def hanaita_conf(*args)
|
57
|
+
warn("DEPRECATED WARNING: 'hanaita_conf' is deprecated. " +
|
58
|
+
"Use 'itamae_conf' instead.")
|
59
|
+
if args.nil? || (args.is_a?(Array) && args[0].is_a?(Symbol) || args[0].nil?)
|
60
|
+
hanaita_conf_sub(hanaita_conf_factory.conf, args)
|
61
|
+
elsif args.is_a?(Array) && args[0].is_a?(String)
|
62
|
+
hanaita_conf_sub(hanaita_conf_factory.conf, args[0].split('.').map{|s| s.to_sym})
|
63
|
+
else
|
64
|
+
raise 'unsupported argument type'
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def hanaita_conf_sub(data, args)
|
71
|
+
if args.size == 0
|
72
|
+
data
|
73
|
+
elsif data.is_a?(Hash)
|
74
|
+
hanaita_conf_sub(data[args[0].to_s], args.drop(1))
|
75
|
+
else
|
76
|
+
nil
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def warn(msg)
|
81
|
+
if defined?(Rails) and Rails.logger
|
82
|
+
Rails.logger.warn(msg)
|
83
|
+
else
|
84
|
+
STDERR.print(msg, "\n")
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# https://github.com/bnix/double-bag-ftps/issues/17
|
2
|
+
# implicit に対応するためのパッチ
|
3
|
+
|
4
|
+
require 'net/ftp'
|
5
|
+
|
6
|
+
module Bizside
|
7
|
+
class ImplicitFTPS < Net::FTP
|
8
|
+
FTP_PORT = 990
|
9
|
+
|
10
|
+
def connect(host, port = FTP_PORT)
|
11
|
+
synchronize do
|
12
|
+
@host = host
|
13
|
+
@bare_sock = open_socket(host, port)
|
14
|
+
begin
|
15
|
+
ssl_sock = start_tls_session(Socket.tcp(host, port))
|
16
|
+
@sock = BufferedSSLSocket.new(ssl_sock, read_timeout: @read_timeout)
|
17
|
+
voidresp
|
18
|
+
if @private_data_connection
|
19
|
+
voidcmd("PBSZ 0")
|
20
|
+
voidcmd("PROT P")
|
21
|
+
end
|
22
|
+
rescue OpenSSL::SSL::SSLError, Net::OpenTimeout
|
23
|
+
@sock.close
|
24
|
+
raise
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|