-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Added quota contoll without the service control client library #92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d5a878a
Get attributes from envoy config. (#87)
chowchow316 e1d500b
Added quota contoll without service control client library
d4af8ef
Removed unnecessary QuotaResponseInfo class
998904f
Code format fix
2f0d759
Removed uncessary class, enum, and comment
f5577b2
Added comment
b2b3c4a
Added comment
mangchiandjjoe 1bb5ae8
Merge branch 'master' of github.com:mangchiandjjoe/proxy
b13b3dc
Merge branch 'master' of github.com:mangchiandjjoe/proxy
mangchiandjjoe 30620ce
Merge branch 'master' of github.com:mangchiandjjoe/proxy
0ed3e7a
Merge branch 'master' of github.com:mangchiandjjoe/proxy
mangchiandjjoe 8a1cc4e
Fixed file formatting error
mangchiandjjoe 464df92
Merge branch 'master' of github.com:mangchiandjjoe/proxy
mangchiandjjoe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| // Copyright 2017 Google Inc. All Rights Reserved. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // | ||
| //////////////////////////////////////////////////////////////////////////////// | ||
| // | ||
| #include <iostream> | ||
|
|
||
| #include "contrib/endpoints/src/api_manager/cloud_trace/cloud_trace.h" | ||
| #include "contrib/endpoints/src/api_manager/quota_control.h" | ||
| #include "google/protobuf/stubs/status.h" | ||
|
|
||
| using ::google::api_manager::utils::Status; | ||
| using ::google::protobuf::util::error::Code; | ||
|
|
||
| namespace google { | ||
| namespace api_manager { | ||
|
|
||
| void QuotaControl(std::shared_ptr<context::RequestContext> context, | ||
| std::function<void(Status status)> continuation) { | ||
| std::shared_ptr<cloud_trace::CloudTraceSpan> trace_span( | ||
| CreateSpan(context->cloud_trace(), "QuotaControl")); | ||
|
|
||
| if (!context->service_context()->service_control()) { | ||
| TRACE(trace_span) << "Service control check is not needed"; | ||
| continuation(Status::OK); | ||
| return; | ||
| } | ||
|
|
||
| if (context->api_key().empty()) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we need to call quota for all requests.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed the paragraph |
||
| if (context->method()->allow_unregistered_calls()) { | ||
| // Not need to call Check. | ||
| TRACE(trace_span) << "Service control check is not needed"; | ||
| continuation(Status::OK); | ||
| return; | ||
| } | ||
|
|
||
| TRACE(trace_span) << "Failed at checking caller identity."; | ||
| continuation( | ||
| Status(Code::UNAUTHENTICATED, | ||
| "Method doesn't allow unregistered callers (callers without " | ||
| "established identity). Please use API Key or other form of " | ||
| "API consumer identity to call this API.", | ||
| Status::SERVICE_CONTROL)); | ||
| return; | ||
| } | ||
|
|
||
| service_control::QuotaRequestInfo info; | ||
| context->FillAllocateQuotaRequestInfo(&info); | ||
| context->service_context()->service_control()->Quota( | ||
| info, trace_span.get(), | ||
| [context, continuation, trace_span](utils::Status status) { | ||
|
|
||
| TRACE(trace_span) << "Quota service control request returned with " | ||
| << "status " << status.ToString(); | ||
|
|
||
| continuation(status); | ||
| }); | ||
| } | ||
|
|
||
| } // namespace service_control_client | ||
| } // namespace google | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| // Copyright 2017 Google Inc. All Rights Reserved. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // | ||
| //////////////////////////////////////////////////////////////////////////////// | ||
| // | ||
| #ifndef API_MANAGER_QUOTA_CONTROL_H_ | ||
| #define API_MANAGER_QUOTA_CONTROL_H_ | ||
|
|
||
| #include "contrib/endpoints/include/api_manager/utils/status.h" | ||
| #include "contrib/endpoints/src/api_manager/context/request_context.h" | ||
|
|
||
| namespace google { | ||
| namespace api_manager { | ||
|
|
||
| // Call service control quota. | ||
| void QuotaControl(std::shared_ptr<context::RequestContext>, | ||
| std::function<void(utils::Status)>); | ||
|
|
||
| } // namespace api_manager | ||
| } // namespace google | ||
|
|
||
| #endif // API_MANAGER_QUOTA_CONTROL_H_ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see info->labels get used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function was moved to Proto::FillAllocateQuotaRequest
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed