Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Grpc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tci-gateway-module
Grpc
Commits
c91a9f94
Commit
c91a9f94
authored
Mar 16, 2015
by
jboeuf
Browse files
Options
Downloads
Plain Diff
Merge pull request #1011 from yang-g/jwt
Put back C++ JWTCredentials code and add a test case in interop test.
parents
4c3ee74d
2fbbb9bd
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
include/grpc++/credentials.h
+8
-0
8 additions, 0 deletions
include/grpc++/credentials.h
src/cpp/client/secure_credentials.cc
+20
-2
20 additions, 2 deletions
src/cpp/client/secure_credentials.cc
test/cpp/interop/client.cc
+29
-2
29 additions, 2 deletions
test/cpp/interop/client.cc
with
57 additions
and
4 deletions
include/grpc++/credentials.h
+
8
−
0
View file @
c91a9f94
...
@@ -105,6 +105,14 @@ std::unique_ptr<Credentials> ServiceAccountCredentials(
...
@@ -105,6 +105,14 @@ std::unique_ptr<Credentials> ServiceAccountCredentials(
const
grpc
::
string
&
json_key
,
const
grpc
::
string
&
scope
,
const
grpc
::
string
&
json_key
,
const
grpc
::
string
&
scope
,
std
::
chrono
::
seconds
token_lifetime
);
std
::
chrono
::
seconds
token_lifetime
);
// Builds JWT credentials.
// json_key is the JSON key string containing the client's private key.
// token_lifetime is the lifetime of each Json Web Token (JWT) created with
// this credentials. It should not exceed grpc_max_auth_token_lifetime or
// will be cropped to this value.
std
::
unique_ptr
<
Credentials
>
JWTCredentials
(
const
grpc
::
string
&
json_key
,
std
::
chrono
::
seconds
token_lifetime
);
// Builds IAM credentials.
// Builds IAM credentials.
std
::
unique_ptr
<
Credentials
>
IAMCredentials
(
std
::
unique_ptr
<
Credentials
>
IAMCredentials
(
const
grpc
::
string
&
authorization_token
,
const
grpc
::
string
&
authorization_token
,
...
...
This diff is collapsed.
Click to expand it.
src/cpp/client/secure_credentials.cc
+
20
−
2
View file @
c91a9f94
...
@@ -98,12 +98,30 @@ std::unique_ptr<Credentials> ComputeEngineCredentials() {
...
@@ -98,12 +98,30 @@ std::unique_ptr<Credentials> ComputeEngineCredentials() {
std
::
unique_ptr
<
Credentials
>
ServiceAccountCredentials
(
std
::
unique_ptr
<
Credentials
>
ServiceAccountCredentials
(
const
grpc
::
string
&
json_key
,
const
grpc
::
string
&
scope
,
const
grpc
::
string
&
json_key
,
const
grpc
::
string
&
scope
,
std
::
chrono
::
seconds
token_lifetime
)
{
std
::
chrono
::
seconds
token_lifetime
)
{
gpr_timespec
lifetime
=
gpr_time_from_seconds
(
if
(
token_lifetime
.
count
()
<=
0
)
{
token_lifetime
.
count
()
>
0
?
token_lifetime
.
count
()
:
0
);
gpr_log
(
GPR_ERROR
,
"Trying to create ServiceAccountCredentials "
"with non-positive lifetime"
);
return
WrapCredentials
(
nullptr
);
}
gpr_timespec
lifetime
=
gpr_time_from_seconds
(
token_lifetime
.
count
());
return
WrapCredentials
(
grpc_service_account_credentials_create
(
return
WrapCredentials
(
grpc_service_account_credentials_create
(
json_key
.
c_str
(),
scope
.
c_str
(),
lifetime
));
json_key
.
c_str
(),
scope
.
c_str
(),
lifetime
));
}
}
// Builds JWT credentials.
std
::
unique_ptr
<
Credentials
>
JWTCredentials
(
const
grpc
::
string
&
json_key
,
std
::
chrono
::
seconds
token_lifetime
)
{
if
(
token_lifetime
.
count
()
<=
0
)
{
gpr_log
(
GPR_ERROR
,
"Trying to create JWTCredentials with non-positive lifetime"
);
return
WrapCredentials
(
nullptr
);
}
gpr_timespec
lifetime
=
gpr_time_from_seconds
(
token_lifetime
.
count
());
return
WrapCredentials
(
grpc_jwt_credentials_create
(
json_key
.
c_str
(),
lifetime
));
}
// Builds IAM credentials.
// Builds IAM credentials.
std
::
unique_ptr
<
Credentials
>
IAMCredentials
(
std
::
unique_ptr
<
Credentials
>
IAMCredentials
(
const
grpc
::
string
&
authorization_token
,
const
grpc
::
string
&
authorization_token
,
...
...
This diff is collapsed.
Click to expand it.
test/cpp/interop/client.cc
+
29
−
2
View file @
c91a9f94
...
@@ -73,6 +73,7 @@ DEFINE_string(test_case, "large_unary",
...
@@ -73,6 +73,7 @@ DEFINE_string(test_case, "large_unary",
"ping_pong : full-duplex streaming; "
"ping_pong : full-duplex streaming; "
"service_account_creds : large_unary with service_account auth; "
"service_account_creds : large_unary with service_account auth; "
"compute_engine_creds: large_unary with compute engine auth; "
"compute_engine_creds: large_unary with compute engine auth; "
"jwt_token_creds: large_unary with JWT token auth; "
"all : all of above."
);
"all : all of above."
);
DEFINE_string
(
default_service_account
,
""
,
DEFINE_string
(
default_service_account
,
""
,
"Email of GCE default service account"
);
"Email of GCE default service account"
);
...
@@ -85,6 +86,7 @@ using grpc::ClientContext;
...
@@ -85,6 +86,7 @@ using grpc::ClientContext;
using
grpc
::
ComputeEngineCredentials
;
using
grpc
::
ComputeEngineCredentials
;
using
grpc
::
CreateTestChannel
;
using
grpc
::
CreateTestChannel
;
using
grpc
::
Credentials
;
using
grpc
::
Credentials
;
using
grpc
::
JWTCredentials
;
using
grpc
::
ServiceAccountCredentials
;
using
grpc
::
ServiceAccountCredentials
;
using
grpc
::
testing
::
ResponseParameters
;
using
grpc
::
testing
::
ResponseParameters
;
using
grpc
::
testing
::
SimpleRequest
;
using
grpc
::
testing
::
SimpleRequest
;
...
@@ -146,6 +148,13 @@ std::shared_ptr<ChannelInterface> CreateChannelForTestCase(
...
@@ -146,6 +148,13 @@ std::shared_ptr<ChannelInterface> CreateChannelForTestCase(
creds
=
ComputeEngineCredentials
();
creds
=
ComputeEngineCredentials
();
return
CreateTestChannel
(
host_port
,
FLAGS_server_host_override
,
return
CreateTestChannel
(
host_port
,
FLAGS_server_host_override
,
FLAGS_enable_ssl
,
FLAGS_use_prod_roots
,
creds
);
FLAGS_enable_ssl
,
FLAGS_use_prod_roots
,
creds
);
}
else
if
(
test_case
==
"jwt_token_creds"
)
{
std
::
unique_ptr
<
Credentials
>
creds
;
GPR_ASSERT
(
FLAGS_enable_ssl
);
grpc
::
string
json_key
=
GetServiceAccountJsonKey
();
creds
=
JWTCredentials
(
json_key
,
std
::
chrono
::
hours
(
1
));
return
CreateTestChannel
(
host_port
,
FLAGS_server_host_override
,
FLAGS_enable_ssl
,
FLAGS_use_prod_roots
,
creds
);
}
else
{
}
else
{
return
CreateTestChannel
(
host_port
,
FLAGS_server_host_override
,
return
CreateTestChannel
(
host_port
,
FLAGS_server_host_override
,
FLAGS_enable_ssl
,
FLAGS_use_prod_roots
);
FLAGS_enable_ssl
,
FLAGS_use_prod_roots
);
...
@@ -227,6 +236,21 @@ void DoServiceAccountCreds() {
...
@@ -227,6 +236,21 @@ void DoServiceAccountCreds() {
gpr_log
(
GPR_INFO
,
"Large unary with service account creds done."
);
gpr_log
(
GPR_INFO
,
"Large unary with service account creds done."
);
}
}
void
DoJwtTokenCreds
()
{
gpr_log
(
GPR_INFO
,
"Sending a large unary rpc with JWT token credentials ..."
);
std
::
shared_ptr
<
ChannelInterface
>
channel
=
CreateChannelForTestCase
(
"jwt_token_creds"
);
SimpleRequest
request
;
SimpleResponse
response
;
request
.
set_fill_username
(
true
);
PerformLargeUnary
(
channel
,
&
request
,
&
response
);
GPR_ASSERT
(
!
response
.
username
().
empty
());
grpc
::
string
json_key
=
GetServiceAccountJsonKey
();
GPR_ASSERT
(
json_key
.
find
(
response
.
username
())
!=
grpc
::
string
::
npos
);
gpr_log
(
GPR_INFO
,
"Large unary with JWT token creds done."
);
}
void
DoLargeUnary
()
{
void
DoLargeUnary
()
{
gpr_log
(
GPR_INFO
,
"Sending a large unary rpc..."
);
gpr_log
(
GPR_INFO
,
"Sending a large unary rpc..."
);
std
::
shared_ptr
<
ChannelInterface
>
channel
=
std
::
shared_ptr
<
ChannelInterface
>
channel
=
...
@@ -415,6 +439,8 @@ int main(int argc, char** argv) {
...
@@ -415,6 +439,8 @@ int main(int argc, char** argv) {
DoServiceAccountCreds
();
DoServiceAccountCreds
();
}
else
if
(
FLAGS_test_case
==
"compute_engine_creds"
)
{
}
else
if
(
FLAGS_test_case
==
"compute_engine_creds"
)
{
DoComputeEngineCreds
();
DoComputeEngineCreds
();
}
else
if
(
FLAGS_test_case
==
"jwt_token_creds"
)
{
DoJwtTokenCreds
();
}
else
if
(
FLAGS_test_case
==
"all"
)
{
}
else
if
(
FLAGS_test_case
==
"all"
)
{
DoEmpty
();
DoEmpty
();
DoLargeUnary
();
DoLargeUnary
();
...
@@ -422,9 +448,10 @@ int main(int argc, char** argv) {
...
@@ -422,9 +448,10 @@ int main(int argc, char** argv) {
DoResponseStreaming
();
DoResponseStreaming
();
DoHalfDuplex
();
DoHalfDuplex
();
DoPingPong
();
DoPingPong
();
// service_account_creds can only run with ssl.
// service_account_creds
and jwt_token_creds
can only run with ssl.
if
(
FLAGS_enable_ssl
)
{
if
(
FLAGS_enable_ssl
)
{
DoServiceAccountCreds
();
DoServiceAccountCreds
();
DoJwtTokenCreds
();
}
}
// compute_engine_creds only runs in GCE.
// compute_engine_creds only runs in GCE.
}
else
{
}
else
{
...
@@ -432,7 +459,7 @@ int main(int argc, char** argv) {
...
@@ -432,7 +459,7 @@ int main(int argc, char** argv) {
GPR_ERROR
,
GPR_ERROR
,
"Unsupported test case %s. Valid options are all|empty_unary|"
"Unsupported test case %s. Valid options are all|empty_unary|"
"large_unary|client_streaming|server_streaming|half_duplex|ping_pong|"
"large_unary|client_streaming|server_streaming|half_duplex|ping_pong|"
"service_account_creds|compute_engine_creds"
,
"service_account_creds|compute_engine_creds
|jwt_token_creds
"
,
FLAGS_test_case
.
c_str
());
FLAGS_test_case
.
c_str
());
}
}
...
...
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
sign in
to comment