cmd

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2023 License: MIT Imports: 48 Imported by: 0

Documentation

Index

Constants

View Source
const (
	API          = "api"
	ClientId     = "client_id"
	ClientSecret = "client_secret"
)

Variables

View Source
var AbortRunbookExecution = atomic.Bool{}
View Source
var ApiHostToUrlMap = map[string]string{
	"api.moltin.com":             "https://euwest.cm.elasticpath.com/",
	"useast.api.elasticpath.com": "https://useast.cm.elasticpath.com/",
}
View Source
var DeleteApplicationKeys = true
View Source
var Logs = &cobra.Command{Use: "logs", Short: "Retrieve information about previous requests"}
View Source
var LogsClear = &cobra.Command{
	Use:   "clear",
	Short: "Clears all HTTP request and response logs",
	RunE: func(cmd *cobra.Command, args []string) error {
		return profiles.ClearAllRequestLogs()
	},
}
View Source
var LogsList = &cobra.Command{
	Use:   "list",
	Short: "List all HTTP logs",
	RunE: func(cmd *cobra.Command, args []string) error {
		files, err := profiles.GetAllRequestLogTitles()
		if err != nil {
			return err
		}

		for idx, name := range files {
			fmt.Printf("%d %s\n", idx, name)
		}
		return nil
	},
}
View Source
var LogsShow = &cobra.Command{
	Use:   "show <NUMBER>",
	Short: "Show HTTP logs for specific number, negative values are from the last value",
	Args:  cobra.MinimumNArgs(1),

	DisableFlagParsing: true,
	RunE: func(cmd *cobra.Command, args []string) error {

		i, err := strconv.Atoi(args[0])

		if err != nil {
			return fmt.Errorf("could not get the %s entry => %w", args[0], err)
		}

		content, err := profiles.GetNthRequestLog(i)

		if err != nil {
			return fmt.Errorf("couldn't print logs: %v", err)
		}

		fmt.Println(content)

		return nil
	},
}
View Source
var NonAlphaCharacter = regexp.MustCompile("[^A-Za-z]+")
View Source
var ResetStore = &cobra.Command{
	Use:   "reset-store [STORE_ID]",
	Short: "Resets a store to it's initial state on a \"best effort\" basis.",
	Long:  "This command resets a store to it's initial state. There are some limitations to this as for instance orders cannot be deleted, nor can audit entries.",
	Args:  cobra.MinimumNArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {
		ctx := context.Background()

		overrides := &httpclient.HttpParameterOverrides{
			QueryParameters: nil,
			OverrideUrlPath: "",
		}

		storeId, err := getStoreId(ctx, args)
		if err != nil {
			return fmt.Errorf("could not determine store id: %w", err)
		}

		rx, err := regexp.Compile("^" + args[0] + "$")

		if err != nil {
			if storeId != args[0] {
				return fmt.Errorf("You are trying to reset store id '%s', but you passed '%s' to this command", storeId, args[0])
			}
		} else {
			if !rx.MatchString(storeId) {
				return fmt.Errorf("You are trying to reset store id '%s', but you passed '%s' to this command which doesn't match", storeId, args[0])
			}
		}

		errors := make([]string, 0)

		_, err = getInternal(ctx, overrides, []string{"customer-authentication-settings"})

		if err != nil {
			errors = append(errors, err.Error())
		}

		_, err = getInternal(ctx, overrides, []string{"account-authentication-settings"})

		if err != nil {
			errors = append(errors, err.Error())
		}

		_, err = getInternal(ctx, overrides, []string{"merchant-realm-mappings"})

		if err != nil {
			errors = append(errors, err.Error())
		}

		_, err = getInternal(ctx, overrides, []string{"authentication-realms"})

		if err != nil {
			errors = append(errors, err.Error())
		}

		err, resetUndeletableResourcesErrors := resetResourcesUndeletableResources(ctx, overrides)

		if err != nil {
			return err
		}

		errors = append(errors, resetUndeletableResourcesErrors...)

		resourceNames := resources.GetPluralResourceNames()
		sort.Strings(resourceNames)
		err, deleteAllResourceDataErrors := deleteAllResourceData(resourceNames)
		if err != nil {
			return err
		}

		errors = append(errors, deleteAllResourceDataErrors...)

		if len(errors) > 0 {
			log.Warnf("The following errors occurred while deleting all data: \n\t%s", strings.Join(errors, "\n\t"))
		}

		return nil

	},
}
View Source
var RootCmd = &cobra.Command{
	Use:   os.Args[0],
	Short: "A command line interface for interacting with the Elastic Path Commerce Cloud API",
	Long: `The EPCC CLI tool provides a powerful command line interface for interacting with the Elastic Path Commerce Cloud API.

The EPCC CLI tool uses environment variables for configuration and in particular a tool like https://direnv.net/ which
auto populates your shell with environment variables when you switch directories. This allows you to store a context in a folder,
and come back to it at any time.

Environment Variables

- EPCC_API_BASE_URL - The API endpoint that we will hit
- EPCC_CLIENT_ID - The client id (available in Commerce Manager)
- EPCC_CLIENT_SECRET - The client secret (available in Commerce Manager)
- EPCC_BETA_API_FEATURES - Beta features in the API we want to enable.
- EPCC_CLI_HTTP_HEADER_[0,1,...] - An additional HTTP header to set with all requests, the format should be "HeaderName: value"
- EPCC_PROFILE - The name of the profile we will use (isolates namespace, credentials, etc...)

`,
	PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
		log.SetLevel(logger.Loglevel)

		env := config.GetEnv()
		if env.EPCC_RATE_LIMIT != 0 {
			rateLimit = env.EPCC_RATE_LIMIT
		}
		log.Debugf("Rate limit set to %d request per second ", rateLimit)
		httpclient.Initialize(rateLimit, requestTimeout)

		for _, runFunc := range persistentPreRunFuncs {
			err := runFunc(cmd, args)
			if err != nil {
				return err
			}
		}

		version.CheckVersionChangeAndLogWarning()

		return nil
	},

	SilenceUsage: true,
	Version:      fmt.Sprintf("%s (Commit %s)", version.Version, version.Commit),
}

