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"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
type EdgeConnect struct {
|
||||
BaseURL string
|
||||
HttpClient *http.Client
|
||||
BaseURL string
|
||||
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
|
||||
|
||||
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)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -28,7 +38,7 @@ func (e *EdgeConnect) NewAppInstance(ctx context.Context, input NewAppInstanceIn
|
|||
return err
|
||||
}
|
||||
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)
|
||||
if err != nil {
|
||||
|
|
@ -47,8 +57,12 @@ func (e *EdgeConnect) NewAppInstance(ctx context.Context, input NewAppInstanceIn
|
|||
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 {
|
||||
token, err := e.RetrieveToken(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
json_data, err := json.Marshal(input)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -59,7 +73,7 @@ func (e *EdgeConnect) NewApp(ctx context.Context, input NewAppInput) error {
|
|||
return err
|
||||
}
|
||||
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)
|
||||
if err != nil {
|
||||
|
|
@ -78,59 +92,59 @@ func (e *EdgeConnect) NewApp(ctx context.Context, input NewAppInput) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
type NewAppInstanceInput struct {
|
||||
Region string `json:"region"`
|
||||
AppInst AppInstance `json:"appinst"`
|
||||
func (e *EdgeConnect) ShowApp(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()
|
||||
var response struct {
|
||||
Data App `json:"data"`
|
||||
}
|
||||
err = json.NewDecoder(resp.Body).Decode(&response)
|
||||
if err != nil {
|
||||
return App{}, err
|
||||
}
|
||||
|
||||
return response.Data, nil
|
||||
}
|
||||
|
||||
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"`
|
||||
}
|
||||
|
||||
func (e *EdgeConnect) RetrieveToken(ctx context.Context, username, password string) (string, error) {
|
||||
func (e *EdgeConnect) RetrieveToken(ctx context.Context) (string, error) {
|
||||
json_data, err := json.Marshal(map[string]string{
|
||||
"username": username,
|
||||
"password": password,
|
||||
"username": e.Credentials.Username,
|
||||
"password": e.Credentials.Password,
|
||||
})
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
|
@ -149,81 +163,13 @@ func (e *EdgeConnect) RetrieveToken(ctx context.Context, username, password stri
|
|||
|
||||
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 {
|
||||
Token string `json:"token"`
|
||||
}
|
||||
err = json.Unmarshal(bodyBytes, &respData)
|
||||
err = json.NewDecoder(resp.Body).Decode(&respData)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
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"`
|
||||
}
|
||||
104
lala/lala.go
104
lala/lala.go
|
|
@ -9,34 +9,90 @@ import (
|
|||
"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() {
|
||||
ctx := context.TODO()
|
||||
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{},
|
||||
}
|
||||
token, err := e.RetrieveToken(ctx, os.Getenv("EDGEXR_USERNAME"), os.Getenv("EDGEXR_PASSWORD"))
|
||||
fmt.Printf("Token: %v\n", token)
|
||||
fmt.Printf("Error: %v\n", err)
|
||||
err = e.NewAppInstance(ctx, client.NewAppInstanceInput{
|
||||
Region: "us-west",
|
||||
AppInst: client.AppInstance{
|
||||
Key: client.AppInstanceKey{
|
||||
Organization: "my-org",
|
||||
Name: "my-app-instance",
|
||||
CloudletKey: client.CloudletKey{
|
||||
Organization: "my-org",
|
||||
Name: "my-cloudlet",
|
||||
},
|
||||
},
|
||||
AppKey: client.AppKey{
|
||||
Organization: "my-org",
|
||||
Name: "my-app",
|
||||
},
|
||||
Flavor: client.Flavor{
|
||||
Name: "default",
|
||||
},
|
||||
Credentials: client.Credentials{
|
||||
Username: os.Getenv("EDGEXR_USERNAME"),
|
||||
Password: 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("Error: %v\n", err)
|
||||
err = e.NewApp(ctx, client.NewAppInput{
|
||||
Region: "EU",
|
||||
App: client.App{
|
||||
Key: client.AppKey{
|
||||
Organization: "edp-developer-framework",
|
||||
Name: "mganter-test",
|
||||
Version: "0.0.1",
|
||||
},
|
||||
Deployment: "kubernetes",
|
||||
ImageType: "Docker",
|
||||
ImagePath: "",
|
||||
AllowServerless: true,
|
||||
ServerlessConfig: struct{}{},
|
||||
DefaultFlavor: client.Flavor{
|
||||
Name: "EU.small",
|
||||
},
|
||||
DeploymentGenerator: "kubernetes-basic",
|
||||
DeploymentManifest: testManifest,
|
||||
},
|
||||
})
|
||||
fmt.Printf("Error: %v\n", err)*/
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue