+
Skip to content
This repository was archived by the owner on Sep 28, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions cmd/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,22 @@ corectl context set rd-sense --engine localhost:9076 --comment "R&D Qlik Sense d
}, "comment")

var removeContextCmd = &cobra.Command{
Use: "rm <context name>",
Args: cobra.MinimumNArgs(1),
Short: "Remove a context",
Long: "Remove a context",
Example: "corectl context rm local-engine",
Use: "rm <context name>...",
Args: cobra.MinimumNArgs(1),
Short: "Remove one or more contexts",
Long: "Remove one or more contexts",
Example: `corectl context rm local-engine
corectl context rm ctx1 ctx2`,

Run: func(ccmd *cobra.Command, args []string) {
_, wasCurrent := internal.RemoveContext(args[0])
if wasCurrent {
var removedCurrent bool
for _, arg := range args {
_, wasCurrent := internal.RemoveContext(arg)
if wasCurrent {
removedCurrent = true
}
}
if removedCurrent {
printer.PrintCurrentContext("")
}
},
Expand Down
2 changes: 1 addition & 1 deletion docs/corectl_context.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Contexts are stored locally in your ~/.corectl/contexts.yml file.
* [corectl context clear](corectl_context_clear.md) - Set the current context to none
* [corectl context get](corectl_context_get.md) - Get context, current context by default
* [corectl context ls](corectl_context_ls.md) - List all contexts
* [corectl context rm](corectl_context_rm.md) - Remove a context
* [corectl context rm](corectl_context_rm.md) - Remove one or more contexts
* [corectl context set](corectl_context_set.md) - Set a context to the current configuration
* [corectl context use](corectl_context_use.md) - Specify what context to use

7 changes: 4 additions & 3 deletions docs/corectl_context_rm.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
## corectl context rm

Remove a context
Remove one or more contexts

### Synopsis

Remove a context
Remove one or more contexts

```
corectl context rm <context name> [flags]
corectl context rm <context name>... [flags]
```

### Examples

```
corectl context rm local-engine
corectl context rm ctx1 ctx2
```

### Options
Expand Down
2 changes: 1 addition & 1 deletion docs/spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
"description": "List all contexts"
},
"rm": {
"description": "Remove a context"
"description": "Remove one or more contexts"
},
"set": {
"description": "Set a context to the current configuration\n\nThis command creates or updates a context by using the supplied flags and any\nrelevant config information found in the config file (if any).\nThe information stored will be engine url, headers and certificates (if present)\nalong with comment and the context-name.",
Expand Down
33 changes: 21 additions & 12 deletions internal/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,16 @@ func ReadConnectionsFile(path string) *ConnectionsConfig {
func ReadConfig(explicitConfigFile, certPath string, withContext bool) {
var err error
if explicitConfigFile != "" {
if !filepath.IsAbs(explicitConfigFile) {
explicitConfigFile, err = filepath.Abs(strings.TrimSpace(explicitConfigFile))
if err != nil {
FatalErrorf("unexpected error when converting to absolute filepath: %s", err)
}
explicitConfigFile, err = toAbsPath(strings.TrimSpace(explicitConfigFile))
if err != nil {
FatalErrorf("unexpected error when converting to absolute filepath: %s", err)
}
configFile = explicitConfigFile
} else {
configFile = findConfigFile("corectl") // name of config file (without extension)
}
if certPath != "" && !filepath.IsAbs(certPath) {
certPath, err = filepath.Abs(strings.TrimSpace(certPath))
if certPath != "" {
certPath, err = toAbsPath(strings.TrimSpace(certPath))
if err != nil {
FatalErrorf("unexpected error when converting to absolute filepath: %s", err)
}
Expand All @@ -138,20 +136,24 @@ func ReadConfig(explicitConfigFile, certPath string, withContext bool) {
viper.Set("certificates", certPath)
}
InitLogOutput() // sets json, verbose and traffic
if configFile != "" {
switch {
case configFile != "":
ConfigDir = filepath.Dir(configFile)
LogVerbose("Using config file: " + configFile)
} else {
case withContext:
LogVerbose("No config file specified, using context.")
default:
LogVerbose("No config file specified, using default values.")
}
}

// ReadCertificates reads and loads the specified certificates
func ReadCertificates(certificatesPath string) *tls.Config {
// Read client and root certificates.
certFile := certificatesPath + "/client.pem"
keyFile := certificatesPath + "/client_key.pem"
caFile := certificatesPath + "/root.pem"
certPath := RelativeToProject(certificatesPath)
certFile := certPath + "/client.pem"
keyFile := certPath + "/client_key.pem"
caFile := certPath + "/root.pem"

cert, err := tls.LoadX509KeyPair(certFile, keyFile)
if err != nil {
Expand Down Expand Up @@ -340,3 +342,10 @@ func mergeContext(config *map[interface{}]interface{}) {
}
}
}

func toAbsPath(path string) (string, error) {
if !filepath.IsAbs(path) {
return filepath.Abs(path)
}
return path, nil
}
7 changes: 6 additions & 1 deletion internal/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func SetContext(contextName, comment string) string {

var context *Context
var update bool
var certificates string

if handler.Exists(contextName) {
context = handler.Get(contextName)
Expand All @@ -51,10 +52,14 @@ func SetContext(contextName, comment string) string {
LogVerbose("Creating context: " + contextName)
}

if certPath := viper.GetString("certificates"); certPath != "" {
certificates = RelativeToProject(viper.GetString("certificates"))
}

updated := context.Update(&map[string]interface{}{
"engine": viper.GetString("engine"),
"headers": viper.GetStringMapString("headers"),
"certificates": viper.GetString("certificates"),
"certificates": certificates,
"comment": comment,
})

Expand Down
3 changes: 1 addition & 2 deletions internal/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,9 @@ func connectToEngine(ctx context.Context, appName, ttl string, headers http.Head

if headers.Get("X-Qlik-Session") == "" {
sessionID := getSessionID(appName)
LogVerbose("SessionId: " + sessionID)
headers.Set("X-Qlik-Session", sessionID)
}
LogVerbose("SessionId " + headers.Get("X-Qlik-Session"))
LogVerbose("SessionId: " + headers.Get("X-Qlik-Session"))

var dialer = enigma.Dialer{}

Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载