Skip to content

Commit

Permalink
Merge pull request #17 from cyverse/implement_ticket
Browse files Browse the repository at this point in the history
Implement ticket
  • Loading branch information
iychoi authored Aug 12, 2021
2 parents eddc0ac + fb9c888 commit a4930d9
Show file tree
Hide file tree
Showing 39 changed files with 644 additions and 62 deletions.
9 changes: 9 additions & 0 deletions examples/ticket_list_dir/account.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
host:
hostname: "data.cyverse.org"
port: 1247
user:
username: ""
password: ""
zone: "iplant"
ticket: ""
auth_scheme: "native"
72 changes: 72 additions & 0 deletions examples/ticket_list_dir/list_dir.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package main

import (
"flag"
"fmt"
"io/ioutil"
"os"

"github.com/cyverse/go-irodsclient/fs"
"github.com/cyverse/go-irodsclient/irods/types"
"github.com/cyverse/go-irodsclient/irods/util"
)

func main() {
util.SetLogLevel(9)

// Parse cli parameters
flag.Parse()
args := flag.Args()

if len(args) != 1 {
fmt.Fprintf(os.Stderr, "Give an iRODS path!\n")
os.Exit(1)
}

inputPath := args[0]

// Read account configuration from YAML file
yaml, err := ioutil.ReadFile("account.yml")
if err != nil {
util.LogErrorf("err - %v", err)
panic(err)
}

account, err := types.CreateIRODSAccountFromYAML(yaml)
if err != nil {
util.LogErrorf("err - %v", err)
panic(err)
}

util.LogDebugf("Account : %v", account.MaskSensitiveData())

// Create a file system
appName := "list_dir_ticket"
filesystem, err := fs.NewFileSystemWithDefault(account, appName)
if err != nil {
util.LogErrorf("err - %v", err)
panic(err)
}

defer filesystem.Release()

entries, err := filesystem.List(inputPath)
if err != nil {
util.LogErrorf("err - %v", err)
panic(err)
}

if len(entries) == 0 {
fmt.Printf("Found no entries in the directory - %s\n", inputPath)
} else {
fmt.Printf("DIR: %s\n", inputPath)
for _, entry := range entries {
if entry.Type == fs.FSFileEntry {
fmt.Printf("> FILE:\t%s\t%d\n", entry.Path, entry.Size)
} else {
// dir
fmt.Printf("> DIRECTORY:\t%s\n", entry.Path)
}
}
}
}
10 changes: 0 additions & 10 deletions irods/common/error_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -910,13 +910,3 @@ func GetIRODSErrorString(code ErrorCode) string {
}
return fmt.Sprintf("ErrorCode: %d", int(code))
}

// MakeIRODSError creates an error from error code
func MakeIRODSError(code ErrorCode) error {
return fmt.Errorf("iRODS Error - %d (%s)", int(code), GetIRODSErrorString(code))
}

// MakeIRODSErrorFromString creates an error from error code and message
func MakeIRODSErrorFromString(code ErrorCode, message string) error {
return fmt.Errorf("iRODS Error - %d (%s): %s", int(code), GetIRODSErrorString(code), message)
}
16 changes: 16 additions & 0 deletions irods/connection/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ func (conn *IRODSConnection) Connect() error {
return err
}

if conn.Account.UseTicket() {
conn.showTicket()
}

conn.connected = true

return nil
Expand Down Expand Up @@ -322,6 +326,18 @@ func (conn *IRODSConnection) loginPAM() error {
return conn.loginNative(conn.generatedPasswordForPAM)
}

func (conn *IRODSConnection) showTicket() error {
util.LogInfo("Submitting a ticket to obtain access")

if len(conn.Account.Ticket) > 0 {
// show the ticket
ticketRequest := message.NewIRODSMessageTicketAdminRequest("session", conn.Account.Ticket)
ticketResult := message.IRODSMessageTicketAdminResponse{}
return conn.RequestAndCheck(ticketRequest, &ticketResult)
}
return nil
}

// Disconnect disconnects
func (conn *IRODSConnection) disconnectNow() error {
conn.connected = false
Expand Down
55 changes: 55 additions & 0 deletions irods/fs/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ func GetCollection(conn *connection.IRODSConnection, path string) (*types.IRODSC
return nil, fmt.Errorf("Could not receive a collection query result message - %v", err)
}

err = queryResult.CheckError()
if err != nil {
return nil, fmt.Errorf("Received a collection query error - %v", err)
}

if queryResult.RowCount != 1 {
// file not found
return nil, types.NewFileNotFoundErrorf("Could not find a collection")
Expand Down Expand Up @@ -150,6 +155,16 @@ func ListCollectionMeta(conn *connection.IRODSConnection, path string) ([]*types
return nil, fmt.Errorf("Could not receive a collection metadata query result message - %v", err)
}

err = queryResult.CheckError()
if err != nil {
if types.GetIRODSErrorCode(err) == common.CAT_NO_ROWS_FOUND {
// empty
return metas, nil
}

return nil, fmt.Errorf("Received a collection metadata query error - %v", err)
}

if queryResult.RowCount == 0 {
break
}
Expand Down Expand Up @@ -235,6 +250,16 @@ func ListCollectionAccess(conn *connection.IRODSConnection, path string) ([]*typ
return nil, fmt.Errorf("Could not receive a collection access query result message - %v", err)
}

err = queryResult.CheckError()
if err != nil {
if types.GetIRODSErrorCode(err) == common.CAT_NO_ROWS_FOUND {
// empty
return accesses, nil
}

return nil, fmt.Errorf("Received a collection access query error - %v", err)
}

if queryResult.RowCount == 0 {
break
}
Expand Down Expand Up @@ -318,6 +343,16 @@ func ListSubCollections(conn *connection.IRODSConnection, path string) ([]*types
return nil, fmt.Errorf("Could not receive a collection query result message - %v", err)
}

err = queryResult.CheckError()
if err != nil {
if types.GetIRODSErrorCode(err) == common.CAT_NO_ROWS_FOUND {
// empty
return collections, nil
}

return nil, fmt.Errorf("Received a collection query error - %v", err)
}

if queryResult.RowCount == 0 {
break
}
Expand Down Expand Up @@ -508,6 +543,16 @@ func SearchCollectionsByMeta(conn *connection.IRODSConnection, metaName string,
return nil, fmt.Errorf("Could not receive a collection query result message - %v", err)
}

err = queryResult.CheckError()
if err != nil {
if types.GetIRODSErrorCode(err) == common.CAT_NO_ROWS_FOUND {
// empty
return collections, nil
}

return nil, fmt.Errorf("Received a collection query error - %v", err)
}

if queryResult.RowCount == 0 {
break
}
Expand Down Expand Up @@ -610,6 +655,16 @@ func SearchCollectionsByMetaWildcard(conn *connection.IRODSConnection, metaName
return nil, fmt.Errorf("Could not receive a collection query result message - %v", err)
}

err = queryResult.CheckError()
if err != nil {
if types.GetIRODSErrorCode(err) == common.CAT_NO_ROWS_FOUND {
// empty
return collections, nil
}

return nil, fmt.Errorf("Received a collection query error - %v", err)
}

if queryResult.RowCount == 0 {
break
}
Expand Down
Loading

0 comments on commit a4930d9

Please sign in to comment.