capability: Simplify the API to remove unnecessary RPC calls (#206)

The capabilities API is deprecated for all but the datastore_v3.write calls. Every other call always returns true because the APIs are always enabled. Don't make RPC calls when we know the answer already.
This commit is contained in:
Arjun Srinivasan 2019-08-01 11:14:06 -07:00 коммит произвёл Steven Buss
Родитель b2f4a3cf3c
Коммит fb139bde60
1 изменённых файлов: 6 добавлений и 11 удалений

Просмотреть файл

@ -29,6 +29,11 @@ import (
// If the underlying RPC fails (if the package is unknown, for example),
// false is returned and information is written to the application log.
func Enabled(ctx context.Context, api, capability string) bool {
// For non datastore*/write requests always return ENABLED
if !(api == "datastore_v3" && capability == "write") {
return true
}
req := &pb.IsEnabledRequest{
Package: &api,
Capability: []string{capability},
@ -38,15 +43,5 @@ func Enabled(ctx context.Context, api, capability string) bool {
log.Warningf(ctx, "capability.Enabled: RPC failed: %v", err)
return false
}
switch *res.SummaryStatus {
case pb.IsEnabledResponse_ENABLED,
pb.IsEnabledResponse_SCHEDULED_FUTURE,
pb.IsEnabledResponse_SCHEDULED_NOW:
return true
case pb.IsEnabledResponse_UNKNOWN:
log.Errorf(ctx, "capability.Enabled: unknown API capability %s/%s", api, capability)
return false
default:
return false
}
return *res.SummaryStatus == pb.IsEnabledResponse_ENABLED
}