func (attribute *Attribute) Create(context *ctp.ApiContext) *ctp.HttpError {
	attribute.BuildLinks(context)
	if !ctp.CreateResource(context, "attributes", attribute) {
		return ctp.NewHttpError(http.StatusInternalServerError, "Could not save object")
	}
	return nil
}
func (account *Account) Create(context *ctp.ApiContext) *ctp.HttpError {
	var key [24]byte

	account.BuildLinks(context)

	if account.Token == "" {
		_, err := rand.Read(key[:])
		if err != nil {
			return ctp.NewInternalServerError("Error generating key")
		}
		account.Token = base64.StdEncoding.EncodeToString(key[:])
	}

	if len(account.AccountTags.WithPrefix("account:")) == 0 {
		account.AccountTags.Append(ctp.NewTags("account:" + string(account.Id)))
	}

	if len(account.AccountTags.WithPrefix("role:")) == 0 {
		account.AccountTags.Append(ctp.UserRoleTag)
	}

	if !ctp.CreateResource(context, "accounts", account) {
		return ctp.NewHttpError(http.StatusInternalServerError, "Could not save account")
	}
	return nil
}
Exemple #3
0
func (asset *Asset) Create(context *ctp.ApiContext) *ctp.HttpError {
	asset.BuildLinks(context)
	if !ctp.CreateResource(context, "assets", asset) {
		return ctp.NewHttpError(http.StatusInternalServerError, "Could not save asset")
	}
	return nil
}
func (measurement *Measurement) Create(context *ctp.ApiContext) *ctp.HttpError {
	measurement.BuildLinks(context)
	measurement.Metric = ctp.ShortenLink(context.CtpBase, measurement.Metric)
	if !ctp.IsShortLink(measurement.Metric) {
		return ctp.NewBadRequestError("Invalid metric URL")
	}

	if !measurement.State.IsValid() {
		return ctp.NewBadRequestError("Invalid or missing state value")
	}

	if measurement.Result != nil {
		if err := measurementCheckResult(context, measurement); err != nil {
			return err
		}
	} else {
		if err := measurementCheckMetric(context, measurement); err != nil {
			return err
		}
	}

	if measurement.Objective != nil {
		if err := measurementObjectiveEvaluate(context, measurement); err != nil {
			return err
		}
	}

	if !ctp.CreateResource(context, "measurements", measurement) {
		return ctp.NewInternalServerError("Could not save measurement object")
	}
	return nil
}
func (metric *Metric) Create(context *ctp.ApiContext) *ctp.HttpError {
	metric.BuildLinks(context)

	if !ctp.CreateResource(context, "metrics", metric) {
		return ctp.NewHttpError(http.StatusInternalServerError, "Could not save object")
	}
	return nil
}
Exemple #6
0
func (log *LogEntry) Create(context *ctp.ApiContext) *ctp.HttpError {
	log.BuildLinks(context)
	//log.CreationTime = ctp.Now()
	if !ctp.CreateResource(context, "logs", log) {
		return ctp.NewHttpError(http.StatusInternalServerError, "Could not save object")
	}
	return nil
}
func (serviceview *ServiceView) Create(context *ctp.ApiContext) *ctp.HttpError {
	serviceview.BuildLinks(context)

	if !ctp.CreateResource(context, "serviceViews", serviceview) {
		return ctp.NewHttpError(http.StatusInternalServerError, "Could not save object")
	}
	return nil
}
Exemple #8
0
func (serviceview *ServiceView) Create(context *ctp.ApiContext) *ctp.HttpError {
	serviceview.BuildLinks(context)

	// we don't set serviceview.AccessTags it's the admin's job to do so.

	if !ctp.CreateResource(context, "serviceViews", serviceview) {
		return ctp.NewHttpError(http.StatusInternalServerError, "Could not save object")
	}
	return nil
}
func (trigger *Trigger) Create(context *ctp.ApiContext) *ctp.HttpError {
	trigger.BuildLinks(context)
	trigger.Measurement = ctp.ShortenLink(context.CtpBase, trigger.Measurement)
	if !ctp.IsShortLink(trigger.Measurement) {
		return ctp.NewBadRequestError("Invalid measurement URL")
	}

	ok, err := triggerCheckCondition(context, trigger, nil)
	if err != nil {
		return ctp.NewBadRequestErrorf("%s", err.Error())
	}

	if ok {
		triggerLogAndNotify(context, trigger, nil)
	}

	if !ctp.CreateResource(context, "triggers", trigger) {
		return ctp.NewHttpError(http.StatusInternalServerError, "Could not save object")
	}
	return nil
}