Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
perxis-python
Manage
Activity
Members
Labels
Plan
Issues
3
Issue boards
Milestones
Wiki
Custom issue tracker
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
perxis
perxis-python
Commits
eb0e5fe8
Commit
eb0e5fe8
authored
3 years ago
by
Georgiy Eterevskiy
Browse files
Options
Downloads
Patches
Plain Diff
Add plugin `Api-Key` for auth
parent
5468e6f2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!13
Add plugin `Api-Key` for auth
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/auth_api_key.py
+29
-0
29 additions, 0 deletions
examples/auth_api_key.py
perxis/auth.py
+13
-0
13 additions, 0 deletions
perxis/auth.py
with
42 additions
and
0 deletions
examples/auth_api_key.py
0 → 100644
+
29
−
0
View file @
eb0e5fe8
import
logging
import
grpc
from
perxis.auth
import
APIKeyPlugin
from
perxis.collections
import
collections_pb2_grpc
,
collections_pb2
API_KEY
=
'
0Xp7bYBqYmIUqwZcNRMtRCtDBaheFdAc
'
SPACE_ID
=
'
c2qcp9cuaccmpj8lmom0
'
ENV_ID
=
'
master
'
TARGET
=
'
envoy.perxis.pt.perx.ru:443
'
def
main
():
api_key_plugin
=
APIKeyPlugin
(
API_KEY
)
call_credentials
=
grpc
.
metadata_call_credentials
(
api_key_plugin
,
name
=
'
api-key
'
)
channel_credentials
=
grpc
.
ssl_channel_credentials
()
composite_credentials
=
grpc
.
composite_channel_credentials
(
channel_credentials
,
call_credentials
)
with
grpc
.
secure_channel
(
TARGET
,
composite_credentials
)
as
channel
:
stub
=
collections_pb2_grpc
.
CollectionsStub
(
channel
)
collections
=
stub
.
List
(
collections_pb2
.
ListRequest
(
space_id
=
SPACE_ID
,
env_id
=
ENV_ID
))
print
(
collections
)
if
__name__
==
'
__main__
'
:
logging
.
basicConfig
(
level
=
logging
.
INFO
)
main
()
This diff is collapsed.
Click to expand it.
perxis/auth.py
+
13
−
0
View file @
eb0e5fe8
...
@@ -50,3 +50,16 @@ class OAuth2Plugin(grpc.AuthMetadataPlugin):
...
@@ -50,3 +50,16 @@ class OAuth2Plugin(grpc.AuthMetadataPlugin):
self
.
_token
=
fetch_token
()
self
.
_token
=
fetch_token
()
return
self
.
_token
return
self
.
_token
class
APIKeyPlugin
(
grpc
.
AuthMetadataPlugin
):
_token
=
None
def
__init__
(
self
,
token
:
str
,
signature_header_key
:
str
=
'
authorization
'
,
token_type
:
str
=
'
API-Key
'
)
->
None
:
self
.
_token
=
token
self
.
_signature_header_key
=
signature_header_key
self
.
_token_type
=
token_type
def
__call__
(
self
,
context
:
grpc
.
AuthMetadataContext
,
callback
:
grpc
.
AuthMetadataPluginCallback
)
->
None
:
callback
(((
self
.
_signature_header_key
,
f
'
{
self
.
_token_type
}
{
self
.
_token
}
'
),),
None
)
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