Skip to content

Commit 5b78cf5

Browse files
Merge pull request #6 from PaystackOSS/autogen/ruby-sdk/57c9087
chore(ruby-sdk): sync generated dist from 57c9087
2 parents 8de187b + 50b28eb commit 5b78cf5

4 files changed

Lines changed: 50 additions & 0 deletions

File tree

lib/paystack/base_resource.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,13 @@ def self.new(transport)
99
instance.instance_variable_set(:@transport, transport)
1010
instance
1111
end
12+
13+
def inspect
14+
@transport.inspect
15+
end
16+
17+
def to_s
18+
@transport.to_s
19+
end
1220
end
1321
end

lib/paystack/client.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,5 +142,13 @@ def virtual_terminal
142142
@virtual_terminal ||= Resources::VirtualTerminal.new(@transport)
143143
end
144144

145+
146+
def inspect
147+
@transport.inspect
148+
end
149+
150+
def to_s
151+
@transport.to_s
152+
end
145153
end
146154
end

lib/paystack/transport.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,23 @@ def ssl_options
6060
read_timeout: 30
6161
}
6262
end
63+
64+
def masked_api_key
65+
visible_prefix = 8
66+
visible_suffix = 4
67+
return "[key too short to mask]" if @api_key.nil? || @api_key.length <= visible_prefix + visible_suffix
68+
69+
"#{@api_key[0, visible_prefix]}#{"*" * 8}#{@api_key[-visible_suffix, visible_suffix]}"
70+
end
71+
72+
public
73+
74+
def inspect
75+
"#<#{self.class.name} api_key=#{masked_api_key.inspect}>"
76+
end
77+
78+
def to_s
79+
inspect
80+
end
6381
end
6482
end

test/paystack/client_test.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,4 +251,20 @@ def test_memoizes_virtual_terminal_resource
251251
assert_same @client.virtual_terminal, @client.virtual_terminal
252252
end
253253

254+
255+
def test_inspect_masks_the_api_key
256+
key = "sk_test_abcdefghijklmnopqrstuvwxyz"
257+
client = Paystack::Client.new(key)
258+
259+
refute_includes client.inspect, key
260+
assert_includes client.inspect, key[0, 8]
261+
assert_includes client.inspect, key[-4, 4]
262+
end
263+
264+
def test_to_s_masks_the_api_key
265+
key = "sk_test_abcdefghijklmnopqrstuvwxyz"
266+
client = Paystack::Client.new(key)
267+
268+
refute_includes client.to_s, key
269+
end
254270
end

0 commit comments

Comments
 (0)