feat(client): IPCEICIS-5755 introduced api calls against edge conenct
Some checks failed
Go Tests / go-tests (push) Failing after 1m25s
Some checks failed
Go Tests / go-tests (push) Failing after 1m25s
This commit is contained in:
parent
b1928ad9e7
commit
0839b62b84
3 changed files with 201 additions and 149 deletions
|
|
@ -7,17 +7,27 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type EdgeConnect struct {
|
type EdgeConnect struct {
|
||||||
BaseURL string
|
BaseURL string
|
||||||
HttpClient *http.Client
|
HttpClient *http.Client
|
||||||
|
Credentials Credentials
|
||||||
|
}
|
||||||
|
|
||||||
|
type Credentials struct {
|
||||||
|
Username string
|
||||||
|
Password string
|
||||||
}
|
}
|
||||||
|
|
||||||
// curl -X POST https://mc.orca.platform.mg3.mdb.osc.live/api/v1/auth/ctrl/CreateAppInst -H 'Content-Type: application/json' -H "Authorization: Bearer $EDGEXR_TOKEN" -S --data "$CREATEAPPINSTANCE_JSON" --fail-with-body
|
// curl -X POST https://mc.orca.platform.mg3.mdb.osc.live/api/v1/auth/ctrl/CreateAppInst -H 'Content-Type: application/json' -H "Authorization: Bearer $EDGEXR_TOKEN" -S --data "$CREATEAPPINSTANCE_JSON" --fail-with-body
|
||||||
|
|
||||||
func (e *EdgeConnect) NewAppInstance(ctx context.Context, input NewAppInstanceInput) error {
|
func (e *EdgeConnect) NewAppInstance(ctx context.Context, input NewAppInstanceInput) error {
|
||||||
|
token, err := e.RetrieveToken(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
json_data, err := json.Marshal(input)
|
json_data, err := json.Marshal(input)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -28,7 +38,7 @@ func (e *EdgeConnect) NewAppInstance(ctx context.Context, input NewAppInstanceIn
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
request.Header.Set("Content-Type", "application/json")
|
request.Header.Set("Content-Type", "application/json")
|
||||||
request.Header.Set("Authorization", "Bearer "+os.Getenv("EDGEXR_TOKEN"))
|
request.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token))
|
||||||
|
|
||||||
resp, err := e.HttpClient.Do(request)
|
resp, err := e.HttpClient.Do(request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -47,8 +57,12 @@ func (e *EdgeConnect) NewAppInstance(ctx context.Context, input NewAppInstanceIn
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// curl -X POST https://mc.orca.platform.mg3.mdb.osc.live/api/v1/auth/ctrl/CreateApp -H 'Content-Type: application/json' -H "Authorization: Bearer $EDGEXR_TOKEN" -S --data "$CREATEAPP_JSON" --fail-with-body
|
|
||||||
func (e *EdgeConnect) NewApp(ctx context.Context, input NewAppInput) error {
|
func (e *EdgeConnect) NewApp(ctx context.Context, input NewAppInput) error {
|
||||||
|
token, err := e.RetrieveToken(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
json_data, err := json.Marshal(input)
|
json_data, err := json.Marshal(input)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -59,7 +73,7 @@ func (e *EdgeConnect) NewApp(ctx context.Context, input NewAppInput) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
request.Header.Set("Content-Type", "application/json")
|
request.Header.Set("Content-Type", "application/json")
|
||||||
request.Header.Set("Authorization", "Bearer "+os.Getenv("EDGEXR_TOKEN"))
|
request.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token))
|
||||||
|
|
||||||
resp, err := e.HttpClient.Do(request)
|
resp, err := e.HttpClient.Do(request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -78,59 +92,59 @@ func (e *EdgeConnect) NewApp(ctx context.Context, input NewAppInput) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type NewAppInstanceInput struct {
|
func (e *EdgeConnect) ShowApp(ctx context.Context, appkey AppKey, region string) (App, error) {
|
||||||
Region string `json:"region"`
|
token, err := e.RetrieveToken(ctx)
|
||||||
AppInst AppInstance `json:"appinst"`
|
if err != nil {
|
||||||
|
return App{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
type AppInstance struct {
|
input := struct {
|
||||||
Key AppInstanceKey `json:"key"`
|
App struct {
|
||||||
AppKey AppKey `json:"app_key"`
|
|
||||||
Flavor Flavor `json:"flavor"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type AppInstanceKey struct {
|
|
||||||
Organization string `json:"organization"`
|
|
||||||
Name string `json:"name"`
|
|
||||||
CloudletKey CloudletKey `json:"cloudlet_key"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type CloudletKey struct {
|
|
||||||
Organization string `json:"organization"`
|
|
||||||
Name string `json:"name"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type AppKey struct {
|
|
||||||
Organization string `json:"organization"`
|
|
||||||
Name string `json:"name"`
|
|
||||||
Version string `json:"version"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Flavor struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type NewAppInput struct {
|
|
||||||
Region string `json:"region"`
|
|
||||||
App App `json:"app"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type App struct {
|
|
||||||
Key AppKey `json:"key"`
|
Key AppKey `json:"key"`
|
||||||
Deployment string `json:"deployment"`
|
} `json:"App"`
|
||||||
ImageType string `json:"image_type"`
|
Region string `json:"Region"`
|
||||||
ImagePath string `json:"image_path"`
|
}{
|
||||||
AllowServerless bool `json:"allow_serverless"`
|
App: struct {
|
||||||
DefaultFlavor Flavor `json:"defaultFlavor"`
|
Key AppKey `json:"key"`
|
||||||
ServerlessConfig any `json:"serverless_config"`
|
}{
|
||||||
DeploymentGenerator string `json:"deployment_generator"`
|
Key: appkey,
|
||||||
DeploymentManifest string `json:"deployment_manifest"`
|
},
|
||||||
|
Region: region,
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *EdgeConnect) RetrieveToken(ctx context.Context, username, password string) (string, error) {
|
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()
|
||||||
|
var response struct {
|
||||||
|
Data App `json:"data"`
|
||||||
|
}
|
||||||
|
err = json.NewDecoder(resp.Body).Decode(&response)
|
||||||
|
if err != nil {
|
||||||
|
return App{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.Data, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *EdgeConnect) RetrieveToken(ctx context.Context) (string, error) {
|
||||||
json_data, err := json.Marshal(map[string]string{
|
json_data, err := json.Marshal(map[string]string{
|
||||||
"username": username,
|
"username": e.Credentials.Username,
|
||||||
"password": password,
|
"password": e.Credentials.Password,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
|
@ -149,81 +163,13 @@ func (e *EdgeConnect) RetrieveToken(ctx context.Context, username, password stri
|
||||||
|
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
fmt.Printf("Header: %v\n", request.Header)
|
|
||||||
bodyBytes, err := io.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
fmt.Printf("Response: %v\n", string(bodyBytes))
|
|
||||||
|
|
||||||
var respData struct {
|
var respData struct {
|
||||||
Token string `json:"token"`
|
Token string `json:"token"`
|
||||||
}
|
}
|
||||||
err = json.Unmarshal(bodyBytes, &respData)
|
err = json.NewDecoder(resp.Body).Decode(&respData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
return respData.Token, nil
|
return respData.Token, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// EDGEXR_TOKEN="$(curl -X POST https://mc.orca.platform.mg3.mdb.osc.live/api/v1/login -H 'Content-Type: application/json' --data '{"password": "'${EDGEXR_PLATFORM_PASSWORD}'","username": "'${EDGEXR_PLATFORM_USERNAME}'"}' -sSf | jq -r .token)"
|
|
||||||
|
|
||||||
// CREATEAPP_JSON=$(cat <<EOF
|
|
||||||
// {
|
|
||||||
// "region": "${APP_REGION}",
|
|
||||||
// "app": {
|
|
||||||
// "key": {
|
|
||||||
// "organization": "dev-framework",
|
|
||||||
// "name": "$(echo ${{ steps.repository.outputs.repository }} | sed -e 's|^.*/||')",
|
|
||||||
// "version": "${{ steps.docker.outputs.version }}"
|
|
||||||
// },
|
|
||||||
// "deployment": "kubernetes",
|
|
||||||
// "image_type": "Docker",
|
|
||||||
// "image_path": "${{ steps.repository.outputs.registry }}/${{ steps.repository.outputs.repository }}:${{ steps.docker.outputs.version }}",
|
|
||||||
// "allow_serverless": true,
|
|
||||||
// "defaultFlavor": {
|
|
||||||
// "name": "${APP_FLAVOR}"
|
|
||||||
// },
|
|
||||||
// "serverless_config": {},
|
|
||||||
// "deployment_generator": "kubernetes-basic",
|
|
||||||
// "deployment_manifest": "apiVersion: v1\nkind: Service\nmetadata:\n name: $(echo ${{ steps.repository.outputs.repository }} | sed -e 's|^.*/||')-tcp\n labels:\n run: $(echo ${{ steps.repository.outputs.repository }} | sed -e 's|^.*/||')\nspec:\n type: LoadBalancer\n ports:\n - name: tcp80\n protocol: TCP\n port: 80\n targetPort: 80\n selector:\n run: $(echo ${{ steps.repository.outputs.repository }} | sed -e 's|^.*/||')\n---\napiVersion: apps/v1\nkind: Deployment\nmetadata:\n name: $(echo ${{ steps.repository.outputs.repository }} | sed -e 's|^.*/||')-deployment\nspec:\n replicas: 1\n selector:\n matchLabels:\n run: $(echo ${{ steps.repository.outputs.repository }} | sed -e 's|^.*/||')\n template:\n metadata:\n labels:\n run: $(echo ${{ steps.repository.outputs.repository }} | sed -e 's|^.*/||')\n mexDeployGen: kubernetes-basic\n spec:\n volumes:\n containers:\n - name: $(echo ${{ steps.repository.outputs.repository }} | sed -e 's|^.*/||')\n image: ${{ steps.repository.outputs.registry }}/${{ steps.repository.outputs.repository }}:${{ steps.docker.outputs.version }}\n imagePullPolicy: Always\n ports:\n - containerPort: 80\n protocol: TCP\n\n"
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// EOF
|
|
||||||
// )
|
|
||||||
|
|
||||||
// echo $CREATEAPP_JSON
|
|
||||||
|
|
||||||
// echo create app
|
|
||||||
// curl -X POST https://mc.orca.platform.mg3.mdb.osc.live/api/v1/auth/ctrl/CreateApp -H 'Content-Type: application/json' -H "Authorization: Bearer $EDGEXR_TOKEN" -S --data "$CREATEAPP_JSON" --fail-with-body
|
|
||||||
|
|
||||||
// CREATEAPPINSTANCE_JSON=$(cat <<EOF
|
|
||||||
// {
|
|
||||||
// "region": "${APP_REGION}",
|
|
||||||
// "appinst": {
|
|
||||||
// "key": {
|
|
||||||
// "organization": "dev-framework",
|
|
||||||
// "name": "$(echo ${{ steps.repository.outputs.repository }} | sed -e 's|^.*/||')-instance",
|
|
||||||
// "cloudlet_key": {
|
|
||||||
// "organization": "TelekomOP",
|
|
||||||
// "name": "${CLOUDLET}"
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
// "app_key": {
|
|
||||||
// "organization": "dev-framework",
|
|
||||||
// "name": "$(echo ${{ steps.repository.outputs.repository }} | sed -e 's|^.*/||')",
|
|
||||||
// "version": "${{ steps.docker.outputs.version }}"
|
|
||||||
// },
|
|
||||||
// "flavor": {
|
|
||||||
// "name": "${APP_FLAVOR}"
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// EOF
|
|
||||||
// )
|
|
||||||
|
|
||||||
// echo $CREATEAPPINSTANCE_JSON
|
|
||||||
|
|
||||||
// echo create app instance
|
|
||||||
// curl -X POST https://mc.orca.platform.mg3.mdb.osc.live/api/v1/auth/ctrl/CreateAppInst -H 'Content-Type: application/json' -H "Authorization: Bearer $EDGEXR_TOKEN" -S --data "$CREATEAPPINSTANCE_JSON" --fail-with-body
|
|
||||||
|
|
|
||||||
50
internal/client/models.go
Normal file
50
internal/client/models.go
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
package client
|
||||||
|
|
||||||
|
type NewAppInstanceInput struct {
|
||||||
|
Region string `json:"region"`
|
||||||
|
AppInst AppInstance `json:"appinst"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type AppInstance struct {
|
||||||
|
Key AppInstanceKey `json:"key"`
|
||||||
|
AppKey AppKey `json:"app_key"`
|
||||||
|
Flavor Flavor `json:"flavor"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type AppInstanceKey struct {
|
||||||
|
Organization string `json:"organization"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
CloudletKey CloudletKey `json:"cloudlet_key"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type CloudletKey struct {
|
||||||
|
Organization string `json:"organization"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type AppKey struct {
|
||||||
|
Organization string `json:"organization"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Version string `json:"version"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Flavor struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type NewAppInput struct {
|
||||||
|
Region string `json:"region"`
|
||||||
|
App App `json:"app"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type App struct {
|
||||||
|
Key AppKey `json:"key"`
|
||||||
|
Deployment string `json:"deployment"`
|
||||||
|
ImageType string `json:"image_type"`
|
||||||
|
ImagePath string `json:"image_path"`
|
||||||
|
AllowServerless bool `json:"allow_serverless"`
|
||||||
|
DefaultFlavor Flavor `json:"defaultFlavor"`
|
||||||
|
ServerlessConfig any `json:"serverless_config"`
|
||||||
|
DeploymentGenerator string `json:"deployment_generator"`
|
||||||
|
DeploymentManifest string `json:"deployment_manifest"`
|
||||||
|
}
|
||||||
94
lala/lala.go
94
lala/lala.go
|
|
@ -9,34 +9,90 @@ import (
|
||||||
"edp.buildth.ing/DevFW-CICD/garm-provider-edge-connect/internal/client"
|
"edp.buildth.ing/DevFW-CICD/garm-provider-edge-connect/internal/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var testManifest = `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: mganter-test-tcp
|
||||||
|
labels:
|
||||||
|
run: mganter-test
|
||||||
|
spec:
|
||||||
|
type: LoadBalancer
|
||||||
|
ports:
|
||||||
|
- name: tcp80
|
||||||
|
protocol: TCP
|
||||||
|
port: 80
|
||||||
|
targetPort: 80
|
||||||
|
selector:
|
||||||
|
run: mganter-test
|
||||||
|
---
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: mganter-test-deployment
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
run: mganter-test
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
run: mganter-test
|
||||||
|
mexDeployGen: kubernetes-basic
|
||||||
|
spec:
|
||||||
|
volumes:
|
||||||
|
containers:
|
||||||
|
- name: mganter-test
|
||||||
|
image:
|
||||||
|
imagePullPolicy: Always
|
||||||
|
ports:
|
||||||
|
- containerPort: 80
|
||||||
|
protocol: TCP
|
||||||
|
`
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
ctx := context.TODO()
|
ctx := context.TODO()
|
||||||
e := client.EdgeConnect{
|
e := client.EdgeConnect{
|
||||||
BaseURL: "https://mc.orca.platform.mg3.mdb.osc.live",
|
BaseURL: "https://hub.apps.edge.platform.mg3.mdb.osc.live",
|
||||||
HttpClient: &http.Client{},
|
HttpClient: &http.Client{},
|
||||||
|
Credentials: client.Credentials{
|
||||||
|
Username: os.Getenv("EDGEXR_USERNAME"),
|
||||||
|
Password: os.Getenv("EDGEXR_PASSWORD"),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
token, err := e.RetrieveToken(ctx, os.Getenv("EDGEXR_USERNAME"), os.Getenv("EDGEXR_PASSWORD"))
|
|
||||||
|
app, err := e.ShowApp(ctx, client.AppKey{
|
||||||
|
Organization: "edp-developer-framework",
|
||||||
|
Name: "mganter-test",
|
||||||
|
Version: "0.0.1",
|
||||||
|
}, "EU")
|
||||||
|
fmt.Printf("Error: %v\n", err)
|
||||||
|
fmt.Printf("App: %v\n", app)
|
||||||
|
|
||||||
|
/*
|
||||||
|
token, err := e.RetrieveToken(ctx)
|
||||||
fmt.Printf("Token: %v\n", token)
|
fmt.Printf("Token: %v\n", token)
|
||||||
fmt.Printf("Error: %v\n", err)
|
fmt.Printf("Error: %v\n", err)
|
||||||
err = e.NewAppInstance(ctx, client.NewAppInstanceInput{
|
err = e.NewApp(ctx, client.NewAppInput{
|
||||||
Region: "us-west",
|
Region: "EU",
|
||||||
AppInst: client.AppInstance{
|
App: client.App{
|
||||||
Key: client.AppInstanceKey{
|
Key: client.AppKey{
|
||||||
Organization: "my-org",
|
Organization: "edp-developer-framework",
|
||||||
Name: "my-app-instance",
|
Name: "mganter-test",
|
||||||
CloudletKey: client.CloudletKey{
|
Version: "0.0.1",
|
||||||
Organization: "my-org",
|
|
||||||
Name: "my-cloudlet",
|
|
||||||
},
|
},
|
||||||
|
Deployment: "kubernetes",
|
||||||
|
ImageType: "Docker",
|
||||||
|
ImagePath: "",
|
||||||
|
AllowServerless: true,
|
||||||
|
ServerlessConfig: struct{}{},
|
||||||
|
DefaultFlavor: client.Flavor{
|
||||||
|
Name: "EU.small",
|
||||||
},
|
},
|
||||||
AppKey: client.AppKey{
|
DeploymentGenerator: "kubernetes-basic",
|
||||||
Organization: "my-org",
|
DeploymentManifest: testManifest,
|
||||||
Name: "my-app",
|
|
||||||
},
|
|
||||||
Flavor: client.Flavor{
|
|
||||||
Name: "default",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
fmt.Printf("Error: %v\n", err)
|
fmt.Printf("Error: %v\n", err)*/
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue