Documentation
¶
Overview ¶
Package cmd implements some basic examples of what can be achieved when combining the use of the Go SDK for Cells with the powerful Cobra framework to implement CLI client applications for Cells.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( DefaultConfig *cells_sdk.SdkConfig DefaultS3Config *cells_sdk.S3Config // Keys to retrieve configuration via environment variables KeyURL, KeyClientKey, KeyClientSecret, KeyUser, KeyPassword, KeySkipVerify = "TARGET_URL", "TARGET_CLIENT_KEY", "TARGET_CLIENT_SECRET", "TARGET_USER", "TARGET_PASSWORD", "TARGET_SKIP_VERIFY" // Keys to retrieve environment variables to configure connection to Pydio Cells S3 API KeyS3Endpoint, KeyS3Region, KeyS3Bucket, KeyS3ApiKey, KeyS3ApiSecret, KeyS3UsePydioSpecificHeader, KeyS3IsDebug = "TARGET_S3_ENDPOINT", "TARGET_S3_REGION", "TARGET_S3_BUCKET", "TARGET_S3_API_KEY", "TARGET_S3_API_SECRET", "TARGET_S3_USE_PYDIO_SPECIFIC_HEADER", "TARGET_S3_IS_DEBUG" )
var ExampleCmd = &cobra.Command{ Use: os.Args[0], Short: "Sample commands to show how to use the Go SDK for Pydio Cells", Long: ` # Sample commands to show how to use the Go SDK for Pydio Cells Pydio Cells comes with a powerful REST API that exposes various endpoints and enable management of a running Cells instance. As a convenience, the Pydio team also provide a ready to use SDK for the Go language that encapsulates the boiling code to wire things and provides a few chosen utilitary methods to ease implemantation when using the SDK in various Go programs. The children commands defined here show some basic examples of what can be achieved when combining the use of this SDK with the powerful Cobra framework to easily implement small CLI client applications. `, PersistentPreRun: func(cmd *cobra.Command, args []string) { if configFile == "" { // insure all necessary parameters are defined var msg string if host == "" { msg += " - Host URL\n" } if user == "" { msg += " - the login of an existing user\n" } if pwd == "" { msg += " - the password of an existing user\n" } if len(msg) > 0 { cmd.Println("Could not set up default configuration, missing arguments:\n", msg, "\n\nYou might also directly provide the relative path to a config.json file. See in-line help for more details.") os.Exit(1) } DefaultConfig = &cells_sdk.SdkConfig{ Url: host, User: user, Password: pwd, SkipVerify: skipVerify, } return } data, e := ioutil.ReadFile(configFile) if e != nil { log.Fatal("cannot read config file:", e) } var c cells_sdk.SdkConfig if e = json.Unmarshal(data, &c); e != nil { log.Fatal("Cannot decode config content for file at", configFile, "- route cause:", e) } else { DefaultConfig = &c } }, Run: func(cmd *cobra.Command, args []string) { cmd.Help() }, }
ExampleCmd is the parent of all example commands defined in this package. It takes care of the pre-configuration of the defaut connection to the SDK in its PersistentPreRun phase.
Functions ¶
func GetApiClient ¶
func GetApiClient(sdkConfig *cells_sdk.SdkConfig, anonymous ...bool) (context.Context, *client.PydioCellsRest, error)
GetApiClient connects to the Pydio Cells server defined by this config, by sending an authentication request to the OIDC service to get a valid JWT (or taking the JWT from cache). Also returns a context to be used in subsequent requests.
func GetDefaultConfigFiles ¶
GetDefaultConfigFiles simply retrieves absolute path for cells and s3 SDK config files given the absolute path to the root of the cells-sdk-go source code folder.
func SetUpEnvironment ¶
SetUpEnvironment retrieves parameters and stores them in the DefaultConfig of the SDK. configFilePath and s3ConfigFilePath can be <nil> if the parameters are defined via env variables.
Types ¶
This section is empty.