Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
stripe-checkout
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
geant-swd
stripe-checkout
Commits
c90d90d9
Commit
c90d90d9
authored
5 months ago
by
Pelle Koster
Browse files
Options
Downloads
Patches
Plain Diff
add missing file
parent
8db3a32a
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
stripe_checkout/stripe_checkout/utils.py
+39
-0
39 additions, 0 deletions
stripe_checkout/stripe_checkout/utils.py
with
39 additions
and
0 deletions
stripe_checkout/stripe_checkout/utils.py
0 → 100644
+
39
−
0
View file @
c90d90d9
import
functools
from
django.conf
import
settings
from
django.http
import
HttpResponseForbidden
ALLOW_ALL
=
"
*
"
def
whitelist_ips
(
func
=
None
,
by_setting
=
None
):
if
not
func
:
return
functools
.
partial
(
whitelist_ips
,
by_setting
=
by_setting
)
@functools.wraps
(
func
)
def
_whitelisted_view
(
request
):
allowed_ips
=
_read_whitelist_setting
(
by_setting
,
[
ALLOW_ALL
])
if
not
allowed_ips
&
{
ALLOW_ALL
,
get_client_ip
(
request
)}:
return
HttpResponseForbidden
(
"
forbidden
"
)
return
func
(
request
)
return
_whitelisted_view
def
_read_whitelist_setting
(
setting
:
str
,
default
=
None
)
->
set
[
str
]:
result
=
getattr
(
settings
,
setting
,
default
)
assert
isinstance
(
result
,
list
)
and
all
(
isinstance
(
s
,
str
)
for
s
in
result
),
f
"
{
setting
}
must be a list of strings
"
return
set
(
result
)
def
get_client_ip
(
request
):
# cf. https://stackoverflow.com/a/4581997
x_forwarded_for
=
request
.
META
.
get
(
"
HTTP_X_FORWARDED_FOR
"
)
if
x_forwarded_for
:
ip
=
x_forwarded_for
.
split
(
"
,
"
)[
0
]
else
:
ip
=
request
.
META
.
get
(
"
REMOTE_ADDR
"
)
return
ip
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment