-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add helper methods for aws-session-manager plugin.
- Loading branch information
Showing
7 changed files
with
94 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package internal | ||
|
||
import ( | ||
"embed" | ||
"fmt" | ||
"runtime" | ||
"strings" | ||
) | ||
|
||
//go:embed assets/* | ||
var assets embed.FS | ||
|
||
// GetAsset returns asset file. | ||
// cannot be accessed from outer package. | ||
func GetAsset(filename string) ([]byte, error) { | ||
return assets.ReadFile("assets/" + filename) | ||
} | ||
|
||
// GetSsmPluginName returns filename for aws ssm plugin. | ||
func GetSsmPluginName() string { | ||
if strings.ToLower(runtime.GOOS) == "windows" { | ||
return "session-manager-plugin.exe" | ||
} else { | ||
return "session-manager-plugin" | ||
} | ||
} | ||
|
||
// GetSsmPlugin returns filepath for aws ssm plugin. | ||
func GetSsmPlugin() ([]byte, error) { | ||
return GetAsset(getSSMPluginKey()) | ||
} | ||
|
||
func getSSMPluginKey() string { | ||
return fmt.Sprintf("plugin/%s_%s/%s", | ||
strings.ToLower(runtime.GOOS), strings.ToLower(runtime.GOARCH), GetSsmPluginName()) | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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,58 @@ | ||
package internal | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGetAsset(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
tests := map[string]struct { | ||
input string | ||
isErr bool | ||
}{ | ||
"fail": {input: "fail", isErr: true}, | ||
"plugin/darwin_amd64/session-manager-plugin": {input: "plugin/darwin_amd64/session-manager-plugin", isErr: false}, | ||
"plugin/darwin_arm64/session-manager-plugin": {input: "plugin/darwin_arm64/session-manager-plugin", isErr: false}, | ||
"plugin/linux_amd64/session-manager-plugin": {input: "plugin/linux_amd64/session-manager-plugin", isErr: false}, | ||
"plugin/linux_arm64/session-manager-plugin": {input: "plugin/linux_arm64/session-manager-plugin", isErr: false}, | ||
"plugin/windows_amd64/session-manager-plugin.exe": {input: "plugin/windows_amd64/session-manager-plugin.exe", isErr: false}, | ||
} | ||
|
||
for _, t := range tests { | ||
_, err := GetAsset(t.input) | ||
assert.Equal(t.isErr, err != nil) | ||
} | ||
|
||
} | ||
|
||
func TestGetSsmPluginName(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
tests := map[string]struct { | ||
output string | ||
}{ | ||
"success": {output: "session-manager-plugin"}, | ||
} | ||
|
||
for _, t := range tests { | ||
assert.Equal(t.output, GetSsmPluginName()) | ||
} | ||
} | ||
|
||
func TestGetSsmPlugin(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
tests := map[string]struct { | ||
isErr bool | ||
}{ | ||
"success": {isErr: false}, | ||
} | ||
|
||
for _, t := range tests { | ||
_, err := GetSsmPlugin() | ||
assert.Equal(t.isErr, err != nil) | ||
} | ||
} |