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
Merge requests
!42
Добавлен общий код PerxisDataProvider, GrpcChannel и моделей
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Добавлен общий код PerxisDataProvider, GrpcChannel и моделей
feature/add-shared-code-of-data-providers
into
master
Overview
0
Commits
2
Pipelines
0
Changes
4
Merged
Podosochnyy Maxim
requested to merge
feature/add-shared-code-of-data-providers
into
master
1 year ago
Overview
0
Commits
2
Pipelines
0
Changes
3
Expand
https://tracker.yandex.ru/AUTO-1373
review
@teplyakov
0
0
Merge request reports
Viewing commit
62321c44
Prev
Next
Show latest version
3 files
+
285
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
3
Search (e.g. *.vue) (Ctrl+P)
62321c44
Добавлен общий код PerxisDataProvider, GrpcChannel и моделей
· 62321c44
Podosochnyy Maxim
authored
1 year ago
perxis/channel.py
0 → 100644
+
57
−
0
Options
from
typing
import
Optional
import
grpc
from
perxis.auth
import
APIKeyPlugin
from
perxis.models
import
PerxisEnviron
class
GrpcChannel
:
call_credentials
:
grpc
.
CallCredentials
channel_credentials
:
grpc
.
ChannelCredentials
composite_credentials
:
grpc
.
ChannelCredentials
channel
:
Optional
[
grpc
.
Channel
]
=
None
def
__init__
(
self
,
target
:
str
,
metadata_plugin
:
grpc
.
AuthMetadataPlugin
,
project_name
:
str
,
project_version
:
str
,
call_credentials_name
:
str
=
"
api-key
"
,
)
->
None
:
self
.
target
=
target
self
.
metadata_plugin
=
metadata_plugin
self
.
call_credentials_name
=
call_credentials_name
self
.
_init_credentials
()
self
.
connect
(
project_name
,
project_version
)
def
_init_credentials
(
self
)
->
None
:
self
.
call_credentials
=
grpc
.
metadata_call_credentials
(
self
.
metadata_plugin
,
name
=
self
.
call_credentials_name
)
self
.
channel_credentials
=
grpc
.
ssl_channel_credentials
()
self
.
composite_credentials
=
grpc
.
composite_channel_credentials
(
self
.
channel_credentials
,
self
.
call_credentials
)
def
connect
(
self
,
project_name
:
str
,
project_version
:
str
)
->
None
:
if
not
self
.
channel
:
self
.
channel
=
grpc
.
aio
.
secure_channel
(
self
.
target
,
self
.
composite_credentials
,
options
=
(
(
"
grpc.primary_user_agent
"
,
f
"
{
project_name
}
/
{
project_version
}
"
),
)
)
async
def
close
(
self
)
->
None
:
await
self
.
channel
.
close
()
def
get_grpc_channel
(
perxis_environ
:
PerxisEnviron
,
project_name
:
str
,
project_version
:
str
)
->
GrpcChannel
:
return
GrpcChannel
(
target
=
perxis_environ
.
target
,
metadata_plugin
=
APIKeyPlugin
(
token
=
perxis_environ
.
api_key
),
project_name
=
project_name
,
project_version
=
project_version
)
Loading