Beispiel #1
0
// TODO: strip out just hh:mm:ss
func New(d domains.Domain, data []byte) (Record, error) {
	raw := Raw{}
	err := json.Unmarshal(data, &raw)
	if err != nil {
		panic(err)
	}

	// strip dates and make a uuid from raw
	uuidRaw := fmt.Sprintf("%s", raw.Raw)
	uuidRaw = timeRE.ReplaceAllString(uuidRaw, "")
	uuidRaw = dateRE.ReplaceAllString(uuidRaw, "")
	id := uuid.NewSHA1(uuid.NameSpace_OID, []byte(uuidRaw))

	rawContacts, err := json.Marshal(&raw.Contacts)
	if err != nil {
		panic(err)
	}
	rawData, err := json.Marshal(&raw.Data)
	if err != nil {
		panic(err)
	}

	r := Record{
		Domain:   d,
		Data:     rawData,
		Raw:      raw.Raw,
		Contacts: rawContacts,
		UUID:     id,
	}
	r.parseRaw(raw)

	return r, err
}
Beispiel #2
0
// Generate generates AccessToken.
func Generate(seed []byte) AccessToken {
	id := uuid.NewUUID()
	for i := 0; i < 1000; i++ {
		sha := uuid.NewSHA1(id, seed)
		md5 := uuid.NewMD5(id, seed)
		seed = append(sha, md5...)
	}
	encoded := base58.Encode(seed)
	return New(encoded[:40])
}
Beispiel #3
0
func New(name string, t tlds.TLD) Domain {
	name = strings.ToLower(name)
	name = CleanDomain(name, t)
	args := strings.Split(name, ".")
	name = args[len(args)-1]
	id := uuid.NewSHA1(uuid.NameSpace_OID, []byte(fmt.Sprintf("%s_%d", name, t.ID)))
	return Domain{
		UUID: id,
		Name: name,
		TLD:  t,
	}
}
Beispiel #4
0
// New creates a new Record, it takes the entire resource record line, the origin of the zonefile, the tld associated, the ttl and a parse date. It then creates a formalized Record.
func New(line, origin string, tld tlds.TLD, ttl uint, date time.Time, parserID int32) (Record, error) {
	fields := strings.Fields(line)
	r := Record{}

	name := fields[0]
	// set origin if it's not already there
	if !strings.HasSuffix(name, ".") {
		name += "." + origin
	}
	// strip domain name
	name = domains.CleanDomain(name, tld)
	r.Domain = domains.New(name, tld)
	name = strings.TrimSuffix(name, ".")
	name = strings.TrimSuffix(name, r.Domain.TLD.Name)
	name = strings.TrimSuffix(name, r.Domain.Name)
	name = strings.TrimSuffix(name, ".")
	// check if we are referencing top level
	if len(name) == 0 {
		name = "@"
	}
	r.Name = name

	typeIdx := 1
	if len(fields) > 3 {
		fields = util.FilterIN(fields)
	}
	if len(fields) > 3 {
		ttlFromFields, err := strconv.ParseUint(fields[1], 10, 64)
		if err == nil {
			typeIdx = 2
			ttl = uint(ttlFromFields)
		} else {
			log.Warn("Unable to parse RR: len(fields) == %d, fields: %s", len(fields), fields)
		}
	}
	if len(fields) <= typeIdx {
		return r, errors.New("Unable to set typeIdx in getRecord.")
	}
	rt, err := types.Detect(fields[typeIdx])
	if err != nil {
		return r, errors.New("Unable to detect Record Type.")
	}
	r.Type, err = types.New(rt, tld)
	r.Args.Args = fields[typeIdx+1:]
	id := uuid.NewSHA1(uuid.NameSpace_OID, []byte(
		fmt.Sprintf("%v%d", r, parserID),
	))
	r.Date = date
	r.Args.TTL = ttl
	r.UUID = id
	r.Added = time.Now()
	return r, nil
}