RailsでGoogle+シャットダウンに伴うGoogle Sign-in対応
[Action Required] Google+ APIs and OAuth requests are being shutdown on March 7, 2019というメールが来ていた。会社でGoogle Sign-Inを使っているので、影響があるかどうか調べて、変更を行った。
まずは、APIコンソールで確認。
Google+ APIをある程度の頻度で叩いてるので、変更が必要と認識。
Sign-Inに使用しているのGemは、omniauth-google-oauth2
でgithub issueを探ると最新バージョンではGoogle+ dependencyはないとのこと。したがって、さっそくバージョンアップグレード。
bundle update omniauth-google-oauth2
Gemfile.lockを確認すると最新バージョンが入っていない。jwtのバージョンが古いことに起因しているようだ。
bundle update google-api-client
もうひとつサインインではないが、関係のありそうなgoogle-api-client(主にCalendar APIに利用)のバージョンを上げて、jwtが2.0以上になったことを確認。
もう一度、bundle update omniauth-google-oauth2
で最新にするもうまくいってなさそうなので、Gemfileにバージョン指定。
gem "omniauth-google-oauth2", '~>0.6'
bundle installして最新のもになってのを確認。
問題の切り分けに新しいプロジェクトをconsole APIに作り、tokenなどを作成し、テスト後、問題がなかったので本番環境にデプロイした。
数時間後、APIコンソールでgoogle+を叩いていないことを確認し、Google+シャットダウンに伴うGoogle Sign-inの対応完了。
所感:Googleに振り回れるがつらい。Hangoutも消えそうな気がするし。。
[AWS] EFSのマウント方法
EFSのルートを/etc/letsencryptをマウントする方法は、
1. パッケージのインストール (Ubuntuの場合)
# apt-get -y install nfs-common
2. 下記を/etc/fstabに記述する
YOUR_EFS.efs.ap-northeast-1.amazonaws.com:/ /etc/letsencrypt nfs4 nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,_netdev 0 0
3. セキュリティグループの作成
EFSサイドは2049 inboundをオープン。EC2側は2049のoutboundをオープン(outboundは基本全オープンだと思う)
4. 該当ディレクトリを作成し、fstabのReload
# mkdir /etc/letsencrpyt # mount -a
[Rails][JQuery]いつも忘れるDynamic select options
結構な頻度で書く依存型セレクトボックス。毎回自力で書いてるような気がするのでログしておく。
<div class="field"> <%= form.label :region %> <%= form.select :region, options_for_select([ 'us-west-2', 'us-west-1', 'us-east-2', 'us-east-1', 'ap-south-1', 'ap-northeast-2', 'ap-southeast-1', 'ap-southeast-2', 'ap-northeast-1', 'ca-central-1', 'cn-north-1', 'eu-central-1', 'eu-west-1', 'eu-west-2', 'eu-west-3', 'sa-east-1' ]), {include_blank: true}, required: true %> </div> <div class="field"> <%= form.label :availability_zone %> <%= form.select :availability_zone, {}, required: true %> </div> <script> $("#storage_region").change(function(){ var region = $(this).val(); var $saz = $('#storage_availability_zone'); $.get("/api/v1/aws_availability_zones?region="+region, function(zones){ $saz.empty(); zones.forEach(function(zone){ $('<option>').val(zone).text(zone).appendTo($saz) }) }); }) </script>
ruby/railsでEBS volumeを作る方法
AWS version3でebs volumeを作るのはドキュメント通り。
def create_volume begin resp = ec2_client.create_volume({ availability_zone: self.availability_zone, size: self.size, volume_type: "gp2" }) logger.debug resp self.update(volume_id: resp.volume_id) rescue => error logger.error error.inspect false end end def delete_volume begin resp = ec2_client.delete_volume({ volume_id: self.volume_id }) logger.debug resp self.destroy rescue => error logger.error error.inspect false end end def ec2_client @client ||= Aws::EC2::Client.new(region: self.region) # "ap-northeast-1" end def region "ap-northeast-1" end