コード例 #1
0
ファイル: data_cleansing_test.go プロジェクト: bac/juju
func (s *dataCleansingSuite) TestEscapeKeys_EscapesDollarSigns(c *gc.C) {
	before := map[string]interface{}{
		"$a": "c",
	}
	after := utils.EscapeKeys(before)

	c.Check(after, gc.DeepEquals, map[string]interface{}{
		"\uff04" + "a": "c",
	})
}
コード例 #2
0
ファイル: data_cleansing_test.go プロジェクト: bac/juju
func (s *dataCleansingSuite) TestEscapeKeys_EscapesPeriods(c *gc.C) {
	before := map[string]interface{}{
		"a.b": "c",
	}
	after := utils.EscapeKeys(before)

	c.Check(after, gc.DeepEquals, map[string]interface{}{
		"a" + "\uff0e" + "b": "c",
	})
}
コード例 #3
0
ファイル: audit_test.go プロジェクト: bac/juju
func (*AuditSuite) TestPutAuditEntry_PersistAuditEntry(c *gc.C) {

	requested := audit.AuditEntry{
		JujuServerVersion: version.MustParse("1.0.0"),
		ModelUUID:         utils.MustNewUUID().String(),
		Timestamp:         coretesting.NonZeroTime().UTC(),
		RemoteAddress:     "8.8.8.8",
		OriginType:        "user",
		OriginName:        "bob",
		Operation:         "status",
		Data: map[string]interface{}{
			"a": "b",
			"$a.b": map[string]interface{}{
				"b.$a": "c",
			},
		},
	}

	var insertDocsCalled bool
	insertDocs := func(collectionName string, docs ...interface{}) error {
		insertDocsCalled = true
		c.Check(collectionName, gc.Equals, "audit.log")
		c.Assert(docs, gc.HasLen, 1)

		serializedAuditDoc, err := bson.Marshal(docs[0])
		c.Assert(err, jc.ErrorIsNil)

		requestedTimeBlob, err := requested.Timestamp.MarshalText()
		c.Assert(err, jc.ErrorIsNil)

		c.Check(string(serializedAuditDoc), jc.BSONEquals, map[string]interface{}{
			"juju-server-version": requested.JujuServerVersion,
			"model-uuid":          requested.ModelUUID,
			"timestamp":           string(requestedTimeBlob),
			"remote-address":      "8.8.8.8",
			"origin-type":         requested.OriginType,
			"origin-name":         requested.OriginName,
			"operation":           requested.Operation,
			"data":                mongoutils.EscapeKeys(requested.Data),
		})

		return nil
	}

	putAuditEntry := stateaudit.PutAuditEntryFn("audit.log", insertDocs)
	err := putAuditEntry(requested)
	c.Assert(err, jc.ErrorIsNil)

	c.Assert(insertDocsCalled, jc.IsTrue)
}
コード例 #4
0
ファイル: data_cleansing_test.go プロジェクト: bac/juju
func (s *dataCleansingSuite) TestEscapeKeys_RecursivelyEscapes(c *gc.C) {
	before := map[string]interface{}{
		"$a": "c",
		"b": map[string]interface{}{
			"$foo.bar": "baz",
		},
	}
	after := utils.EscapeKeys(before)

	c.Check(after, gc.DeepEquals, map[string]interface{}{
		"\uff04" + "a": "c",
		"b": map[string]interface{}{
			"\uff04" + "foo" + "\uff0e" + "bar": "baz",
		},
	})
}
コード例 #5
0
ファイル: audit.go プロジェクト: bac/juju
func auditEntryDocFromAuditEntry(auditEntry audit.AuditEntry) (auditEntryDoc, error) {

	timeAsBlob, err := auditEntry.Timestamp.MarshalText()
	if err != nil {
		return auditEntryDoc{}, errors.Trace(err)
	}

	return auditEntryDoc{
		JujuServerVersion: auditEntry.JujuServerVersion,
		ModelUUID:         auditEntry.ModelUUID,
		Timestamp:         string(timeAsBlob),
		RemoteAddress:     auditEntry.RemoteAddress,
		OriginType:        auditEntry.OriginType,
		OriginName:        auditEntry.OriginName,
		Operation:         auditEntry.Operation,
		Data:              utils.EscapeKeys(auditEntry.Data),
	}, nil
}
コード例 #6
0
ファイル: export_test.go プロジェクト: kat-co/juju
// PrimeUnitStatusHistory will add count history elements, advancing the test clock by
// one second for each entry.
func PrimeUnitStatusHistory(
	c *gc.C, clock *testing.Clock,
	unit *Unit, statusVal status.Status,
	count, batchSize int,
	nextData func(int) map[string]interface{},
) {
	globalKey := unit.globalKey()

	history, closer := unit.st.getCollection(statusesHistoryC)
	defer closer()
	historyW := history.Writeable()

	var data map[string]interface{}
	for i := 0; i < count; {
		var docs []interface{}
		for j := 0; j < batchSize && i < count; j++ {
			clock.Advance(time.Second)
			if nextData != nil {
				data = utils.EscapeKeys(nextData(i))
			}
			docs = append(docs, &historicalStatusDoc{
				Status:     statusVal,
				StatusData: data,
				Updated:    clock.Now().UnixNano(),
				GlobalKey:  globalKey,
			})
			// Seems like you can't increment two values in one loop
			i++
		}
		err := historyW.Insert(docs...)
		c.Assert(err, jc.ErrorIsNil)
	}
	// Set the status for the unit itself.
	doc := statusDoc{
		Status:     statusVal,
		StatusData: data,
		Updated:    clock.Now().UnixNano(),
	}
	buildTxn := updateStatusSource(unit.st, globalKey, doc)
	err := unit.st.run(buildTxn)
	c.Assert(err, jc.ErrorIsNil)
}
コード例 #7
0
ファイル: status.go プロジェクト: bac/juju
// setStatus inteprets the supplied params as documented on the type.
func setStatus(st *State, params setStatusParams) (err error) {
	defer errors.DeferredAnnotatef(&err, "cannot set status")

	doc := statusDoc{
		Status:     params.status,
		StatusInfo: params.message,
		StatusData: utils.EscapeKeys(params.rawData),
		Updated:    params.updated.UnixNano(),
	}
	probablyUpdateStatusHistory(st, params.globalKey, doc)

	// Set the authoritative status document, or fail trying.
	buildTxn := updateStatusSource(st, params.globalKey, doc)
	if params.token != nil {
		buildTxn = buildTxnWithLeadership(buildTxn, params.token)
	}
	err = st.run(buildTxn)
	if cause := errors.Cause(err); cause == mgo.ErrNotFound {
		return errors.NotFoundf(params.badge)
	}
	return errors.Trace(err)
}