File tree 2 files changed +41
-0
lines changed
2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ module OpenAI
2
2
class Client
3
3
include OpenAI ::HTTP
4
4
5
+ SENSITIVE_ATTRIBUTES = %i[ @access_token @organization_id @extra_headers ] . freeze
5
6
CONFIG_KEYS = %i[
6
7
api_type
7
8
api_version
@@ -107,5 +108,15 @@ def beta(apis)
107
108
client . add_headers ( "OpenAI-Beta" : apis . map { |k , v | "#{ k } =#{ v } " } . join ( ";" ) )
108
109
end
109
110
end
111
+
112
+ def inspect
113
+ vars = instance_variables . map do |var |
114
+ value = instance_variable_get ( var )
115
+
116
+ SENSITIVE_ATTRIBUTES . include? ( var ) ? "#{ var } =[REDACTED]" : "#{ var } =#{ value . inspect } "
117
+ end
118
+
119
+ "#<#{ self . class } :#{ object_id } #{ vars . join ( ', ' ) } >"
120
+ end
110
121
end
111
122
end
Original file line number Diff line number Diff line change 133
133
expect ( connection . builder . handlers ) . to include Faraday ::Response ::Logger
134
134
end
135
135
end
136
+
137
+ context "when calling inspect" do
138
+ let ( :api_key ) { "sk-123456789" }
139
+ let ( :organization_id ) { "org-123456789" }
140
+ let ( :extra_headers ) { { "Other-Auth" : "key-123456789" } }
141
+ let ( :uri_base ) { "https://example.com/" }
142
+ let ( :request_timeout ) { 500 }
143
+ let ( :client ) do
144
+ OpenAI ::Client . new (
145
+ uri_base : uri_base ,
146
+ request_timeout : request_timeout ,
147
+ access_token : api_key ,
148
+ organization_id : organization_id ,
149
+ extra_headers : extra_headers
150
+ )
151
+ end
152
+
153
+ it "does not expose sensitive information" do
154
+ expect ( client . inspect ) . not_to include ( api_key )
155
+ expect ( client . inspect ) . not_to include ( organization_id )
156
+ expect ( client . inspect ) . not_to include ( extra_headers [ :"Other-Auth" ] )
157
+ end
158
+
159
+ it "does expose non-sensitive information" do
160
+ expect ( client . inspect ) . to include ( uri_base . inspect )
161
+ expect ( client . inspect ) . to include ( request_timeout . inspect )
162
+ expect ( client . inspect ) . to include ( client . object_id . to_s )
163
+ expect ( client . inspect ) . to include ( client . class . to_s )
164
+ end
165
+ end
136
166
end
You can’t perform that action at this time.
0 commit comments