feat(client): implemented ShopApps
Some checks failed
Go Tests / go-tests (push) Failing after 1m28s
Some checks failed
Go Tests / go-tests (push) Failing after 1m28s
This commit is contained in:
parent
60ceddf649
commit
cf88522e57
4 changed files with 76 additions and 8 deletions
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -141,6 +142,64 @@ func (e *EdgeConnect) ShowApp(ctx context.Context, appkey AppKey, region string)
|
||||||
return response.Data, nil
|
return response.Data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (e *EdgeConnect) ShowApps(ctx context.Context, appkey AppKey, region string) ([]App, error) {
|
||||||
|
token, err := e.RetrieveToken(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return []App{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
input := struct {
|
||||||
|
App struct {
|
||||||
|
Key AppKey `json:"key"`
|
||||||
|
} `json:"App"`
|
||||||
|
Region string `json:"Region"`
|
||||||
|
}{
|
||||||
|
App: struct {
|
||||||
|
Key AppKey `json:"key"`
|
||||||
|
}{
|
||||||
|
Key: appkey,
|
||||||
|
},
|
||||||
|
Region: region,
|
||||||
|
}
|
||||||
|
|
||||||
|
json_data, err := json.Marshal(input)
|
||||||
|
if err != nil {
|
||||||
|
return []App{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
request, err := http.NewRequestWithContext(ctx, "POST", e.BaseURL+"/api/v1/auth/ctrl/ShowApp", bytes.NewBuffer(json_data))
|
||||||
|
if err != nil {
|
||||||
|
return []App{}, err
|
||||||
|
}
|
||||||
|
request.Header.Set("Content-Type", "application/json")
|
||||||
|
request.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token))
|
||||||
|
|
||||||
|
resp, err := e.HttpClient.Do(request)
|
||||||
|
if err != nil {
|
||||||
|
return []App{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
defer resp.Body.Close()
|
||||||
|
type response struct {
|
||||||
|
Data App `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
apps := []App{}
|
||||||
|
decoder := json.NewDecoder(resp.Body)
|
||||||
|
for {
|
||||||
|
var d response
|
||||||
|
if err := decoder.Decode(&d); err != nil {
|
||||||
|
if err.Error() == "EOF" {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
apps = append(apps, d.Data)
|
||||||
|
}
|
||||||
|
|
||||||
|
return apps, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (e *EdgeConnect) ShowAppInstance(ctx context.Context, appinstkey AppInstanceKey, region string) (AppInstance, error) {
|
func (e *EdgeConnect) ShowAppInstance(ctx context.Context, appinstkey AppInstanceKey, region string) (AppInstance, error) {
|
||||||
token, err := e.RetrieveToken(ctx)
|
token, err := e.RetrieveToken(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,8 @@ type CloudletKey struct {
|
||||||
|
|
||||||
type AppKey struct {
|
type AppKey struct {
|
||||||
Organization string `json:"organization"`
|
Organization string `json:"organization"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name,omitempty"`
|
||||||
Version string `json:"version"`
|
Version string `json:"version,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Flavor struct {
|
type Flavor struct {
|
||||||
|
|
|
||||||
20
lala/lala.go
20
lala/lala.go
|
|
@ -3,8 +3,10 @@ package main
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
|
||||||
"edp.buildth.ing/DevFW-CICD/garm-provider-edge-connect/provider"
|
"edp.buildth.ing/DevFW-CICD/garm-provider-edge-connect/internal/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
var testManifest = `
|
var testManifest = `
|
||||||
|
|
@ -51,14 +53,14 @@ spec:
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
ctx := context.TODO()
|
ctx := context.TODO()
|
||||||
/*e := client.EdgeConnect{
|
e := client.EdgeConnect{
|
||||||
BaseURL: "https://hub.apps.edge.platform.mg3.mdb.osc.live",
|
BaseURL: "https://hub.apps.edge.platform.mg3.mdb.osc.live",
|
||||||
HttpClient: &http.Client{},
|
HttpClient: &http.Client{},
|
||||||
Credentials: client.Credentials{
|
Credentials: client.Credentials{
|
||||||
Username: os.Getenv("EDGEXR_USERNAME"),
|
Username: os.Getenv("EDGEXR_USERNAME"),
|
||||||
Password: os.Getenv("EDGEXR_PASSWORD"),
|
Password: os.Getenv("EDGEXR_PASSWORD"),
|
||||||
},
|
},
|
||||||
}*/
|
}
|
||||||
|
|
||||||
/*e.DeleteAppInstance(ctx, client.AppInstanceKey{
|
/*e.DeleteAppInstance(ctx, client.AppInstanceKey{
|
||||||
Organization: "edp-developer-framework",
|
Organization: "edp-developer-framework",
|
||||||
|
|
@ -143,16 +145,22 @@ func main() {
|
||||||
fmt.Printf("appinst: %v\n", appinst)
|
fmt.Printf("appinst: %v\n", appinst)
|
||||||
fmt.Printf("Error: %v\n", err)*/
|
fmt.Printf("Error: %v\n", err)*/
|
||||||
|
|
||||||
edgeprovider, err := provider.NewEdgeConnectProvider("/home/chris/ipcei/projects/garm-provider-edge-connect/config/config.toml", "lalacontroller")
|
//edgeprovider, err := provider.NewEdgeConnectProvider("/home/chris/ipcei/projects/garm-provider-edge-connect/config/config.toml", "lalacontroller")
|
||||||
//providerinst, err := edgeprovider.GetInstance(ctx, appinst.Key.Name)
|
//providerinst, err := edgeprovider.GetInstance(ctx, appinst.Key.Name)
|
||||||
/*providerinst, err := edgeprovider.CreateInstance(ctx, params.BootstrapInstance{
|
/*providerinst, err := edgeprovider.CreateInstance(ctx, params.BootstrapInstance{
|
||||||
Name: "bootstrapparams",
|
Name: "bootstrapparams",
|
||||||
})*/
|
})*/
|
||||||
|
|
||||||
err = edgeprovider.DeleteInstance(ctx, "Bootstrapparams")
|
//err = edgeprovider.DeleteInstance(ctx, "Bootstrapparams")
|
||||||
|
result, _ := e.ShowApps(ctx, client.AppKey{
|
||||||
|
Organization: "edp-developer-framework",
|
||||||
|
}, "EU")
|
||||||
|
|
||||||
|
fmt.Printf("%v", result)
|
||||||
|
//ShowApps
|
||||||
|
|
||||||
//fmt.Printf("provider: %v\n", providerinst)
|
//fmt.Printf("provider: %v\n", providerinst)
|
||||||
fmt.Printf("Error: %v\n", err)
|
//fmt.Printf("Error: %v\n", err)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
token, err := e.RetrieveToken(ctx)
|
token, err := e.RetrieveToken(ctx)
|
||||||
|
|
|
||||||
|
|
@ -250,6 +250,7 @@ func (a *edgeConnectProvider) GetInstance(ctx context.Context, instance string)
|
||||||
|
|
||||||
// ListInstances will list all instances for a provider.
|
// ListInstances will list all instances for a provider.
|
||||||
func (a *edgeConnectProvider) ListInstances(ctx context.Context, poolID string) ([]params.ProviderInstance, error) {
|
func (a *edgeConnectProvider) ListInstances(ctx context.Context, poolID string) ([]params.ProviderInstance, error) {
|
||||||
|
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue