Skip to content

Commit

Permalink
Implement ticket modify/remove APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
iychoi committed May 23, 2023
1 parent 626fa4d commit 7e771a0
Show file tree
Hide file tree
Showing 8 changed files with 527 additions and 45 deletions.
2 changes: 1 addition & 1 deletion examples/list_ticket/list_ticket.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func main() {
fmt.Printf(" owner zone: %s\n", ticket.OwnerZone)
fmt.Printf(" object type: %s\n", ticket.ObjectType)
fmt.Printf(" path: %s\n", ticket.Path)
fmt.Printf(" expireTime: %s\n", ticket.ExpireTime)
fmt.Printf(" expireTime: %s\n", ticket.ExpirationTime)
fmt.Printf(" uses limit: %d\n", ticket.UsesLimit)
fmt.Printf(" uses count: %d\n", ticket.UsesCount)
fmt.Printf(" write file limit: %d\n", ticket.WriteFileLimit)
Expand Down
242 changes: 242 additions & 0 deletions fs/fs_ticket.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package fs

import (
"time"

irods_fs "github.com/cyverse/go-irodsclient/irods/fs"
"github.com/cyverse/go-irodsclient/irods/types"
"github.com/cyverse/go-irodsclient/irods/util"
Expand Down Expand Up @@ -149,3 +151,243 @@ func (fs *FileSystem) CreateTicket(ticketName string, ticketType types.TicketTyp

return nil
}

// DeleteTicket deletes the given ticket
func (fs *FileSystem) DeleteTicket(ticketName string) error {
conn, err := fs.metaSession.AcquireConnection()
if err != nil {
return err
}
defer fs.metaSession.ReturnConnection(conn)

err = irods_fs.DeleteTicket(conn, ticketName)
if err != nil {
return err
}

return nil
}

// ModifyTicketUseLimit modifies the use limit of the given ticket
func (fs *FileSystem) ModifyTicketUseLimit(ticketName string, uses int) error {
conn, err := fs.metaSession.AcquireConnection()
if err != nil {
return err
}
defer fs.metaSession.ReturnConnection(conn)

err = irods_fs.ModifyTicketUseLimit(conn, ticketName, uses)
if err != nil {
return err
}

return nil
}

// ClearTicketUseLimit clears the use limit of the given ticket
func (fs *FileSystem) ClearTicketUseLimit(ticketName string) error {
conn, err := fs.metaSession.AcquireConnection()
if err != nil {
return err
}
defer fs.metaSession.ReturnConnection(conn)

err = irods_fs.ClearTicketUseLimit(conn, ticketName)
if err != nil {
return err
}

return nil
}

// ModifyTicketWriteFileLimit modifies the write file limit of the given ticket
func (fs *FileSystem) ModifyTicketWriteFileLimit(ticketName string, count int) error {
conn, err := fs.metaSession.AcquireConnection()
if err != nil {
return err
}
defer fs.metaSession.ReturnConnection(conn)

err = irods_fs.ModifyTicketWriteFileLimit(conn, ticketName, count)
if err != nil {
return err
}

return nil
}

// ClearTicketWriteFileLimit clears the write file limit of the given ticket
func (fs *FileSystem) ClearTicketWriteFileLimit(ticketName string) error {
conn, err := fs.metaSession.AcquireConnection()
if err != nil {
return err
}
defer fs.metaSession.ReturnConnection(conn)

err = irods_fs.ClearTicketWriteFileLimit(conn, ticketName)
if err != nil {
return err
}

return nil
}

// ModifyTicketWriteByteLimit modifies the write byte limit of the given ticket
func (fs *FileSystem) ModifyTicketWriteByteLimit(ticketName string, bytes int) error {
conn, err := fs.metaSession.AcquireConnection()
if err != nil {
return err
}
defer fs.metaSession.ReturnConnection(conn)

err = irods_fs.ModifyTicketWriteByteLimit(conn, ticketName, bytes)
if err != nil {
return err
}

return nil
}

// ClearTicketWriteByteLimit clears the write byte limit of the given ticket
func (fs *FileSystem) ClearTicketWriteByteLimit(ticketName string) error {
conn, err := fs.metaSession.AcquireConnection()
if err != nil {
return err
}
defer fs.metaSession.ReturnConnection(conn)

err = irods_fs.ClearTicketWriteByteLimit(conn, ticketName)
if err != nil {
return err
}

return nil
}

// AddTicketAllowedUser adds a user to the allowed user names list of the given ticket
func (fs *FileSystem) AddTicketAllowedUser(ticketName string, userName string) error {
conn, err := fs.metaSession.AcquireConnection()
if err != nil {
return err
}
defer fs.metaSession.ReturnConnection(conn)

err = irods_fs.AddTicketAllowedUser(conn, ticketName, userName)
if err != nil {
return err
}

return nil
}

// RemoveTicketAllowedUser removes the user from the allowed user names list of the given ticket
func (fs *FileSystem) RemoveTicketAllowedUser(ticketName string, userName string) error {
conn, err := fs.metaSession.AcquireConnection()
if err != nil {
return err
}
defer fs.metaSession.ReturnConnection(conn)

err = irods_fs.RemoveTicketAllowedUser(conn, ticketName, userName)
if err != nil {
return err
}

return nil
}

// AddTicketAllowedGroup adds a group to the allowed group names list of the given ticket
func (fs *FileSystem) AddTicketAllowedGroup(ticketName string, groupName string) error {
conn, err := fs.metaSession.AcquireConnection()
if err != nil {
return err
}
defer fs.metaSession.ReturnConnection(conn)

err = irods_fs.AddTicketAllowedGroup(conn, ticketName, groupName)
if err != nil {
return err
}

return nil
}

// RemoveTicketAllowedGroup removes the group from the allowed group names list of the given ticket
func (fs *FileSystem) RemoveTicketAllowedGroup(ticketName string, groupName string) error {
conn, err := fs.metaSession.AcquireConnection()
if err != nil {
return err
}
defer fs.metaSession.ReturnConnection(conn)

err = irods_fs.RemoveTicketAllowedGroup(conn, ticketName, groupName)
if err != nil {
return err
}

return nil
}

// AddTicketAllowedHost adds a host to the allowed hosts list of the given ticket
func (fs *FileSystem) AddTicketAllowedHost(ticketName string, host string) error {
conn, err := fs.metaSession.AcquireConnection()
if err != nil {
return err
}
defer fs.metaSession.ReturnConnection(conn)

err = irods_fs.AddTicketAllowedHost(conn, ticketName, host)
if err != nil {
return err
}

return nil
}

// RemoveTicketAllowedHost removes the host from the allowed hosts list of the given ticket
func (fs *FileSystem) RemoveTicketAllowedHost(ticketName string, host string) error {
conn, err := fs.metaSession.AcquireConnection()
if err != nil {
return err
}
defer fs.metaSession.ReturnConnection(conn)

err = irods_fs.RemoveTicketAllowedHost(conn, ticketName, host)
if err != nil {
return err
}

return nil
}

// ModifyTicketExpirationTime modifies the expiration time of the given ticket
func (fs *FileSystem) ModifyTicketExpirationTime(ticketName string, expirationTime time.Time) error {
conn, err := fs.metaSession.AcquireConnection()
if err != nil {
return err
}
defer fs.metaSession.ReturnConnection(conn)

err = irods_fs.ModifyTicketExpirationTime(conn, ticketName, expirationTime)
if err != nil {
return err
}

return nil
}

// ClearTicketExpirationTime clears the expiration time of the given ticket
func (fs *FileSystem) ClearTicketExpirationTime(ticketName string) error {
conn, err := fs.metaSession.AcquireConnection()
if err != nil {
return err
}
defer fs.metaSession.ReturnConnection(conn)

err = irods_fs.ClearTicketExpirationTime(conn, ticketName)
if err != nil {
return err
}

return nil
}
28 changes: 5 additions & 23 deletions irods/connection/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,11 @@ func (conn *IRODSConnection) Connect() error {
}

if conn.account.UseTicket() {
conn.showTicket()
req := message.NewIRODSMessageTicketAdminRequest("session", conn.account.Ticket)
err := conn.RequestAndCheck(req, &message.IRODSMessageAdminResponse{}, nil)
if err != nil {
return xerrors.Errorf("received supply ticket error: %w", err)
}
}

conn.connected = true
Expand Down Expand Up @@ -491,28 +495,6 @@ func (conn *IRODSConnection) loginPAM() error {
return conn.login(conn.generatedPasswordForPAM)
}

func (conn *IRODSConnection) showTicket() error {
logger := log.WithFields(log.Fields{
"package": "connection",
"struct": "IRODSConnection",
"function": "showTicket",
})

logger.Debug("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{}
err := conn.RequestAndCheck(ticketRequest, &ticketResult, nil)
if err != nil {
return xerrors.Errorf("received irods ticket request error: %w", err)
}
return nil
}
return nil
}

// Disconnect disconnects
func (conn *IRODSConnection) disconnectNow() error {
conn.connected = false
Expand Down
Loading

0 comments on commit 7e771a0

Please sign in to comment.