最後にサインアウトした時間が欲しい


before_logoutというwardenのフックメソッドがあるのでそこに追加
自分はconfig/initializers/devise.rbに追加しちゃいました。

1
2
3
4
5
Warden::Manager.before_logout do |user,auth,opts|
  if user.is_a?(User)
    user.update_column(:current_sign_out_at, Time.current)
  end
end


GrapeでCSRF対策

セキュリティ試験を受けたらapiでpostしている箇所がcsrf違反でレポートが上がってきました。
apiでcsrfって必要なの?
って感じでしたが実際にレポートあがってきてしまっているしよくよく考えたら必要じゃんってなったので実装します。

ググってみると情報が少ないですね。
みなさんgrapeでcsrfどうしているんでしょう。

Read on →

Doorkeeperの認証で使われるtokenを取得

doorkeeprの処理のなかで削除済のユーザのステータスが取りたくて、tokenを取得できるかやってみました。

イレギュラーアクセス -> tokenが取れない。
通常のアクセス -> tokenが取れる。ユーザがひける。
削除済または退会済みユーザへのアクセス -> tokenが取れる。ユーザがひけない。

って感じでしょうか?

Read on →

S3に直接にファイルアップロード

Herokuでの大きいファイルアップロードはリクエストタイムアウトが30秒に設定されているのでやっかいです。

Herokuの公式でも4MBを超えるファイルをあげる場合はS3に直接あげてねって書いてあります。
https://devcenter.heroku.com/articles/s3#direct-upload

1
This is the preferred approach if you’re working with file uploads bigger than 4MB. The idea is to skip the hop to your dyno, making a direct connection from the end user browser to S3. While this reduces the processing required by your application it is a more complex implementation and limits the ability to modify (transform, filter, resize etc…) the file before storing in S3.

carriwaveを使っているのでcarriwave_directいいなと思いましたが、
carrierwave_direct

最終更新日が結構前でメンテされていないのかな?ってのとgemを使いすぎるとわけわかめになるので自力でやることにしました。

Read on →

carrierwaveのリンクの有効期間を個別に設定

全体でかける場合はこうですかね。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# config/initializers/carrierwave.rb
CarrierWave::SanitizedFile.sanitize_regexp = /[^[:word:]\.\-\+]/ # for Japanese
CarrierWave.configure do |config|
  config.fog_credentials = {
    provider:              'AWS',
    aws_access_key_id:     ENV[:access_key],
    aws_secret_access_key: ENV[:secret],
    region:                ENV['s3_region']
  }

  config.fog_public = false
  config.fog_directory = Settings.aws['s3_bucket']
  config.cache_storage = :fog
  config.fog_authenticated_url_expiration = 1.minutes.to_i
end
Read on →


国際化対応(お金関連)

国際化対応。
DBの日時はutcで保存して表示する時にユーザによって該当のタイムゾーンで表示とか色々な知見はあるかと思いますが。
お金の区切りもあるんですね。

Read on →


CircleCIでRuby2.5使おうとしたらbad interpreter

一度は成功していたのに急にCircleCI 1.0がこけるようになってしまいました。

1
set ruby version to 2.5.0  

1
2
3
ruby-2.5.0 - #generating default wrappers|/-\|/-\|.-\|/-\|/-.|/-\|/-\|.-\|/-\|/-.|/-\|/-\|.-\|/-\|/-.|/-\|/-\|.-\|/-\|.  
Using /home/ubuntu/.rvm/gems/ruby-2.5.0  
/home/ubuntu/.rvm/scripts/override_gem: /home/ubuntu/.rvm/rubies/ruby-2.5.0/bin/gem: /home/travis/.rvm/rubies/ruby-2.5.0/bin/ruby: bad interpreter: No such file or directory  

のようなエラー。

Read on →