FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
passkit-python-quickstart/shared/grpcConnection.py at main · PassKit/passkit-python-quickstart · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
PassKit
/
passkit-python-quickstart
Public
Notifications
You must be signed in to change notification settings
Fork
6
Star
7
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
passkit-python-quickstart
/
shared
/
grpcConnection.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
58 lines (47 loc) · 1.87 KB
Breadcrumbs
passkit-python-quickstart
/
shared
/
grpcConnection.py
Copy path
File metadata and controls
58 lines (47 loc) · 1.87 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# shared/grpcConnection.py
from
dataclasses
import
dataclass
from
typing
import
Tuple
import
grpc
import
constants
from
passkit
.
io
.
member
import
a_rpc_pb2_grpc
as
member_grpc
from
passkit
.
io
.
single_use_coupons
import
a_rpc_pb2_grpc
as
coupons_grpc
from
passkit
.
io
.
core
import
a_rpc_templates_pb2_grpc
as
templates_grpc
from
passkit
.
io
.
event_tickets
import
a_rpc_pb2_grpc
as
events_grpc
from
passkit
.
io
.
flights
import
a_rpc_pb2_grpc
as
flights_grpc
@
dataclass
class
Stubs
:
members
:
member_grpc
.
MembersStub
coupons
:
coupons_grpc
.
SingleUseCouponsStub
events
:
events_grpc
.
EventTicketsStub
flights
:
flights_grpc
.
FlightsStub
templates
:
templates_grpc
.
TemplatesStub
def
_load_certs
()
->
Tuple
[
bytes
,
bytes
,
bytes
]:
with
open
(
constants
.
CA_FILE
,
"rb"
)
as
f
:
ca
=
f
.
read
()
with
open
(
constants
.
CERT_FILE
,
"rb"
)
as
f
:
cert
=
f
.
read
()
with
open
(
constants
.
KEY_FILE
,
"rb"
)
as
f
:
key
=
f
.
read
()
return
ca
,
cert
,
key
def
create_channel
()
->
grpc
.
Channel
:
ca
,
cert
,
key
=
_load_certs
()
creds
=
grpc
.
ssl_channel_credentials
(
root_certificates
=
ca
,
private_key
=
key
,
certificate_chain
=
cert
,
)
# Optional channel options (keepalive etc.) can go here if needed
return
grpc
.
secure_channel
(
constants
.
GRPC_HOST
,
creds
)
def
create_stubs
(
channel
:
grpc
.
Channel
)
->
Stubs
:
"""Build all commonly used stubs for a given channel."""
return
Stubs
(
members
=
member_grpc
.
MembersStub
(
channel
),
coupons
=
coupons_grpc
.
SingleUseCouponsStub
(
channel
),
events
=
events_grpc
.
EventTicketsStub
(
channel
),
flights
=
flights_grpc
.
FlightsStub
(
channel
),
templates
=
templates_grpc
.
TemplatesStub
(
channel
),
)
def
connect
()
->
Tuple
[
grpc
.
Channel
,
Stubs
]:
"""Return a secure channel and all service stubs (single-channel workflow)."""
channel
=
create_channel
()
return
channel
,
create_stubs
(
channel
)
Back
|
FazBrowse Home
|
New Git URL