mirror of
https://github.com/ceph/go-ceph
synced 2024-12-26 08:02:31 +00:00
Merge pull request #11 from scjalliance/master
Added NewConnWithUser to allow users other than the default Signed-off-by: Noah Watkins <noahwatkins@gmail.com>
This commit is contained in:
commit
f5802b762b
@ -7,6 +7,7 @@ import "C"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
type RadosError int
|
||||
@ -35,3 +36,19 @@ func NewConn() (*Conn, error) {
|
||||
return nil, RadosError(int(ret))
|
||||
}
|
||||
}
|
||||
|
||||
// NewConnWithUser creates a new connection object with a custom username.
|
||||
// It returns the connection and an error, if any.
|
||||
func NewConnWithUser(user string) (*Conn, error) {
|
||||
c_user := C.CString(user)
|
||||
defer C.free(unsafe.Pointer(c_user))
|
||||
|
||||
conn := &Conn{}
|
||||
ret := C.rados_create(&conn.cluster, c_user)
|
||||
|
||||
if ret == 0 {
|
||||
return conn, nil
|
||||
} else {
|
||||
return nil, RadosError(int(ret))
|
||||
}
|
||||
}
|
||||
|
@ -436,3 +436,8 @@ func TestObjectIterator(t *testing.T) {
|
||||
|
||||
assert.Equal(t, objectList, createdList)
|
||||
}
|
||||
|
||||
func TestNewConnWithUser(t *testing.T) {
|
||||
_, err := rados.NewConnWithUser("admin")
|
||||
assert.Equal(t, err, nil)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user