github.com/cyverse/go-irodsclient@v0.13.2/examples/get_ticket_anon/get_ticket_anon.go (about)

     1  package main
     2  
     3  import (
     4  	"flag"
     5  	"fmt"
     6  	"os"
     7  
     8  	"github.com/cyverse/go-irodsclient/fs"
     9  	irods_fs "github.com/cyverse/go-irodsclient/irods/fs"
    10  	"github.com/cyverse/go-irodsclient/irods/session"
    11  	"github.com/cyverse/go-irodsclient/irods/types"
    12  
    13  	log "github.com/sirupsen/logrus"
    14  )
    15  
    16  func main() {
    17  	logger := log.WithFields(log.Fields{
    18  		"package":  "main",
    19  		"function": "main",
    20  	})
    21  
    22  	// Parse cli parameters
    23  	flag.Parse()
    24  	args := flag.Args()
    25  
    26  	if len(args) != 1 {
    27  		fmt.Fprintf(os.Stderr, "Give an iRODS ticket!\n")
    28  		os.Exit(1)
    29  	}
    30  
    31  	ticketName := args[0]
    32  
    33  	// Read account configuration from YAML file
    34  	yaml, err := os.ReadFile("account.yml")
    35  	if err != nil {
    36  		logger.Error(err)
    37  		panic(err)
    38  	}
    39  
    40  	account, err := types.CreateIRODSAccountFromYAML(yaml)
    41  	if err != nil {
    42  		logger.Error(err)
    43  		panic(err)
    44  	}
    45  
    46  	logger.Debugf("Account : %v", account.MaskSensitiveData())
    47  
    48  	// Create a file system
    49  	appName := "get_ticket_anon"
    50  	config := fs.NewFileSystemConfigWithDefault(appName)
    51  	sessConfig := session.NewIRODSSessionConfig(config.ApplicationName, config.ConnectionErrorTimeout, config.ConnectionInitNumber, config.ConnectionLifespan, config.OperationTimeout, config.ConnectionIdleTimeout, config.ConnectionMax, config.TCPBufferSize, config.StartNewTransaction)
    52  	sess, err := session.NewIRODSSession(account, sessConfig)
    53  	if err != nil {
    54  		logger.Error(err)
    55  		panic(err)
    56  	}
    57  
    58  	defer sess.Release()
    59  
    60  	conn, err := sess.AcquireConnection()
    61  	if err != nil {
    62  		logger.Error(err)
    63  		panic(err)
    64  	}
    65  
    66  	ticket, err := irods_fs.GetTicketForAnonymousAccess(conn, ticketName)
    67  	if err != nil {
    68  		logger.Error(err)
    69  		panic(err)
    70  	}
    71  
    72  	/*
    73  		filesystem, err := fs.NewFileSystemWithDefault(account, appName)
    74  		if err != nil {
    75  			logger.Error(err)
    76  			panic(err)
    77  		}
    78  
    79  		defer filesystem.Release()
    80  
    81  
    82  		entries, err := filesystem.List(inputPath)
    83  		if err != nil {
    84  			logger.Error(err)
    85  			panic(err)
    86  		}
    87  	*/
    88  
    89  	fmt.Printf("> Ticket: %s\n", ticketName)
    90  	fmt.Printf("%s\n", ticket.ToString())
    91  }