OLD | NEW |
---|---|
1 // Copyright 2016 The LUCI Authors. All rights reserved. | 1 // Copyright 2016 The LUCI Authors. All rights reserved. |
2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
4 | 4 |
5 package certconfig | 5 package certconfig |
6 | 6 |
7 import ( | 7 import ( |
8 "bytes" | 8 "bytes" |
9 "crypto/x509" | 9 "crypto/x509" |
10 "encoding/gob" | 10 "encoding/gob" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
64 | 64 |
65 // ParseConfig parses proto message stored in Config. | 65 // ParseConfig parses proto message stored in Config. |
66 func (c *CA) ParseConfig() (*admin.CertificateAuthorityConfig, error) { | 66 func (c *CA) ParseConfig() (*admin.CertificateAuthorityConfig, error) { |
67 msg := &admin.CertificateAuthorityConfig{} | 67 msg := &admin.CertificateAuthorityConfig{} |
68 if err := proto.Unmarshal(c.Config, msg); err != nil { | 68 if err := proto.Unmarshal(c.Config, msg); err != nil { |
69 return nil, err | 69 return nil, err |
70 } | 70 } |
71 return msg, nil | 71 return msg, nil |
72 } | 72 } |
73 | 73 |
74 // ListCAs returns names of all currently active CAs, in no particular order. | |
75 func ListCAs(c context.Context) ([]string, error) { | |
Vadim Sh.
2017/03/29 21:12:57
this is just moved from rpc_list_cas.go
| |
76 keys := []*ds.Key{} | |
77 q := ds.NewQuery("CA").Eq("Removed", false).KeysOnly(true) | |
78 if err := ds.GetAll(c, q, &keys); err != nil { | |
79 return nil, errors.WrapTransient(err) | |
80 } | |
81 names := make([]string, len(keys)) | |
82 for i, key := range keys { | |
83 names[i] = key.StringID() | |
84 } | |
85 return names, nil | |
86 } | |
87 | |
74 // CAUniqueIDToCNMap is a singleton entity that stores a mapping between CA's | 88 // CAUniqueIDToCNMap is a singleton entity that stores a mapping between CA's |
75 // unique_id (specified in config) and its Common Name. | 89 // unique_id (specified in config) and its Common Name. |
76 // | 90 // |
77 // It's loaded in memory in full and kept cached there (for 1 min). | 91 // It's loaded in memory in full and kept cached there (for 1 min). |
78 // See GetCAByUniqueID below. | 92 // See GetCAByUniqueID below. |
79 type CAUniqueIDToCNMap struct { | 93 type CAUniqueIDToCNMap struct { |
80 _id int64 `gae:"$id,1"` | 94 _id int64 `gae:"$id,1"` |
81 | 95 |
82 GobEncodedMap []byte `gae:",noindex"` // gob-encoded map[int64]string | 96 GobEncodedMap []byte `gae:",noindex"` // gob-encoded map[int64]string |
83 } | 97 } |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
151 } | 165 } |
152 | 166 |
153 func (m *idToCNmapper) getCAByUniqueID(c context.Context, id int64) (string, err or) { | 167 func (m *idToCNmapper) getCAByUniqueID(c context.Context, id int64) (string, err or) { |
154 val, err := m.mapping.Get(c) | 168 val, err := m.mapping.Get(c) |
155 if err != nil { | 169 if err != nil { |
156 return "", err | 170 return "", err |
157 } | 171 } |
158 mapping := val.Value.(map[int64]string) | 172 mapping := val.Value.(map[int64]string) |
159 return mapping[id], nil | 173 return mapping[id], nil |
160 } | 174 } |
OLD | NEW |