-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add authzHandler to sdk-validator's grpc server (#797)
### Description of change Add authzHandler to sdk-validator's grpc server - Add CommonHandler - Refactor FlowControlHandler with CommonHandler ##### Checklist - [ ] Tested in playground or other setup - [ ] Documentation is changed or added - [ ] Tests and/or benchmarks are included - [ ] Breaking changes <!-- Reviewable:start --> - - - This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/fluxninja/aperture/797) <!-- Reviewable:end -->
- Loading branch information
Showing
7 changed files
with
140 additions
and
58 deletions.
There are no files selected for viewing
This file contains 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 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,41 @@ | ||
package validator | ||
|
||
import ( | ||
"context" | ||
"sync/atomic" | ||
|
||
"golang.org/x/exp/maps" | ||
|
||
flowcontrolv1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/flowcontrol/check/v1" | ||
"github.com/fluxninja/aperture/pkg/log" | ||
"github.com/fluxninja/aperture/pkg/policies/flowcontrol/selectors" | ||
"github.com/fluxninja/aperture/pkg/policies/flowcontrol/service/check" | ||
) | ||
|
||
// CommonHandler implements common.HandlerWithValues. | ||
type CommonHandler struct { | ||
check.HandlerWithValues | ||
|
||
Rejects int64 | ||
Rejected int64 | ||
} | ||
|
||
// CheckWithValues is a dummy function for creating *flowcontrolv1.CheckResponse from given parameters. | ||
func (c *CommonHandler) CheckWithValues(ctx context.Context, services []string, controlPoint selectors.ControlPoint, labels map[string]string) *flowcontrolv1.CheckResponse { | ||
resp := &flowcontrolv1.CheckResponse{ | ||
DecisionType: flowcontrolv1.CheckResponse_DECISION_TYPE_ACCEPTED, | ||
FlowLabelKeys: maps.Keys(labels), | ||
Services: services, | ||
ControlPointInfo: controlPoint.ToControlPointInfoProto(), | ||
RejectReason: flowcontrolv1.CheckResponse_REJECT_REASON_NONE, | ||
} | ||
|
||
if c.Rejected != c.Rejects { | ||
log.Trace().Msg("Rejecting call") | ||
resp.DecisionType = flowcontrolv1.CheckResponse_DECISION_TYPE_REJECTED | ||
resp.RejectReason = flowcontrolv1.CheckResponse_REJECT_REASON_RATE_LIMITED | ||
atomic.AddInt64(&c.Rejected, 1) | ||
} | ||
|
||
return resp | ||
} |
This file contains 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 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 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 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 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