Esempio n. 1
0
func createMultipleEvents(p *model.Project, params CreateMultipleEventParams) (interface{}, error) {
	r := repo.NewRepository(p.RepoName())
	defer r.Close()

	result := make(map[string][]RawResult)
	for event, docs := range params {
		result[event] = insertEvents(r, event, docs...)
	}

	return result, nil
}
Esempio n. 2
0
func createEvent(p *model.Project, collName string, params CreateSingleEventParams) (interface{}, error) {
	r := repo.NewRepository(p.RepoName())
	defer r.Close()

	result := insertEvents(r, collName, params)
	if result[0]["success"] == true {
		return RawResult{"created": true}, nil
	} else {
		return RawResult{"created": false}, nil
	}
}
Esempio n. 3
0
func inspectCollection(p *model.Project, name string) (interface{}, error) {
	r := repo.NewRepository(p.RepoName())
	defer r.Close()

	c := r.C(name)
	var result query.RawExpr

	if err := c.Find(nil).One(&result); err != nil {
		return nil, err
	} else {
		return inspectResult{
			Name:       name,
			Properties: docToSchema(&result),
			Url:        fmt.Sprintf("/3.0/projects/<PROJECT_ID>/events/%s", name),
		}, nil
	}
}
Esempio n. 4
0
func inspectAllCollections(p *model.Project) (interface{}, error) {
	r := repo.NewRepository(p.RepoName())
	defer r.Close()

	collectionNames, err := r.CollectionNames()
	if err != nil {
		return nil, err
	}

	results := []interface{}{}
	for _, name := range collectionNames {
		if singleResult, err := inspectCollection(p, name); err != nil {
			return nil, err
		} else {
			results = append(results, singleResult)
		}
	}

	return results, nil
}
Esempio n. 5
0
func createProject() {
	db := model.DB()
	project := model.Project{
		UUID: uuid.NewV4().String(),
	}
	db.Create(&project)

	fmt.Printf("Created a new project.\n")
	fmt.Printf("Project UUID - %s\n", project.UUID)
	fmt.Printf("Project Master Key - %s\n", project.MasterKey().Value)
	fmt.Printf("Project Read Key - %s\n", project.ReadKey().Value)
	fmt.Printf("Project Write Key - %s\n", project.WriteKey().Value)
}
Esempio n. 6
0
func boundScope(project *model.Project, authKey string, scopes ...model.ApiScope) bool {
	ok := false

	for _, scope := range scopes {
		switch scope {
		case model.ApiReadKey:
			ok = (project.ReadKey().Value == authKey)
		case model.ApiWriteKey:
			ok = (project.WriteKey().Value == authKey)
		case model.ApiMasterKey:
			ok = (project.MasterKey().Value == authKey)
		}

		if ok {
			return ok
		}
	}

	return ok
}