Exemplo n.º 1
0
// UpdateRecord updates a record to a resource(domain)
func UpdateRecord(domain string, resource *sham.Resource) error {
	resource.Validate()
	sham.SanitizeDomain(&domain)

	// in case of some update to domain name...
	if domain != resource.Domain {
		// delete old domain
		err := DeleteRecord(domain)
		if err != nil {
			return fmt.Errorf("Failed to clean up old domain - %v", err)
		}
	}

	// store in cache
	config.Log.Trace("Updating record in persistent cache...")
	err := cache.UpdateRecord(domain, resource)
	if err != nil {
		return err
	}

	// set new resource to domain
	// todo: atomic
	Answers[resource.Domain] = *resource

	return nil
}
Exemplo n.º 2
0
// DeleteRecord removes a record from the persistent cache
func DeleteRecord(domain string) error {
	if storage == nil {
		return nil
	}
	shaman.SanitizeDomain(&domain)
	return storage.deleteRecord(domain)
}
Exemplo n.º 3
0
// UpdateRecord updates a record in the persistent cache
func UpdateRecord(domain string, resource *shaman.Resource) error {
	if storage == nil {
		return nil
	}
	shaman.SanitizeDomain(&domain)
	resource.Validate()
	return storage.updateRecord(domain, *resource)
}
Exemplo n.º 4
0
// GetRecord gets a record to the persistent cache
func GetRecord(domain string) (*shaman.Resource, error) {
	if storage == nil {
		return nil, nil
	}

	shaman.SanitizeDomain(&domain)
	return storage.getRecord(domain)
}
Exemplo n.º 5
0
// DeleteRecord deletes the resource(domain)
func DeleteRecord(domain string) error {
	sham.SanitizeDomain(&domain)

	// update cache
	config.Log.Trace("Removing record from persistent cache...")
	err := cache.DeleteRecord(domain)
	if err != nil {
		return err
	}

	// todo: atomic
	delete(Answers, domain)

	// otherwise, be idempotent and report it was deleted...
	return nil
}
Exemplo n.º 6
0
// GetRecord returns a resource for the specified domain
func GetRecord(domain string) (sham.Resource, error) {
	sham.SanitizeDomain(&domain)

	resource, ok := Answers[domain]
	// if domain not cached in memory...
	if !ok {
		// fetch from cache
		record, err := cache.GetRecord(domain)
		if record == nil {
			return resource, fmt.Errorf("Failed to find domain - %v", err)
		}
		// update local cache
		config.Log.Debug("Cache differs from local, updating...")
		Answers[domain] = *record
	}

	return Answers[domain], nil
}
Exemplo n.º 7
0
// Exists returns whether or not that domain exists
func Exists(domain string) bool {
	sham.SanitizeDomain(&domain)
	_, ok := Answers[domain]
	return ok
}