class ShopifyGdpr::Generators::ShopifyGdprGenerator
generates basic GDPR endpoints
Public Instance Methods
create_endpoints()
click to toggle source
# File lib/generators/shopify_gdpr/shopify_gdpr_generator.rb, line 9 def create_endpoints create_file 'app/controllers/shopify_gdpr_controller.rb', "class ShopifyGdprController < ActionController::Base def shop_redact if params['shop_domain'].present? shop = Shop.find_by(shopify_domain: params['shop_domain']) shop.delete if !shop.nil? render json: '{\"message\": \"Success\"}', status: 200 else render json: '{\"message\": \"Bad Request\"}', status: 400 end end def customers_redact if params['customer'].present? render json: '{\"message\": \"Success\"}', status: 200 else render json: '{\"message\": \"Bad Request\"}', status: 400 end end def customers_data_request if params['customer'].present? puts params render json: '{\"message\": \"Success\"}', status: 200 else render json: '{\"message\": \"Bad Request\"}', status: 400 end end end" create_routes if options.validate? add_validator inject_into_file 'app/controllers/shopify_gdpr_controller.rb', after: "class ShopifyGdprController < ActionController::Base\n" do <<-'RUBY' include ShopifyApp::WebhookVerification RUBY end end end
Private Instance Methods
add_validator()
click to toggle source
# File lib/generators/shopify_gdpr/shopify_gdpr_generator.rb, line 59 def add_validator create_file 'lib/webhook_verification.rb', "module ShopifyApp module WebhookVerification extend ActiveSupport::Concern included do skip_before_action :verify_authenticity_token, raise: false before_action :verify_request end private def verify_request data = request.raw_post return head :unauthorized unless hmac_valid?(data) end def hmac_valid?(data) secret = ShopifyApp.configuration.secret digest = OpenSSL::Digest.new('sha256') ActiveSupport::SecurityUtils.secure_compare( shopify_hmac, Base64.encode64(OpenSSL::HMAC.digest(digest, secret, data)).strip ) end def shop_domain request.headers['HTTP_X_SHOPIFY_SHOP_DOMAIN'] end def shopify_hmac request.headers['HTTP_X_SHOPIFY_HMAC_SHA256'] end end end " end
create_routes()
click to toggle source
# File lib/generators/shopify_gdpr/shopify_gdpr_generator.rb, line 53 def create_routes route "post 'shop_redact', to: 'shopify_gdpr#shop_redact'" route "post 'customers_redact', to: 'shopify_gdpr#customers_redact'" route "post 'customers_data_request', to: 'shopify_gdpr#customers_data_request'" end