Functions

func AddRootPreRunFunc added in v0.6.0

func AddRootPreRunFunc(f func(cmd *cobra.Command, args []string) error)

func ConvertSingularTypeToCmdArg added in v0.10.0

func ConvertSingularTypeToCmdArg(typeName string) string

func Execute

func Execute()

func FillUrlWithIds added in v0.10.0

func FillUrlWithIds(urlInfo *resources.CrudEntityInfo, uuids []string) string

func GetArgFunctionForCreate added in v0.10.0

func GetArgFunctionForCreate(resource resources.Resource) func(cmd *cobra.Command, args []string) error

func GetArgFunctionForDelete added in v0.10.0

func GetArgFunctionForDelete(resource resources.Resource) func(cmd *cobra.Command, args []string) error

func GetArgFunctionForUpdate added in v0.10.0

func GetArgFunctionForUpdate(resource resources.Resource) func(cmd *cobra.Command, args []string) error

func GetArgFunctionForUrl added in v0.10.0

func GetArgFunctionForUrl(name, resourceUrl string) func(cmd *cobra.Command, args []string) error

func GetArgumentExampleWithAlias added in v0.10.0

func GetArgumentExampleWithAlias(types []string) string

func GetArgumentExampleWithIds added in v0.10.0

func GetArgumentExampleWithIds(types []string, uuids []string) string

func GetCreateExample added in v0.10.0

func GetCreateExample(resource resources.Resource) string

func GetCreateLong added in v0.10.0

func GetCreateLong(resource resources.Resource) string

func GetCreateShort added in v0.10.0

func GetCreateShort(resource resources.Resource) string

func GetCreateUsageString added in v0.10.0

func GetCreateUsageString(resource resources.Resource) string

func GetDeleteAllShort added in v0.10.0

func GetDeleteAllShort(resource resources.Resource) string

func GetDeleteExample added in v0.10.0

func GetDeleteExample(resource resources.Resource) string

func GetDeleteLong added in v0.10.0

func GetDeleteLong(resource resources.Resource) string

func GetDeleteShort added in v0.10.0

func GetDeleteShort(resource resources.Resource) string

func GetDeleteUsage added in v0.10.0

func GetDeleteUsage(resource resources.Resource) string

func GetGetExample added in v0.10.0

func GetGetExample(resourceName string, resourceUrl string, usageGetType string, completionVerb int, urlInfo *resources.CrudEntityInfo, resource resources.Resource) string

func GetGetLong added in v0.10.0

func GetGetLong(resourceName string, resourceUrl string, usageGetType string, completionVerb int, urlInfo *resources.CrudEntityInfo, resource resources.Resource) string

func GetGetShort added in v0.10.0

func GetGetShort(resourceUrl string) string

func GetGetUsageString added in v0.10.0

func GetGetUsageString(resourceName string, resourceUrl string, completionVerb int, resource resources.Resource) string

func GetHelpResourceUrls added in v0.10.0

func GetHelpResourceUrls(resourceUrl string) string

func GetJsonExample added in v0.10.0

func GetJsonExample(description string, call string, header string, jsonTxt string) string

func GetJsonKeyValuesForUsage added in v0.10.0

func GetJsonKeyValuesForUsage(resource resources.Resource) string

func GetJsonSyntaxExample added in v0.10.0

func GetJsonSyntaxExample(resource resources.Resource, verb string, id string) string

func GetParameterUsageForTypes added in v0.10.0

func GetParameterUsageForTypes(types []string) string

func GetParametersForTypes added in v0.10.0

func GetParametersForTypes(types []string) string

func GetSingularTypeNames added in v0.10.0

func GetSingularTypeNames(types []string) []string

func GetUpdateExample added in v0.10.0

func GetUpdateExample(resource resources.Resource) string

func GetUpdateLong added in v0.10.0

func GetUpdateLong(resource resources.Resource) string

func GetUpdateShort added in v0.10.0

func GetUpdateShort(resource resources.Resource) string

func GetUpdateUsage added in v0.10.0

func GetUpdateUsage(resource resources.Resource) string

func GetUuidsForTypes added in v0.10.0

func GetUuidsForTypes(types []string) []string

func InitializeCmd added in v0.10.0

func InitializeCmd()

func NewCreateCommand added in v0.10.0

func NewCreateCommand(parentCmd *cobra.Command)

func NewDeleteAllCommand added in v0.10.0

func NewDeleteAllCommand(parentCmd *cobra.Command)

func NewDeleteCommand added in v0.10.0

func NewDeleteCommand(parentCmd *cobra.Command)

func NewGetCommand added in v0.10.0

func NewGetCommand(parentCmd *cobra.Command)

func NewUpdateCommand added in v0.10.0

func NewUpdateCommand(parentCmd *cobra.Command)

Types

This section is empty.

Jump to

Keyboard shortcuts

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