-
Notifications
You must be signed in to change notification settings - Fork 349
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): ensure pro providers are up to date before running devpod up
- Loading branch information
1 parent
5142bcf
commit bb2f25d
Showing
4 changed files
with
133 additions
and
33 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
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,51 @@ | ||
package loft | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"strings" | ||
|
||
"github.com/loft-sh/devpod/pkg/http" | ||
"github.com/loft-sh/devpod/pkg/provider" | ||
) | ||
|
||
type VersionObject struct { | ||
// Version is the remote devpod version | ||
DevPodVersion string `json:"devPodVersion,omitempty"` | ||
} | ||
|
||
func GetProInstanceDevPodVersion(proInstance *provider.ProInstance) (string, error) { | ||
url := "https://" + proInstance.Host | ||
return GetDevPodVersion(url) | ||
} | ||
|
||
func GetDevPodVersion(url string) (string, error) { | ||
resp, err := http.GetHTTPClient().Get(url + "/version") | ||
if err != nil { | ||
return "", fmt.Errorf("get %s: %w", url, err) | ||
} else if resp.StatusCode != 200 { | ||
out, _ := io.ReadAll(resp.Body) | ||
return "", fmt.Errorf("get %s: %s (Status: %d)", url, string(out), resp.StatusCode) | ||
} | ||
|
||
versionRaw, err := io.ReadAll(resp.Body) | ||
if err != nil { | ||
return "", fmt.Errorf("read %s: %w", url, err) | ||
} | ||
|
||
version := &VersionObject{} | ||
err = json.Unmarshal(versionRaw, version) | ||
if err != nil { | ||
return "", fmt.Errorf("parse %s: %w", url, err) | ||
} else if version.DevPodVersion == "" { | ||
return "", fmt.Errorf("unexpected version '%s', please use --version to define a provider version", version.DevPodVersion) | ||
} | ||
|
||
// make sure it starts with a v | ||
if !strings.HasPrefix(version.DevPodVersion, "v") { | ||
version.DevPodVersion = "v" + version.DevPodVersion | ||
} | ||
|
||
return version.DevPodVersion, nil | ||
} |
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