Stat get stats for a particular key
(key string)
| 177 | |
| 178 | // Stat get stats for a particular key |
| 179 | func (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 | |
| 204 | const lockFileExists = "Lock file already exists" |
| 205 |