Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
perxis-go
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package Registry
Operate
Terraform modules
Analyze
Contributor 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-go
Commits
0e087c64
Commit
0e087c64
authored
1 year ago
by
Alena Petraki
Browse files
Options
Downloads
Patches
Plain Diff
Добавлена функция для получения TLS TransportCredentials
parent
66b02b9a
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
pkg/auth/grpc.go
+10
-1
10 additions, 1 deletion
pkg/auth/grpc.go
with
10 additions
and
1 deletion
pkg/auth/grpc.go
+
10
−
1
View file @
0e087c64
...
...
@@ -131,6 +131,15 @@ func WithOAuth2Credentials(ctx context.Context, tokenURL, clientID, clientSecret
// WithTLSCredentials возвращает опции для создания grpc-соединения с TLS-сертификатами
func
WithTLSCredentials
(
ctx
context
.
Context
,
cert
,
cacert
,
key
[]
byte
)
(
grpc
.
DialOption
,
error
)
{
creds
,
err
:=
TLSCredentials
(
ctx
,
cert
,
cacert
,
key
)
if
err
!=
nil
{
return
nil
,
err
}
return
grpc
.
WithTransportCredentials
(
creds
),
nil
}
// TLSCredentials возвращает TransportCredentials для создания grpc-соединения с TLS-сертификатами
func
TLSCredentials
(
ctx
context
.
Context
,
cert
,
cacert
,
key
[]
byte
)
(
credentials
.
TransportCredentials
,
error
)
{
certPool
:=
x509
.
NewCertPool
()
if
!
certPool
.
AppendCertsFromPEM
(
cacert
)
{
return
nil
,
errors
.
New
(
"CA certificate not loaded"
)
...
...
@@ -139,5 +148,5 @@ func WithTLSCredentials(ctx context.Context, cert, cacert, key []byte) (grpc.Dia
if
err
!=
nil
{
return
nil
,
err
}
return
grpc
.
WithTransportCredentials
(
credentials
.
NewTLS
(
&
tls
.
Config
{
Certificates
:
[]
tls
.
Certificate
{
clientCert
},
RootCAs
:
certPool
})
)
,
nil
return
credentials
.
NewTLS
(
&
tls
.
Config
{
Certificates
:
[]
tls
.
Certificate
{
clientCert
},
RootCAs
:
certPool
}),
nil
}
This diff is collapsed.
Click to expand it.
Pavel Antonov
@softzilla
mentioned in commit
4928c96f
·
1 year ago
mentioned in commit
4928c96f
mentioned in commit 4928c96f50af44632da7bd58dd352194b23b4d5f
Toggle commit list
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