-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check latest version from index instead of using harcoded value
- Loading branch information
Showing
2 changed files
with
73 additions
and
5 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,47 @@ | ||
package helper | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/redhat-developer/odo/pkg/api" | ||
) | ||
|
||
type Registry struct { | ||
url string | ||
} | ||
|
||
func NewRegistry(url string) Registry { | ||
return Registry{ | ||
url: url, | ||
} | ||
} | ||
|
||
func (o Registry) GetIndex() ([]api.DevfileStack, error) { | ||
resp, err := http.Get(o.url + "/v2index") | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer resp.Body.Close() | ||
|
||
var target []api.DevfileStack | ||
err = json.NewDecoder(resp.Body).Decode(&target) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return target, nil | ||
} | ||
|
||
func (o Registry) GetStack(name string) (api.DevfileStack, error) { | ||
index, err := o.GetIndex() | ||
if err != nil { | ||
return api.DevfileStack{}, err | ||
} | ||
for _, stack := range index { | ||
if stack.Name == name { | ||
return stack, nil | ||
} | ||
} | ||
return api.DevfileStack{}, fmt.Errorf("stack %q not found", name) | ||
} |
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