Skip to content
This repository has been archived by the owner on Mar 21, 2023. It is now read-only.

Commit

Permalink
Added ticket support. refs #4933
Browse files Browse the repository at this point in the history
  • Loading branch information
John Jacquay committed May 12, 2016
1 parent a5093a1 commit 11ba1e2
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 2 deletions.
4 changes: 4 additions & 0 deletions collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ func getCollection(startPath string, recursive bool, con *Connection) (*Collecti
if er := col.init(); er != nil {
return nil, er
}
} else {
if er := col.Open(); er != nil {
return nil, er
}
}

return col, nil
Expand Down
30 changes: 28 additions & 2 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ type ConnectionOptions struct {

Username string
Password string
Ticket string
}

type Connection struct {
Expand All @@ -190,8 +191,8 @@ type Connection struct {
// New creates a connection to an iRods iCAT server. EnvironmentDefined and UserDefined
// constants are used in ConnectionOptions{ Type: ... }).
// When EnvironmentDefined is specified, the options stored in ~/.irods/irods_environment.json will be used.
// When UserDefined is specified you must also pass Host, Port, Username, and Zone. Password
// should be set regardless.
// When UserDefined is specified you must also pass Host, Port, Username, and Zone. Password
// should be set unless using an anonymous user account with tickets.
func New(opts ConnectionOptions) (*Connection, error) {
con := new(Connection)

Expand Down Expand Up @@ -233,9 +234,34 @@ func New(opts ConnectionOptions) (*Connection, error) {
return nil, newError(Fatal, fmt.Sprintf("iRods Connect Failed: %v", C.GoString(errMsg)))
}

if con.Options.Ticket != "" {
if err := con.SetTicket(con.Options.Ticket); err != nil {
return nil, err
}
}

return con, nil
}

// SetTicket is equivalent to using the -t flag with icommands
func (con *Connection) SetTicket(t string) error {
var (
status C.int
errMsg *C.char
)

con.Options.Ticket = t

ticket := C.CString(t)
defer C.free(unsafe.Pointer(ticket))

if status = C.gorods_set_session_ticket(con.ccon, ticket, &errMsg); status != 0 {
return newError(Fatal, fmt.Sprintf("iRods Set Ticket Failed: %v", C.GoString(errMsg)))
}

return nil
}

// Disconnect closes connection to iRods iCAT server, returns error on failure or nil on success
func (con *Connection) Disconnect() error {
if status := int(C.rcDisconnect(con.ccon)); status < 0 {
Expand Down
Binary file modified lib/build/libgorods.a
Binary file not shown.
1 change: 1 addition & 0 deletions lib/include/wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ int gorods_meta_collection(char *name, char *cwd, goRodsMetaResult_t* result, rc
int gorods_mod_meta(char* type, char* path, char* oa, char* ov, char* ou, char* na, char* nv, char* nu, rcComm_t* conn, char** err);
int gorods_add_meta(char* type, char* path, char* na, char* nv, char* nu, rcComm_t* conn, char** err);
int gorods_rm_meta(char* type, char* path, char* oa, char* ov, char* ou, rcComm_t* conn, char** err);
int gorods_set_session_ticket(rcComm_t *myConn, char *ticket, char** err);

int gorodsclearCollEnt( collEnt_t *collEnt );
int gorodsFreeCollEnt( collEnt_t *collEnt );
Expand Down
20 changes: 20 additions & 0 deletions lib/wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,26 @@ int gorods_connect(rcComm_t** conn, char* password, char** err) {
return 0;
}

int gorods_set_session_ticket(rcComm_t *myConn, char *ticket, char** err) {
ticketAdminInp_t ticketAdminInp;
int status;

ticketAdminInp.arg1 = "session";
ticketAdminInp.arg2 = ticket;
ticketAdminInp.arg3 = "";
ticketAdminInp.arg4 = "";
ticketAdminInp.arg5 = "";
ticketAdminInp.arg6 = "";

status = rcTicketAdmin( myConn, &ticketAdminInp );

if ( status != 0 ) {
sprintf(*err, "set ticket error %d \n", status);
}

return status;
}

int gorods_connect_env(rcComm_t** conn, char* host, int port, char* username, char* zone, char* password, char** err) {
int status;

Expand Down

0 comments on commit 11ba1e2

Please sign in to comment.