Exemple #1
0
// Sets the privileges to a whole new ACL
func (a ACL) Set(c *mgo.Collection, service string, object string, key string, user string, privileges map[string]interface{}) (*mgo.ChangeInfo, error) {
	selector := bson.M{"service": service, "object": object, "key": key, "user": user}
	update := copyMap(selector)
	update["privileges"] = privileges

	log.Finest("Setting Privilege: %s", update)
	return c.Upsert(selector, update)
}
Exemple #2
0
// Revokes the privileges from the existing ACL
func (a ACL) Revoke(c *mgo.Collection, service string, object string, key string, user string, privileges []string) (*mgo.ChangeInfo, error) {
	selector := bson.M{"service": service, "object": object, "key": key, "user": user}
	toRevoke := map[string]interface{}{}
	for _, privilege := range privileges {
		toRevoke["privileges."+privilege] = ""
	}
	log.Finest("Revoking Privilege: %s, %s", selector, toRevoke)
	return c.Upsert(selector, bson.M{"$unset": toRevoke})
}
Exemple #3
0
// Denies the privileges from the existing ACL
func (a ACL) Deny(c *mgo.Collection, service string, object string, key string, user string, privileges []string) (*mgo.ChangeInfo, error) {
	selector := bson.M{"service": service, "object": object, "key": key, "user": user}
	update := copyMap(selector)

	for _, privilege := range privileges {
		update["privileges."+privilege] = "deny"
	}

	log.Finest("Denying Privilege: %s", update)
	return c.Upsert(selector, bson.M{"$set": update})
}
Exemple #4
0
func insert_entry(coll *mgo.Collection, entry ReadEntry) (interface{}, error) {
	xe := struct {
		ReadEntry `bson:",inline"`
		TTL       time.Time `bson:"ttl"`
	}{entry, time.Now()}
	ci, err := coll.Upsert(bson.M{"uri": entry.Uri}, bson.M{"$setOnInsert": &xe})
	if ci == nil {
		return nil, err
	}
	return ci.UpsertedId, err
}
Exemple #5
0
func idempotentRecordVerse(cid interface{}, verse Verse, col *mgo.Collection) {
	_, e := col.Upsert(bson.M{
		"chapter":  cid,
		"position": verse.Position,
	}, bson.M{
		"chapter":  cid,
		"position": verse.Position,
		"rhema":    verse.Rhema,
	})
	if e != nil {
		panic(e)
	}
}
Exemple #6
0
func Upsert(collection *mgo.Collection, query interface{}, i interface{}) bool {
	_, err := collection.Upsert(query, i)
	return Err(err)
}
Exemple #7
0
func insert_entry(coll *mgo.Collection, entry Entry) (interface{}, error) {
	ci, err := coll.Upsert(bson.M{"link": entry.Link}, bson.M{"$setOnInsert": &entry})
	return ci.UpsertedId, err
}