This repository was archived by the owner on Mar 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathamazon-auth-proxy.rb
More file actions
57 lines (51 loc) · 1.44 KB
/
amazon-auth-proxy.rb
File metadata and controls
57 lines (51 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#
# amazon-auth-proxy for sinatra
#
# Copyright (C) 2011 TADA Tadashi <t@tdtds.jp>
# You can redistribute it and/or modify it under GPL.
#
load 'amazon-auth-proxy.cgi'
require 'yaml'
require 'sinatra/base'
class AmazonAuthProxyApp < Sinatra::Base
def initialize
@conf = YAML::load_file( 'amazon-auth-proxy.yaml' )
super
end
def make_conf( country )
conf = {}
conf['access_key'] = ENV['AMAZON_ACCESS_KEY'] || @conf['access_key']
conf['secret_key'] = ENV['AMAZON_SECRET_KEY'] || @conf['secret_key']
conf['entry_point'] = @conf['entry_point'][country]
conf['xslt_entry_point'] = @conf['xslt_entry_point'][country]
conf['default_aid'] = @conf['aid'][country]
conf['use_redirect'] = true
conf
end
get '/' do
return "access to #{@conf['aid'].keys.map{|a| "/#{a}/"}.join(', ')} with query for Amazon."
end
get '/*/' do
country = params[:splat][0]
return 400, "400 Bad request: '#{country}' not supported." unless @conf['aid'].keys.index( country )
aparams = {}
params.each do |k, v|
aparams[k] = [v] unless k == 'splat'
end
begin
status, body = paapi( make_conf( country ), aparams )
rescue ArgumentError
return 400, "400 Bad request: #{$!}"
end
redirect body, 302
end
get '/rpaproxy.yaml' do
#yaml = "locales:\n"
#yaml << @conf['aid'].keys.map{|a| " - #{a}\n"}.join
yaml = {
'name' => @conf['name'],
'locales' => @conf['aid'].keys
}.to_yaml
return 200, {'Content-Type' => 'text/yaml'}, yaml
end
end