Add GetTools() function
Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
This commit is contained in:
parent
91e2d7b029
commit
c6f29c8a47
1 changed files with 42 additions and 0 deletions
42
util/util.go
42
util/util.go
|
|
@ -250,6 +250,48 @@ func GetCloudConfig(bootstrapParams params.BootstrapInstance, tools github.Runne
|
|||
return asStr, nil
|
||||
}
|
||||
|
||||
func GetTools(osType params.OSType, osArch params.OSArch, tools []*github.RunnerApplicationDownload) (github.RunnerApplicationDownload, error) {
|
||||
// Validate image OS. Linux only for now.
|
||||
switch osType {
|
||||
case params.Linux:
|
||||
case params.Windows:
|
||||
default:
|
||||
return github.RunnerApplicationDownload{}, fmt.Errorf("unsupported OS type: %s", osType)
|
||||
}
|
||||
|
||||
switch osArch {
|
||||
case params.Amd64:
|
||||
case params.Arm:
|
||||
case params.Arm64:
|
||||
default:
|
||||
return github.RunnerApplicationDownload{}, fmt.Errorf("unsupported OS arch: %s", osArch)
|
||||
}
|
||||
|
||||
// Find tools for OS/Arch.
|
||||
for _, tool := range tools {
|
||||
if tool == nil {
|
||||
continue
|
||||
}
|
||||
if tool.OS == nil || tool.Architecture == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
ghArch, err := ResolveToGithubArch(string(osArch))
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
ghOS, err := ResolveToGithubOSType(string(osType))
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if *tool.Architecture == ghArch && *tool.OS == ghOS {
|
||||
return *tool, nil
|
||||
}
|
||||
}
|
||||
return github.RunnerApplicationDownload{}, fmt.Errorf("failed to find tools for OS %s and arch %s", osType, osArch)
|
||||
}
|
||||
|
||||
// GetRandomString returns a secure random string
|
||||
func GetRandomString(n int) (string, error) {
|
||||
data := make([]byte, n)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue