예제 #1
0
파일: auth.go 프로젝트: eluleci/dock
		queryParam = googleDataAsMap["id"].(string)
		queryKey = "google.id"
	}

	query := make(map[string]string)
	query["$eq"] = queryParam
	whereParams[queryKey] = query

	whereParamsJson, jsonErr := json.Marshal(whereParams)
	if jsonErr != nil {
		err = &utils.Error{http.StatusInternalServerError, "Creating user request failed."}
		return
	}
	requestWrapper.Message.Parameters["where"] = []string{string(whereParamsJson)}

	results, fetchErr := adapters.Query(ClassUsers, requestWrapper.Message.Parameters)
	resultsAsMap := results["data"].([]map[string]interface{})
	if fetchErr != nil || len(resultsAsMap) == 0 {
		err = &utils.Error{http.StatusNotFound, "Account not found."}
		return
	}
	accountData = resultsAsMap[0]

	return
}

var generateToken = func(userId string, userData map[string]interface{}) (tokenString string, err *utils.Error) {

	token := jwt.New(jwt.SigningMethodHS256)

	userTokenData := make(map[string]interface{})
예제 #2
0
파일: triggers.go 프로젝트: eluleci/dock
var getFunctionData = func(name string) (function map[string]interface{}, err *utils.Error) {

	whereParams := map[string]interface{}{
		"name": map[string]string{
			"$eq": name,
		},
	}

	whereParamsJson, jsonErr := json.Marshal(whereParams)
	if jsonErr != nil {
		err = &utils.Error{http.StatusInternalServerError, "Creating 'get function info' request failed."}
		return
	}

	parameters := map[string][]string{"where": []string{string(whereParamsJson)}}
	results, fetchErr := adapters.Query("functions", parameters)

	if fetchErr != nil {
		err = fetchErr
		return
	}
	if results["data"] != nil {
		resultsAsMap := results["data"].([]map[string]interface{})

		if len(resultsAsMap) == 0 {
			err = &utils.Error{http.StatusNotFound, "Function with name '" + name + "' not found."}
			return
		}
		function = resultsAsMap[0]
	}
	return
예제 #3
0
파일: actor.go 프로젝트: eluleci/dock
var handleGet = func(a *Actor, requestWrapper messages.RequestWrapper) (response messages.Message, err *utils.Error) {

	isFileClass := strings.EqualFold(a.class, ClassFiles)
	isObjectTypeActor := strings.EqualFold(a.actorType, ActorTypeModel)
	isCollectionTypeActor := strings.EqualFold(a.actorType, ActorTypeCollection)

	if isObjectTypeActor {
		id := requestWrapper.Message.Res[strings.LastIndex(requestWrapper.Message.Res, "/")+1:]
		if isFileClass { // get file by id
			response.RawBody, err = adapters.GetFile(id)
		} else { // get object by id
			response.Body, err = adapters.Get(a.class, id)
		}
	} else if isCollectionTypeActor { // query objects
		response.Body, err = adapters.Query(a.class, requestWrapper.Message.Parameters)
	}

	if err != nil {
		return
	}

	if requestWrapper.Message.Parameters["expand"] != nil {
		expandConfig := requestWrapper.Message.Parameters["expand"][0]
		if _, hasDataArray := response.Body["data"]; hasDataArray {
			response.Body, err = modifier.ExpandArray(response.Body, expandConfig)
		} else {
			response.Body, err = modifier.ExpandItem(response.Body, expandConfig)
		}
		if err != nil {
			return