+
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
3 changes: 1 addition & 2 deletions cmd/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ var importAppCmd = &cobra.Command{
if err != nil {
internal.FatalError(err)
}
// TODO: Do we want to parse to map to host specifically or just the engine property?
internal.SetAppIDToKnownApps(viper.GetString("engine"), appName, appID, false)
internal.SetAppIDToKnownApps(appName, appID, false)
fmt.Println("Imported app with new ID: " + appID)
},
}
Expand Down
37 changes: 23 additions & 14 deletions internal/knownapps.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@ var knownAppsFilePath = path.Join(userHomeDir(), ".corectl", "knownApps.yml")

// Fetch a matching app id from known apps for a specified app name
// If not found return the appName and found bool set to false
func applyNameToIDTransformation(engineURL string, appName string) (appID string, found bool) {
func applyNameToIDTransformation(appName string) (appID string, found bool) {
apps := getKnownApps()

if apps == nil {
LogVerbose("knownApps yaml file not found")
return appName, false
}

if id, exists := apps[engineURL][appName]; exists {
LogVerbose("Found id: " + id + " for app with name: " + appName + " @" + engineURL)
engineURL := GetEngineURL()
host := engineURL.Host

if id, exists := apps[host][appName]; exists {
LogVerbose("Found id: " + id + " for app with name: " + appName + " @" + host)
return id, true
}

Expand All @@ -46,23 +49,26 @@ func getKnownApps() map[string]map[string]string {
}

// Add an app or remove an app from known apps
func SetAppIDToKnownApps(engineURL string, appName string, appID string, remove bool) {
func SetAppIDToKnownApps(appName string, appID string, remove bool) {

createKnownAppsFileIfNotExist()
apps := getKnownApps()

engineURL := GetEngineURL()
host := engineURL.Host

// Either remove or add an entry
if remove {
if _, exists := apps[engineURL][appName]; exists {
delete(apps[engineURL], appName)
LogVerbose("Removed app with name: " + appName + " and id: " + appID + " @" + engineURL + " from known apps")
if _, exists := apps[host][appName]; exists {
delete(apps[host], appName)
LogVerbose("Removed app with name: " + appName + " and id: " + appID + " @" + host + " from known apps")
}
} else {
if apps[engineURL] == nil {
apps[engineURL] = map[string]string{}
if apps[host] == nil {
apps[host] = map[string]string{}
}
apps[engineURL][appName] = appID
LogVerbose("Added app with name: " + appName + " and id: " + appID + " @" + engineURL + " to known apps")
apps[host][appName] = appID
LogVerbose("Added app with name: " + appName + " and id: " + appID + " @" + host + " to known apps")
}

// Write to knownApps.yml
Expand All @@ -78,9 +84,12 @@ func createKnownAppsFileIfNotExist() {
if _, err := os.Stat(knownAppsFilePath); os.IsNotExist(err) {

// Create .corectl folder in home directory
err = os.Mkdir(path.Join(userHomeDir(), ".corectl"), os.ModePerm)
if err != nil {
FatalError("could not create .corectl folder in home directory: ", err)
corectlDir := path.Join(userHomeDir(), ".corectl")
if _, err := os.Stat(corectlDir); os.IsNotExist(err) {
err = os.Mkdir(corectlDir, os.ModePerm)
if err != nil {
FatalError("could not create .corectl folder in home directory: ", err)
}
}

// Create knownApps.yml in .corectl folder
Expand Down
10 changes: 5 additions & 5 deletions internal/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func connectToEngine(ctx context.Context, appName, ttl string, headers http.Head
//AppExists returns wether or not an app exists along with any eventual error from engine
func AppExists(ctx context.Context, engine string, appName string, headers http.Header, certificates *tls.Config) (bool, error) {
global := PrepareEngineStateWithoutApp(ctx, headers, certificates).Global
appID, _ := applyNameToIDTransformation(engine, appName)
appID, _ := applyNameToIDTransformation(appName)
_, err := global.GetAppEntry(ctx, appID)
if err != nil {
return false, fmt.Errorf("could not find any app by ID '%s': %s", appID, err)
Expand All @@ -81,14 +81,14 @@ func AppExists(ctx context.Context, engine string, appName string, headers http.
//DeleteApp removes the specified app from the engine.
func DeleteApp(ctx context.Context, engine string, appName string, headers http.Header, certificates *tls.Config) {
global := PrepareEngineStateWithoutApp(ctx, headers, certificates).Global
appID, _ := applyNameToIDTransformation(engine, appName)
appID, _ := applyNameToIDTransformation(appName)
succ, err := global.DeleteApp(ctx, appID)
if err != nil {
FatalErrorf("could not delete app with name '%s' and ID '%s': %s", appName, appID, err)
} else if !succ {
FatalErrorf("could not delete app with name '%s' and ID '%s'", appName, appID)
}
SetAppIDToKnownApps(engine, appName, appID, true)
SetAppIDToKnownApps(appName, appID, true)
}

// PrepareEngineState makes sure that the app idenfied by the supplied parameters is created or opened or reconnected to
Expand All @@ -107,7 +107,7 @@ func PrepareEngineState(ctx context.Context, headers http.Header, certificates *
}
}

appID, _ := applyNameToIDTransformation(engine, appName)
appID, _ := applyNameToIDTransformation(appName)

LogVerbose("---------- Connecting to app ----------")
global := connectToEngine(ctx, appName, ttl, headers, certificates)
Expand Down Expand Up @@ -139,7 +139,7 @@ func PrepareEngineState(ctx context.Context, headers http.Header, certificates *
FatalErrorf("could not create app with name '%s'", appName)
}
// Write app id to config
SetAppIDToKnownApps(engine, appName, appID, false)
SetAppIDToKnownApps(appName, appID, false)
doc, err = global.OpenDoc(ctx, appID, "", "", "", noData)
if err != nil {
FatalErrorf("could not do open app with ID '%s': %s", appID, err)
Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载