Documentation
¶
Index ¶
- Constants
- Variables
- func AddRootPreRunFunc(f func(cmd *cobra.Command, args []string) error)
- func ConvertSingularTypeToCmdArg(typeName string) string
- func DumpTraces()
- func Execute()
- func FillUrlWithIds(urlInfo *resources.CrudEntityInfo, uuids []string) string
- func GenerateOpenApiInfo(resource *resources.Resource) string
- func GenerateResourceInfo(r *resources.Resource) string
- func GetArgFunctionForCreate(resource resources.Resource) func(cmd *cobra.Command, args []string) error
- func GetArgFunctionForDelete(resource resources.Resource) func(cmd *cobra.Command, args []string) error
- func GetArgFunctionForUpdate(resource resources.Resource) func(cmd *cobra.Command, args []string) error
- func GetArgFunctionForUrl(name, resourceUrl string) func(cmd *cobra.Command, args []string) error
- func GetArgumentExampleWithAlias(types []string) string
- func GetArgumentExampleWithIds(types []string, uuids []string) string
- func GetCreateExample(resource resources.Resource) string
- func GetCreateLong(resource resources.Resource) string
- func GetCreateShort(resource resources.Resource) string
- func GetCreateUsageString(resource resources.Resource) string
- func GetCurrentResourceState(resourceName string, ids []string, ...) (string, error)
- func GetDeleteAllShort(resource resources.Resource) string
- func GetDeleteExample(resource resources.Resource) string
- func GetDeleteLong(resource resources.Resource) string
- func GetDeleteShort(resource resources.Resource) string
- func GetDeleteUsage(resource resources.Resource) string
- func GetGetExample(resourceName string, resourceUrl string, usageGetType string, ...) string
- func GetGetLong(resourceName string, resourceUrl string, usageGetType string, ...) string
- func GetGetShort(resourceUrl string) string
- func GetGetUsageString(resourceName string, resourceUrl string, completionVerb int, ...) string
- func GetHelpResourceUrls(resourceUrl string) string
- func GetJsonExample(description string, call string, header string, jsonTxt string) string
- func GetJsonKeyValuesForUsage(resource resources.Resource) string
- func GetJsonSyntaxExample(resource resources.Resource, verb string, parentIds string, id string) string
- func GetOtherReferences(currentResource *resources.Resource) string
- func GetParameterDescription(aName string, aType string, usage string, aliasAttribute string, ...) string
- func GetParameterUsageForTypes(resource resources.Resource, types []string, bodyParameters bool) string
- func GetParametersForTypes(types []string) string
- func GetRootCommand() *cobra.Command
- func GetSingularTypeNames(types []string) []string
- func GetUpdateExample(resource resources.Resource) string
- func GetUpdateLong(resource resources.Resource) string
- func GetUpdateShort(resource resources.Resource) string
- func GetUpdateUsage(resource resources.Resource) string
- func GetUuidsForTypes(types []string) []string
- func InitializeCmd()
- func NewCreateCommand(parentCmd *cobra.Command) func()
- func NewDeleteAllCommand(parentCmd *cobra.Command) func()
- func NewDeleteCommand(parentCmd *cobra.Command) func()
- func NewGetCommand(parentCmd *cobra.Command) func()
- func NewHeadersCommand(parentCmd *cobra.Command) func()
- func NewResourceInfoCommand(parentCmd *cobra.Command) func()
- func NewUpdateCommand(parentCmd *cobra.Command) func()
- type CommandAndReset
- type ResourceCache
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/",
"euwest.api.elasticpath.com": "https://euwest.cm.elasticpath.com/",
"useast.api.elasticpath.com": "https://useast.cm.elasticpath.com/",
}
View Source
var CurlInlineAuth = false
View Source
var DeleteApplicationKeys = true
View Source
var DisableExampleOutput = false
View Source
var DisableLongOutput = false
View Source
var LoginCmd = &cobra.Command{ Use: "login", Short: "Login to the API via client_credentials, implicit, customer or account management tokens.", SilenceUsage: false, }
View Source
var LogoutHeaders = &cobra.Command{ Use: "headers", Short: "Clear all headers that are persisted in the profile", RunE: func(cmd *cobra.Command, args []string) error { for k, v := range headergroups.GetAllHeaders() { log.Infof("Unsetting: %s = %s", k, v) } headergroups.ClearAllHeaderGroups() return nil }, }
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() }, }
LogsCmd represents the logs command
View Source
var LogsCurlReplay = &cobra.Command{ Use: "curl-replay <NUMBER>", Short: "Generate a curl command that replays the request from a specific log entry", Args: cobra.MinimumNArgs(1), 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 get log: %v", err) } lines := strings.Split(content, "\n") if len(lines) == 0 { return fmt.Errorf("log entry has no content") } for i := range lines { lines[i] = strings.TrimSpace(lines[i]) } requestLine := lines[0] parts := strings.Fields(requestLine) if len(parts) < 2 { return fmt.Errorf("invalid request line: %s", requestLine) } method := parts[0] path := parts[1] // Extract headers - they appear after the request line until an empty line var host string var headers []string lineIndex := 1 for ; lineIndex < len(lines); lineIndex++ { line := lines[lineIndex] if line == "" { break } if strings.Contains(line, ": ") { headerParts := strings.SplitN(line, ": ", 2) if len(headerParts) == 2 { name := headerParts[0] value := headerParts[1] if name == "Host" { host = value } if name != "Content-Length" && name != "Accept-Encoding" { headers = append(headers, fmt.Sprintf("%s: %s", name, value)) } } } } if host == "" { return fmt.Errorf("could not find Host header in request") } env := config.GetEnv() var template = "https://%s%s" var authUrl = "" reqURL, err := url.Parse(env.EPCC_API_BASE_URL) if err != nil { log.Debugf("Could not get base url defaulting to https") authUrl = fmt.Sprintf("https://%s/oauth/access_token", host) } else if reqURL.Scheme != "" { template = reqURL.Scheme + "://%s%s" authUrl = fmt.Sprintf("%s://%s/oauth/access_token", reqURL.Scheme, host) } else { authUrl = fmt.Sprintf("https://%s/oauth/access_token", host) } url := fmt.Sprintf(template, host, path) // Look for request body - it would be after the headers and before the response var body string bodyStartIndex := lineIndex + 1 responseStartIndex := -1 for j := bodyStartIndex; j < len(lines); j++ { if strings.HasPrefix(lines[j], "HTTP/") { responseStartIndex = j break } } if responseStartIndex > bodyStartIndex { bodyLines := lines[bodyStartIndex:responseStartIndex] if len(bodyLines) > 0 { body = strings.Join(bodyLines, "\n") } } // Build the curl command var sb strings.Builder sb.WriteString(fmt.Sprintf("curl -X %s \\\n '%s'", method, url)) for _, header := range headers { if strings.HasPrefix(header, "Authorization") && CurlInlineAuth { if env.EPCC_CLIENT_SECRET != "" { sb.WriteString(fmt.Sprintf(" \\\n -H \"Authorization: Bearer $(curl -s -X POST '%s' -d 'client_id=%s' -d 'client_secret=%s' -d 'grant_type=client_credentials' | jq -r .access_token)\"", authUrl, env.EPCC_CLIENT_ID, env.EPCC_CLIENT_SECRET)) } else { sb.WriteString(fmt.Sprintf(" \\\n -H \"Authorization: Bearer $(curl -s -X POST '%s' -d 'client_id=%s' -d 'grant_type=implicit' | jq -r .access_token)\"", authUrl, env.EPCC_CLIENT_ID)) } } else { sb.WriteString(fmt.Sprintf(" \\\n -H '%s'", header)) } } if strings.TrimSpace(body) != "" { escapedBody := strings.ReplaceAll(body, "'", "'\\''") sb.WriteString(fmt.Sprintf(" \\\n -d '%s'", escapedBody)) } fmt.Println(sb.String()) return nil }, }
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), 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) } if LogsShowPrettyJson { for l := range strings.Lines(content) { var s any if err := gojson.Unmarshal([]byte(l), &s); err == nil { json.PrintJsonToStdout(l) } else { fmt.Print(l) } } } else { fmt.Println(content) } return nil }, }
View Source
var LogsShowPrettyJson = false
View Source
var NonAlphaCharacter = regexp.MustCompile("[^A-Za-z]+")
View Source
var OidcPort uint16 = 8080
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 := clictx.Ctx e := config.GetEnv() if len(e.EPCC_CLI_DISABLE_RESOURCES) > 0 { return fmt.Errorf("Cannot use the reset-store command with EPCC_CLI_DISABLE_RESOURCES set") } 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 = authentication.ClearCustomerToken() if err != nil { log.Warnf("Couldn't delete the customer token") } err = authentication.ClearAccountManagementAuthenticationToken() if err != nil { log.Warnf("Couldn't delete the account management token") } _, err = rest.GetInternal(ctx, overrides, []string{"customer-authentication-settings"}, false, false) if err != nil { errors = append(errors, err.Error()) } _, err = rest.GetInternal(ctx, overrides, []string{"account-authentication-settings"}, false, false) if err != nil { errors = append(errors, err.Error()) } _, err = rest.GetInternal(ctx, overrides, []string{"merchant-realm-mappings"}, false, false) if err != nil { errors = append(errors, err.Error()) } _, err = rest.GetInternal(ctx, overrides, []string{"authentication-realms"}, false, false) 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")) } err = aliases.ClearAllAliases() if err != nil { log.Warnf("Couldn't clear all aliases") } return nil }, }
View Source
var RootCmd = GetRootCommand()
Functions ¶
func AddRootPreRunFunc ¶ added in v0.6.0
func ConvertSingularTypeToCmdArg ¶ added in v0.10.0
func DumpTraces ¶ added in v0.11.0
func DumpTraces()
func FillUrlWithIds ¶ added in v0.10.0
func FillUrlWithIds(urlInfo *resources.CrudEntityInfo, uuids []string) string
func GenerateOpenApiInfo ¶ added in v0.14.0
func GenerateResourceInfo ¶ added in v0.14.0
func GetArgFunctionForCreate ¶ added in v0.10.0
func GetArgFunctionForDelete ¶ added in v0.10.0
func GetArgFunctionForUpdate ¶ added in v0.10.0
func GetArgFunctionForUrl ¶ added in v0.10.0
func GetArgumentExampleWithAlias ¶ added in v0.10.0
func GetArgumentExampleWithIds ¶ added in v0.10.0
func GetCreateExample ¶ added in v0.10.0
func GetCreateLong ¶ added in v0.10.0
func GetCreateShort ¶ added in v0.10.0
func GetCreateUsageString ¶ added in v0.10.0
func GetCurrentResourceState ¶ added in v0.14.0
func GetCurrentResourceState(resourceName string, ids []string, overrides *httpclient.HttpParameterOverrides) (string, error)
func GetDeleteAllShort ¶ added in v0.10.0
func GetDeleteExample ¶ added in v0.10.0
func GetDeleteLong ¶ added in v0.10.0
func GetDeleteShort ¶ added in v0.10.0
func GetDeleteUsage ¶ added in v0.10.0
func GetGetExample ¶ added in v0.10.0
func GetGetLong ¶ added in v0.10.0
func GetGetShort ¶ added in v0.10.0
func GetGetUsageString ¶ added in v0.10.0
func GetHelpResourceUrls ¶ added in v0.10.0
func GetJsonExample ¶ added in v0.10.0
func GetJsonKeyValuesForUsage ¶ added in v0.10.0
func GetJsonSyntaxExample ¶ added in v0.10.0
func GetOtherReferences ¶ added in v0.14.0
GetOtherReferences finds commands from other resources that reference the current resource
func GetParameterDescription ¶ added in v0.14.0
func GetParameterUsageForTypes ¶ added in v0.10.0
func GetParametersForTypes ¶ added in v0.10.0
func GetRootCommand ¶ added in v0.11.0
func GetSingularTypeNames ¶ added in v0.10.0
func GetUpdateExample ¶ added in v0.10.0
func GetUpdateLong ¶ added in v0.10.0
func GetUpdateShort ¶ added in v0.10.0
func GetUpdateUsage ¶ added in v0.10.0
func GetUuidsForTypes ¶ added in v0.10.0
func InitializeCmd ¶ added in v0.10.0
func InitializeCmd()
func NewCreateCommand ¶ added in v0.10.0
func NewDeleteAllCommand ¶ added in v0.10.0
func NewDeleteCommand ¶ added in v0.10.0
func NewGetCommand ¶ added in v0.10.0
func NewHeadersCommand ¶ added in v0.11.0
func NewResourceInfoCommand ¶ added in v0.14.0
func NewUpdateCommand ¶ added in v0.10.0
Types ¶
type CommandAndReset ¶ added in v0.10.1
type CommandAndReset struct {
// contains filtered or unexported fields
}
Click to show internal directories.
Click to hide internal directories.