blob: d1a21d4a684ab60dff665b9c589ac4646c7583b3 [file] [log] [blame]
// Copyright 2016 The LUCI Authors.
// 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
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.
package certconfig
import (
ds ""
// GetCAStatusRPC implements CertificateAuthorities.GetCAStatus RPC method.
type GetCAStatusRPC struct {
// GetCAStatus returns configuration of some CA defined in the config.
func (r *GetCAStatusRPC) GetCAStatus(c context.Context, req *admin.GetCAStatusRequest) (*admin.GetCAStatusResponse, error) {
// Entities to fetch.
ca := CA{CN: req.Cn}
crl := CRL{Parent: ds.KeyForObj(c, &ca)}
// Fetch them at the same revision. It is fine if CRL is not there yet. Don't
// bother doing it in parallel: GetCAStatus is used only by admins, manually.
err := ds.RunInTransaction(c, func(c context.Context) error {
if err := ds.Get(c, &ca); err != nil {
return err // can be ErrNoSuchEntity
if err := ds.Get(c, &crl); err != nil && err != ds.ErrNoSuchEntity {
return err // only transient errors
return nil
}, nil)
switch {
case err == ds.ErrNoSuchEntity:
return &admin.GetCAStatusResponse{}, nil
case err != nil:
return nil, status.Errorf(codes.Internal, "datastore error - %s", err)
cfgMsg, err := ca.ParseConfig()
if err != nil {
return nil, status.Errorf(codes.Internal, "broken config in the datastore - %s", err)
return &admin.GetCAStatusResponse{
Config: cfgMsg,
Cert: utils.DumpPEM(ca.Cert, "CERTIFICATE"),
Removed: ca.Removed,
Ready: ca.Ready,
AddedRev: ca.AddedRev,
UpdatedRev: ca.UpdatedRev,
RemovedRev: ca.RemovedRev,
CrlStatus: crl.GetStatusProto(),
}, nil