func addIdentifiers(csvFilename string, dbMap *gorp.DbMap, stats metrics.Statter, statsRate float32) { file, err := os.Open(csvFilename) cmd.FailOnError(err, "Could not open the file for reading") csvReader := csv.NewReader(file) for { record, err := csvReader.Read() if err == io.EOF { break } else if err != nil { fmt.Println("Error:", err) return } identifierData := core.IdentifierData{ ReversedName: record[1], CertSHA1: record[0], } importStart := time.Now() err = dbMap.Insert(&identifierData) stats.TimingDuration("ExistingCert.Domains.ImportLatency", time.Since(importStart), statsRate) stats.Inc("ExistingCert.Domains.Imported", 1, statsRate) } }
func removeInvalidCerts(csvFilename string, dbMap *gorp.DbMap, stats metrics.Statter, statsRate float32) { file, err := os.Open(csvFilename) cmd.FailOnError(err, "Could not open the file for reading") csvReader := csv.NewReader(file) for { record, err := csvReader.Read() if err == io.EOF { break } else if err != nil { fmt.Println("Error:", err) return } identifierData := core.IdentifierData{ CertSHA1: record[0], } externalCert := core.ExternalCert{ SHA1: record[0], } deleteStart := time.Now() _, err = dbMap.Delete(&identifierData) stats.TimingDuration("ExistingCert.Domains.DeleteLatency", time.Since(deleteStart), statsRate) _, err = dbMap.Delete(&externalCert) stats.TimingDuration("ExistingCert.Certs.DeleteLatency", time.Since(deleteStart), statsRate) stats.Inc("ExistingCert.Removed", 1, statsRate) } }
func addCerts(csvFilename string, dbMap *gorp.DbMap, stats metrics.Statter, statsRate float32) { file, err := os.Open(csvFilename) cmd.FailOnError(err, "Could not open the file for reading") csvReader := csv.NewReader(file) for { record, err := csvReader.Read() if err == io.EOF { break } else if err != nil { fmt.Println("Error:", err) return } notAfter, err := time.Parse(datestampFormat, record[3]) spkiBytes, err := hex.DecodeString(record[4]) certDER, err := hex.DecodeString(record[7]) externalCert := core.ExternalCert{ SHA1: record[0], Issuer: record[1], Subject: record[2], NotAfter: notAfter, SPKI: spkiBytes, Valid: record[5] == "1", EV: record[6] == "1", CertDER: certDER, } importStart := time.Now() err = dbMap.Insert(&externalCert) stats.TimingDuration("ExistingCert.Certs.ImportLatency", time.Since(importStart), statsRate) stats.Inc("ExistingCert.Certs.Imported", 1, statsRate) } }