@@ -18,6 +18,11 @@ class << self
18
18
def self . configure
19
19
self . configuration ||= Configuration . new
20
20
yield ( configuration ) if block_given?
21
+ configuration . verify!
22
+ end
23
+
24
+ def self . configured?
25
+ self . configuration &.configured?
21
26
end
22
27
23
28
class Configuration
@@ -27,11 +32,24 @@ class Configuration
27
32
:private_p12_certificate ,
28
33
:apple_intermediate_certificate ,
29
34
:apple_team_identifier ,
30
- :pass_type_identifier
35
+ :pass_type_identifier ,
36
+ :dashboard_username ,
37
+ :dashboard_password ,
38
+ :format_version ,
39
+ :skip_verification
40
+
41
+ REQUIRED_ATTRIBUTES = %i[
42
+ web_service_host
43
+ certificate_key
44
+ private_p12_certificate
45
+ apple_intermediate_certificate
46
+ apple_team_identifier
47
+ pass_type_identifier
48
+ ]
31
49
32
50
DEFAULT_AUTHENTICATION = proc do
33
51
authenticate_or_request_with_http_basic ( "Passkit Dashboard. Login required" ) do |username , password |
34
- username == ENV [ "PASSKIT_DASHBOARD_USERNAME" ] && password == ENV [ "PASSKIT_DASHBOARD_PASSWORD" ]
52
+ username == Passkit . configuration . dashboard_username && password == Passkit . configuration . dashboard_password
35
53
end
36
54
end
37
55
def authenticate_dashboard_with ( &block )
@@ -40,14 +58,34 @@ def authenticate_dashboard_with(&block)
40
58
end
41
59
42
60
def initialize
43
- @available_passes = { "Passkit::ExampleStoreCard" => -> { } }
44
- @web_service_host = ENV [ "PASSKIT_WEB_SERVICE_HOST" ] || ( raise "Please set PASSKIT_WEB_SERVICE_HOST" )
45
- raise ( "PASSKIT_WEB_SERVICE_HOST must start with https://" ) unless @web_service_host . start_with? ( "https://" )
46
- @certificate_key = ENV [ "PASSKIT_CERTIFICATE_KEY" ] || ( raise "Please set PASSKIT_CERTIFICATE_KEY" )
47
- @private_p12_certificate = ENV [ "PASSKIT_PRIVATE_P12_CERTIFICATE" ] || ( raise "Please set PASSKIT_PRIVATE_P12_CERTIFICATE" )
48
- @apple_intermediate_certificate = ENV [ "PASSKIT_APPLE_INTERMEDIATE_CERTIFICATE" ] || ( raise "Please set PASSKIT_APPLE_INTERMEDIATE_CERTIFICATE" )
49
- @apple_team_identifier = ENV [ "PASSKIT_APPLE_TEAM_IDENTIFIER" ] || ( raise "Please set PASSKIT_APPLE_TEAM_IDENTIFIER" )
50
- @pass_type_identifier = ENV [ "PASSKIT_PASS_TYPE_IDENTIFIER" ] || ( raise "Please set PASSKIT_PASS_TYPE_IDENTIFIER" )
61
+ # Required
62
+ @certificate_key = ENV [ "PASSKIT_CERTIFICATE_KEY" ]
63
+ @private_p12_certificate = ENV [ "PASSKIT_PRIVATE_P12_CERTIFICATE" ]
64
+ @apple_intermediate_certificate = ENV [ "PASSKIT_APPLE_INTERMEDIATE_CERTIFICATE" ]
65
+ @apple_team_identifier = ENV [ "PASSKIT_APPLE_TEAM_IDENTIFIER" ]
66
+ @pass_type_identifier = ENV [ "PASSKIT_PASS_TYPE_IDENTIFIER" ]
67
+
68
+ # Optional
69
+ @skip_verification = false
70
+ @web_service_host = ENV [ "PASSKIT_WEB_SERVICE_HOST" ] || "https://localhost:3000"
71
+ @available_passes = { "Passkit::ExampleStoreCard" => -> { } }
72
+ @format_version = ENV [ "PASSKIT_FORMAT_VERSION" ] || 1
73
+ @dashboard_username = ENV [ "PASSKIT_DASHBOARD_USERNAME" ]
74
+ @dashboard_password = ENV [ "PASSKIT_DASHBOARD_PASSWORD" ]
75
+ end
76
+
77
+ def configured?
78
+ REQUIRED_ATTRIBUTES . all? { |attr | send ( attr ) . present? }
79
+ end
80
+
81
+ def verify!
82
+ return if skip_verification
83
+
84
+ REQUIRED_ATTRIBUTES . each do |attr |
85
+ raise Error , "Please set #{ attr . upcase } " unless send ( attr ) . present?
86
+ end
87
+
88
+ raise Error , "PASSKIT_WEB_SERVICE_HOST must start with https://" unless web_service_host . start_with? ( "https://" )
51
89
end
52
90
end
53
91
end
0 commit comments