本文整理匯總了Golang中github.com/portworx/kvdb.Kvdb.RevokeUsersAccess方法的典型用法代碼示例。如果您正苦於以下問題:Golang Kvdb.RevokeUsersAccess方法的具體用法?Golang Kvdb.RevokeUsersAccess怎麽用?Golang Kvdb.RevokeUsersAccess使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/portworx/kvdb.Kvdb
的用法示例。
在下文中一共展示了Kvdb.RevokeUsersAccess方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: grantRevokeUser
func grantRevokeUser(kvRootUser kvdb.Kvdb, datastoreInit kvdb.DatastoreInit, t *testing.T) {
fmt.Println("grantRevokeUser")
kvRootUser.Create("allow1/foo", []byte("bar"), 0)
kvRootUser.Create("allow2/foo", []byte("bar"), 0)
kvRootUser.Create("disallow/foo", []byte("bar"), 0)
err := kvRootUser.GrantUserAccess("test", kvdb.ReadWritePermission, "allow1/*")
assert.NoError(t, err, "Error in Grant User")
err = kvRootUser.GrantUserAccess("test", kvdb.ReadWritePermission, "allow2/*")
assert.NoError(t, err, "Error in Grant User")
err = kvRootUser.GrantUserAccess("test", kvdb.ReadWritePermission, "disallow/*")
assert.NoError(t, err, "Error in Grant User")
err = kvRootUser.RevokeUsersAccess("test", kvdb.ReadWritePermission, "disallow/*")
assert.NoError(t, err, "Error in Revoke User")
options := make(map[string]string)
options[kvdb.UsernameKey] = "test"
options[kvdb.PasswordKey] = "test123"
options[kvdb.CAFileKey] = "/etc/pwx/pwx-ca.crt"
options[kvdb.CertFileKey] = "/etc/pwx/pwx-user-cert.crt"
options[kvdb.CertKeyFileKey] = "/etc/pwx/pwx-user-key.key"
machines := []string{"https://192.168.56.101:2379"}
kvTestUser, _ := datastoreInit("pwx/test", machines, options, fatalErrorCb())
actual := "actual"
_, err = kvTestUser.Put("allow1/foo", []byte(actual), 0)
assert.NoError(t, err, "Error in writing to allowed tree")
kvPair, err := kvTestUser.Get("allow1/foo")
assert.NoError(t, err, "Error in accessing allowed values")
if err == nil {
assert.Equal(t, string(kvPair.Value), "actual")
}
_, err = kvTestUser.Put("allow2/foo", []byte(actual), 0)
assert.NoError(t, err, "Error in writing to allowed tree")
kvPair, err = kvTestUser.Get("allow2/foo")
assert.NoError(t, err, "Error in accessing allowed values")
if err == nil {
assert.Equal(t, string(kvPair.Value), "actual")
}
actual2 := "actual2"
_, err = kvTestUser.Put("disallow/foo", []byte(actual2), 0)
assert.Error(t, err, "Expected error in writing to disallowed tree")
kvPair, err = kvTestUser.Get("disallow/foo")
assert.Error(t, err, "Expected error in accessing disallowed values")
kvRootUser.DeleteTree("allow1")
kvRootUser.DeleteTree("allow2")
kvRootUser.DeleteTree("disallow")
}