blob: 715018c9dc8d442ab88919d796c3e748a83e4e88 [file] [log] [blame]
// Copyright 2017 The LUCI Authors. All rights reserved.
// Use of this source code is governed under the Apache License, Version 2.0
// that can be found in the LICENSE file.
package serviceaccounts
import (
"context"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/emptypb"
"go.chromium.org/luci/common/logging"
"go.chromium.org/luci/config/validation"
"go.chromium.org/luci/tokenserver/api/admin/v1"
)
// ImportServiceAccountsConfigsRPC implements admin.ImportServiceAccountsConfigs
// method.
type ImportServiceAccountsConfigsRPC struct {
RulesCache *RulesCache // usually GlobalRulesCache, but replaced in tests
}
// ImportServiceAccountsConfigs fetches configs from from luci-config right now.
func (r *ImportServiceAccountsConfigsRPC) ImportServiceAccountsConfigs(c context.Context, _ *emptypb.Empty) (*admin.ImportedConfigs, error) {
rev, err := r.RulesCache.ImportConfigs(c)
if err != nil {
logging.WithError(err).Errorf(c, "Failed to fetch service accounts configs")
return nil, status.Errorf(codes.Internal, err.Error())
}
return &admin.ImportedConfigs{Revision: rev}, nil
}
// SetupConfigValidation registers the config validation rules.
func (r *ImportServiceAccountsConfigsRPC) SetupConfigValidation(rules *validation.RuleSet) {
r.RulesCache.SetupConfigValidation(rules)
}