Esempio n. 1
0
func NewApplication(name string) (*Application, error) {
	if !x.Where("name = ?", name).First(new(Application)).RecordNotFound() {
		return nil, errors.ApplicationExists{name}
	}

	app := &Application{
		Name:    name,
		Token:   tool.NewSecretToekn(),
		Created: time.Now().UTC().UnixNano(),
	}
	if err := x.Create(app).Error; err != nil {
		return nil, fmt.Errorf("Create: %v", err)
	}
	return app, nil
}
Esempio n. 2
0
func NewCollector(name string, tp CollectType) (*Collector, error) {
	if !x.Where("name = ?", name).First(new(Collector)).RecordNotFound() {
		return nil, errors.CollectorExists{name}
	}

	collector := &Collector{
		Name:    name,
		Type:    tp,
		Secret:  tool.NewSecretToekn(),
		Created: time.Now().UTC().UnixNano(),
	}
	if err := x.Create(collector).Error; err != nil {
		return nil, fmt.Errorf("Create: %v", err)
	}
	return collector, nil
}
Esempio n. 3
0
func RegenerateApplicationToken(id int64) error {
	return x.First(new(Application), id).Update("token", tool.NewSecretToekn()).Error
}
Esempio n. 4
0
func RegenerateCollectorSecret(id int64) error {
	return x.First(new(Collector), id).Update("secret", tool.NewSecretToekn()).Error
}