cmd

package
v5.0.0-alpha5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 10, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

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

View Source
var (
	DefaultConfig *cells_sdk.SdkConfig

	// Keys to retrieve configuration via environment variables
	KeyURL, KeyUser, KeyPassword, KeySkipVerify = "TARGET_URL", "TARGET_USER", "TARGET_PASSWORD", "TARGET_SKIP_VERIFY"
)
View Source
var (
	DefaultUserPolicies = []*models.ServiceResourcePolicy{
		{
			Action:  models.NewServiceResourcePolicyAction(readP),
			Effect:  models.NewServiceResourcePolicyPolicyEffect(allowP),
			Subject: "profile:" + ProfileStandard,
		},
		{
			Action:  models.NewServiceResourcePolicyAction(writeP),
			Effect:  models.NewServiceResourcePolicyPolicyEffect(allowP),
			Subject: "profile:" + ProfileAdmin,
		},
	}

	ProfileAdmin    = "admin"
	ProfileStandard = "standard"
)
View Source
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 useful methods to ease implementation 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 == "" {
			// Also insure all necessary parameters are defined
			var msg string
			if host == "" {
				msg += "- your host URL\n"
			}
			if personalToken != "" {
				DefaultConfig = &cellssdk.SdkConfig{
					AuthType:   cellssdk.AuthTypePat,
					Url:        host,
					SkipVerify: skipVerify,
					IdToken:    personalToken,
				}
				return
			}
			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 a connection to your server, missing arguments:\n", msg,
					"\nYou might also directly provide the relative path to a config.json file. See in-line help for further details.")
				os.Exit(1)
			}

			DefaultConfig = &cellssdk.SdkConfig{
				AuthType:   cellssdk.AuthTypeClientAuth,
				Url:        host,
				SkipVerify: skipVerify,
				User:       user,
				Password:   pwd,
			}
			return
		}

		data, e := os.ReadFile(configFile)
		if e != nil {
			log.Fatal("cannot read config file:", e)
		}

		var c cellssdk.SdkConfig
		if e = json.Unmarshal(data, &c); e != nil {
			log.Fatalf("Cannot decode config content for file at %s, cause: %s\n", configFile, e.Error())
		} else {
			DefaultConfig = &c
		}
	},
	Run: func(cmd *cobra.Command, args []string) {
		err := cmd.Usage()
		if err != nil {
			log.Fatalf("could not display usage helper: %s\n", err.Error())
		}
	},
}

ExampleCmd is the parent of all example commands defined in this package. It takes care of the pre-configuration of the default connection to the SDK in its PersistentPreRun phase.

Functions

func SetUpEnvironment

func SetUpEnvironment(configFilePath string) error

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

type MyProvider

type MyProvider struct {
	AccessKey string
	Secret    string
}

func (*MyProvider) IsExpired

func (m *MyProvider) IsExpired() bool

func (*MyProvider) Retrieve

func (m *MyProvider) Retrieve(_ context.Context) (aws.Credentials, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL