MCPcopy
hub / github.com/spacecloud-io/space-cloud / Stat

Method Stat

gateway/modules/global/letsencrypt/sc_store.go:179–202  ·  view source on GitHub ↗

Stat get stats for a particular key

(key string)

Source from the content-addressed store, hash-verified

177
178// Stat get stats for a particular key
179func (s *Storage) Stat(key string) (certmagic.KeyInfo, error) {
180 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
181 defer cancel()
182
183 response, err := s.db.GetOne(s.collection).Where(types.M{"_id": key}).Apply(ctx)
184 if err != nil {
185 return certmagic.KeyInfo{}, helpers.Logger.LogError(helpers.GetRequestID(context.TODO()), fmt.Sprintf("Unable to get stats of lets encrypt key (%s)", key), err, nil)
186 }
187 if response.Status != http.StatusOK {
188 return certmagic.KeyInfo{}, helpers.Logger.LogError(helpers.GetRequestID(context.TODO()), fmt.Sprintf("Unable to get stats of lets encrypt key (%s) database service responded with status code (%v)", key, response.Status), fmt.Errorf(response.Error), nil)
189 }
190
191 modifiedTime, err := time.Parse(time.RFC3339Nano, response.Data["modified"].(string))
192 if err != nil {
193 return certmagic.KeyInfo{}, helpers.Logger.LogError(helpers.GetRequestID(context.TODO()), fmt.Sprintf("Unable to parse (modified) field of lets encrypt key (%s) time to string ", key), err, nil)
194 }
195
196 return certmagic.KeyInfo{
197 Key: key,
198 Modified: modifiedTime,
199 Size: response.Data["size"].(int64),
200 IsTerminal: true,
201 }, nil
202}
203
204const lockFileExists = "Lock file already exists"
205

Callers 1

LockMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected