-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from MZC-CSC/develop
minor changes for performance evaluation
- Loading branch information
Showing
21 changed files
with
2,146 additions
and
1,957 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,6 @@ ant | |
data | ||
conf | ||
container-volume | ||
./bin/** | ||
./bin/** | ||
|
||
config.yaml |
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
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,57 @@ | ||
package load | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
"github.com/cloud-barista/cm-ant/internal/utils" | ||
) | ||
|
||
// getAddAuthorizedKeyCommand returns a command to add the authorized key. | ||
func getAddAuthorizedKeyCommand(pkName, pubkName string) (string, error) { | ||
pubKeyPath, _, err := validateKeyPair(pkName, pubkName) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
pub, err := utils.ReadToString(pubKeyPath) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
addAuthorizedKeyScript := utils.JoinRootPathWith("/script/add-authorized-key.sh") | ||
|
||
addAuthorizedKeyCommand, err := utils.ReadToString(addAuthorizedKeyScript) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
addAuthorizedKeyCommand = strings.Replace(addAuthorizedKeyCommand, `PUBLIC_KEY=""`, fmt.Sprintf(`PUBLIC_KEY="%s"`, pub), 1) | ||
return addAuthorizedKeyCommand, nil | ||
} | ||
|
||
// validateKeyPair checks and generates SSH key pair if it doesn't exist. | ||
func validateKeyPair(pkName, pubkName string) (string, string, error) { | ||
homeDir, err := os.UserHomeDir() | ||
if err != nil { | ||
return "", "", err | ||
} | ||
|
||
privKeyPath := fmt.Sprintf("%s/.ssh/%s", homeDir, pkName) | ||
pubKeyPath := fmt.Sprintf("%s/.ssh/%s", homeDir, pubkName) | ||
|
||
err = utils.CreateFolderIfNotExist(fmt.Sprintf("%s/.ssh", homeDir)) | ||
if err != nil { | ||
return pubKeyPath, privKeyPath, err | ||
} | ||
|
||
exist := utils.ExistCheck(privKeyPath) | ||
if !exist { | ||
err := utils.GenerateSSHKeyPair(4096, privKeyPath, pubKeyPath) | ||
if err != nil { | ||
return pubKeyPath, privKeyPath, err | ||
} | ||
} | ||
return pubKeyPath, privKeyPath, nil | ||
} |
Oops, something went wrong.