-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
98 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package loader | ||
|
||
import ( | ||
"fmt" | ||
"github.com/joyme123/kubecm/pkg/types" | ||
) | ||
|
||
func Load(syncInfo *types.Sync) ([]byte, error) { | ||
if isLocal(syncInfo.From) { | ||
return localGet(syncInfo.From) | ||
} else if isSSH(syncInfo.From) { | ||
if len(syncInfo.Password) > 0 { | ||
return sshGetWithPassword(syncInfo.From, syncInfo.SSHPort, syncInfo.Password) | ||
} else { | ||
return sshGetWithPrivateKey(syncInfo.From, syncInfo.SSHPort, syncInfo.PrivateKey) | ||
} | ||
} else { | ||
return nil, fmt.Errorf("unsupport path: %s", syncInfo.From) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
package loader | ||
|
||
import ( | ||
"io/ioutil" | ||
"strings" | ||
"io/ioutil" | ||
"strings" | ||
) | ||
|
||
func IsLocal(path string) bool { | ||
if strings.HasPrefix(path, "file://") { | ||
return true | ||
} else if !strings.Contains(path, "://") { | ||
return true | ||
} | ||
func isLocal(path string) bool { | ||
if strings.HasPrefix(path, "file://") { | ||
return true | ||
} else if !strings.Contains(path, "://") { | ||
return true | ||
} | ||
|
||
return false | ||
return false | ||
} | ||
|
||
func LocalGet(path string) ([]byte, error) { | ||
path = strings.TrimLeft(path, "file://") | ||
return ioutil.ReadFile(path) | ||
func localGet(path string) ([]byte, error) { | ||
path = strings.TrimLeft(path, "file://") | ||
return ioutil.ReadFile(path) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters