mirror of
https://git.rwth-aachen.de/acs/public/villas/web-backend-go/
synced 2025-03-30 00:00:12 +01:00
Parameter cleanup in IC model
This commit is contained in:
parent
33eab641cb
commit
1f0455d901
10 changed files with 327 additions and 225 deletions
|
@ -28,7 +28,6 @@ import (
|
|||
"github.com/gin-gonic/gin"
|
||||
"github.com/google/uuid"
|
||||
"github.com/jinzhu/gorm"
|
||||
"github.com/jinzhu/gorm/dialects/postgres"
|
||||
"github.com/streadway/amqp"
|
||||
"log"
|
||||
"time"
|
||||
|
@ -54,14 +53,16 @@ type Action struct {
|
|||
type ICUpdate struct {
|
||||
State *string `json:"state"`
|
||||
Properties struct {
|
||||
UUID string `json:"uuid"`
|
||||
Name *string `json:"name"`
|
||||
Category *string `json:"category"`
|
||||
Type *string `json:"type"`
|
||||
Location *string `json:"location"`
|
||||
WS_url *string `json:"ws_url"`
|
||||
API_url *string `json:"api_url"`
|
||||
UUID string `json:"uuid"`
|
||||
Name *string `json:"name"`
|
||||
Category *string `json:"category"`
|
||||
Type *string `json:"type"`
|
||||
Location *string `json:"location"`
|
||||
WS_url *string `json:"ws_url"`
|
||||
API_url *string `json:"api_url"`
|
||||
Description *string `json:"description"`
|
||||
} `json:"properties"`
|
||||
// TODO add JSON start parameter scheme
|
||||
}
|
||||
|
||||
var client AMQPclient
|
||||
|
@ -272,14 +273,18 @@ func processMessage(message amqp.Delivery) {
|
|||
newICReq.InfrastructureComponent.State = "unknown"
|
||||
}
|
||||
if payload.Properties.WS_url != nil {
|
||||
newICReq.InfrastructureComponent.Host = *payload.Properties.WS_url
|
||||
newICReq.InfrastructureComponent.WebsocketURL = *payload.Properties.WS_url
|
||||
}
|
||||
if payload.Properties.API_url != nil {
|
||||
newICReq.InfrastructureComponent.APIHost = *payload.Properties.API_url
|
||||
newICReq.InfrastructureComponent.APIURL = *payload.Properties.API_url
|
||||
}
|
||||
if payload.Properties.Location != nil {
|
||||
newICReq.InfrastructureComponent.Properties = postgres.Jsonb{json.RawMessage(`{"location" : " ` + *payload.Properties.Location + `"}`)}
|
||||
newICReq.InfrastructureComponent.Location = *payload.Properties.Location
|
||||
}
|
||||
if payload.Properties.Description != nil {
|
||||
newICReq.InfrastructureComponent.Description = *payload.Properties.Description
|
||||
}
|
||||
// TODO add JSON start parameter scheme
|
||||
|
||||
// Validate the new IC
|
||||
err = newICReq.Validate()
|
||||
|
@ -319,14 +324,19 @@ func processMessage(message amqp.Delivery) {
|
|||
updatedICReq.InfrastructureComponent.Name = *payload.Properties.Name
|
||||
}
|
||||
if payload.Properties.WS_url != nil {
|
||||
updatedICReq.InfrastructureComponent.Host = *payload.Properties.WS_url
|
||||
updatedICReq.InfrastructureComponent.WebsocketURL = *payload.Properties.WS_url
|
||||
}
|
||||
if payload.Properties.API_url != nil {
|
||||
updatedICReq.InfrastructureComponent.APIHost = *payload.Properties.API_url
|
||||
updatedICReq.InfrastructureComponent.APIURL = *payload.Properties.API_url
|
||||
}
|
||||
if payload.Properties.Location != nil {
|
||||
updatedICReq.InfrastructureComponent.Properties = postgres.Jsonb{json.RawMessage(`{"location" : " ` + *payload.Properties.Location + `"}`)}
|
||||
//postgres.Jsonb{json.RawMessage(`{"location" : " ` + *payload.Properties.Location + `"}`)}
|
||||
updatedICReq.InfrastructureComponent.Location = *payload.Properties.Location
|
||||
}
|
||||
if payload.Properties.Description != nil {
|
||||
updatedICReq.InfrastructureComponent.Description = *payload.Properties.Description
|
||||
}
|
||||
// TODO add JSON start parameter scheme
|
||||
|
||||
// Validate the updated IC
|
||||
if err = updatedICReq.Validate(); err != nil {
|
||||
|
|
|
@ -120,10 +120,10 @@ type InfrastructureComponent struct {
|
|||
UUID string `json:"uuid" gorm:"not null"`
|
||||
// Name of the IC
|
||||
Name string `json:"name" gorm:"default:''"`
|
||||
// Host if the IC
|
||||
Host string `json:"host" gorm:"default:''"`
|
||||
// Host of API for IC
|
||||
APIHost string `json:"apihost" gorm:"default:''"`
|
||||
// WebsocketURL if the IC
|
||||
WebsocketURL string `json:"websocketurl" gorm:"default:''"`
|
||||
// API URL of API for IC
|
||||
APIURL string `json:"apiurl" gorm:"default:''"`
|
||||
// Category of IC (simulator, gateway, database, etc.)
|
||||
Category string `json:"category" gorm:"default:''"`
|
||||
// Type of IC (RTDS, VILLASnode, RTDS, etc.)
|
||||
|
@ -134,10 +134,12 @@ type InfrastructureComponent struct {
|
|||
State string `json:"state" gorm:"default:''"`
|
||||
// Time of last state update
|
||||
StateUpdateAt string `json:"stateUpdateAt" gorm:"default:''"`
|
||||
// Location of the IC
|
||||
Location string `json:"location" gorm:"default:''"`
|
||||
// Description of the IC
|
||||
Description string `json:"description" gorm:"default:''"`
|
||||
// Properties of IC as JSON string
|
||||
Properties postgres.Jsonb `json:"properties"`
|
||||
// Raw properties of IC as JSON string
|
||||
RawProperties postgres.Jsonb `json:"rawProperties"`
|
||||
// ComponentConfigurations in which the IC is used
|
||||
ComponentConfigurations []ComponentConfiguration `json:"-" gorm:"foreignkey:ICID"`
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
|
||||
// This file was generated by swaggo/swag at
|
||||
// 2020-09-25 16:13:15.130920598 +0200 CEST m=+0.092357808
|
||||
// 2020-10-20 12:56:57.842992188 +0200 CEST m=+0.084567298
|
||||
|
||||
package docs
|
||||
|
||||
|
@ -1078,7 +1078,7 @@ var doc = `{
|
|||
"required": true,
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"$ref": "#/definitions/infrastructure_component.addICRequest"
|
||||
"$ref": "#/definitions/infrastructure_component.AddICRequest"
|
||||
}
|
||||
}
|
||||
],
|
||||
|
@ -1198,7 +1198,7 @@ var doc = `{
|
|||
"required": true,
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"$ref": "#/definitions/infrastructure_component.updateICRequest"
|
||||
"$ref": "#/definitions/infrastructure_component.UpdateICRequest"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -2977,21 +2977,25 @@ var doc = `{
|
|||
"database.InfrastructureComponent": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"apihost": {
|
||||
"description": "Host of API for IC",
|
||||
"apiurl": {
|
||||
"description": "API URL of API for IC",
|
||||
"type": "string"
|
||||
},
|
||||
"category": {
|
||||
"description": "Category of IC (simulator, gateway, database, etc.)",
|
||||
"type": "string"
|
||||
},
|
||||
"host": {
|
||||
"description": "Host if the IC",
|
||||
"description": {
|
||||
"description": "Description of the IC",
|
||||
"type": "string"
|
||||
},
|
||||
"id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"location": {
|
||||
"description": "Location of the IC",
|
||||
"type": "string"
|
||||
},
|
||||
"name": {
|
||||
"description": "Name of the IC",
|
||||
"type": "string"
|
||||
|
@ -3000,10 +3004,6 @@ var doc = `{
|
|||
"description": "Properties of IC as JSON string",
|
||||
"type": "string"
|
||||
},
|
||||
"rawProperties": {
|
||||
"description": "Raw properties of IC as JSON string",
|
||||
"type": "string"
|
||||
},
|
||||
"state": {
|
||||
"description": "State of the IC",
|
||||
"type": "string"
|
||||
|
@ -3023,6 +3023,10 @@ var doc = `{
|
|||
"uuid": {
|
||||
"description": "UUID of the IC",
|
||||
"type": "string"
|
||||
},
|
||||
"websocketurl": {
|
||||
"description": "WebsocketURL if the IC",
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -3351,7 +3355,7 @@ var doc = `{
|
|||
}
|
||||
}
|
||||
},
|
||||
"infrastructure_component.addICRequest": {
|
||||
"infrastructure_component.AddICRequest": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"ic": {
|
||||
|
@ -3360,7 +3364,7 @@ var doc = `{
|
|||
}
|
||||
}
|
||||
},
|
||||
"infrastructure_component.updateICRequest": {
|
||||
"infrastructure_component.UpdateICRequest": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"ic": {
|
||||
|
@ -3378,13 +3382,16 @@ var doc = `{
|
|||
"UUID"
|
||||
],
|
||||
"properties": {
|
||||
"APIHost": {
|
||||
"APIURL": {
|
||||
"type": "string"
|
||||
},
|
||||
"Category": {
|
||||
"type": "string"
|
||||
},
|
||||
"Host": {
|
||||
"Description": {
|
||||
"type": "string"
|
||||
},
|
||||
"Location": {
|
||||
"type": "string"
|
||||
},
|
||||
"Name": {
|
||||
|
@ -3401,19 +3408,25 @@ var doc = `{
|
|||
},
|
||||
"UUID": {
|
||||
"type": "string"
|
||||
},
|
||||
"WebsocketURL": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"infrastructure_component.validUpdatedIC": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"APIHost": {
|
||||
"APIURL": {
|
||||
"type": "string"
|
||||
},
|
||||
"Category": {
|
||||
"type": "string"
|
||||
},
|
||||
"Host": {
|
||||
"Description": {
|
||||
"type": "string"
|
||||
},
|
||||
"Location": {
|
||||
"type": "string"
|
||||
},
|
||||
"Name": {
|
||||
|
@ -3430,6 +3443,9 @@ var doc = `{
|
|||
},
|
||||
"UUID": {
|
||||
"type": "string"
|
||||
},
|
||||
"WebsocketURL": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -3765,7 +3781,7 @@ type swaggerInfo struct {
|
|||
var SwaggerInfo = swaggerInfo{
|
||||
Version: "2.0",
|
||||
Host: "",
|
||||
BasePath: "http://localhost:4000/api/v2/",
|
||||
BasePath: "/api/v2",
|
||||
Schemes: []string{},
|
||||
Title: "VILLASweb Backend API",
|
||||
Description: "This is the [VILLASweb Backend](https://git.rwth-aachen.de/acs/public/villas/web-backend-go) API v2.0.\nThis documentation is auto-generated based on the API documentation in the code. The tool [swag](https://github.com/swaggo/swag) is used to auto-generate API docs for the [gin-gonic](https://github.com/gin-gonic/gin) framework.\nAuthentication: Use the authenticate endpoint below to obtain a token for your user account, copy the token into to the value field of the dialog showing up for the green Authorize button below and confirm with Done.",
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
},
|
||||
"version": "2.0"
|
||||
},
|
||||
"basePath": "http://localhost:4000/api/v2/",
|
||||
"basePath": "/api/v2",
|
||||
"paths": {
|
||||
"/authenticate": {
|
||||
"post": {
|
||||
|
@ -1061,7 +1061,7 @@
|
|||
"required": true,
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"$ref": "#/definitions/infrastructure_component.addICRequest"
|
||||
"$ref": "#/definitions/infrastructure_component.AddICRequest"
|
||||
}
|
||||
}
|
||||
],
|
||||
|
@ -1181,7 +1181,7 @@
|
|||
"required": true,
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"$ref": "#/definitions/infrastructure_component.updateICRequest"
|
||||
"$ref": "#/definitions/infrastructure_component.UpdateICRequest"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -2960,21 +2960,25 @@
|
|||
"database.InfrastructureComponent": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"apihost": {
|
||||
"description": "Host of API for IC",
|
||||
"apiurl": {
|
||||
"description": "API URL of API for IC",
|
||||
"type": "string"
|
||||
},
|
||||
"category": {
|
||||
"description": "Category of IC (simulator, gateway, database, etc.)",
|
||||
"type": "string"
|
||||
},
|
||||
"host": {
|
||||
"description": "Host if the IC",
|
||||
"description": {
|
||||
"description": "Description of the IC",
|
||||
"type": "string"
|
||||
},
|
||||
"id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"location": {
|
||||
"description": "Location of the IC",
|
||||
"type": "string"
|
||||
},
|
||||
"name": {
|
||||
"description": "Name of the IC",
|
||||
"type": "string"
|
||||
|
@ -2983,10 +2987,6 @@
|
|||
"description": "Properties of IC as JSON string",
|
||||
"type": "string"
|
||||
},
|
||||
"rawProperties": {
|
||||
"description": "Raw properties of IC as JSON string",
|
||||
"type": "string"
|
||||
},
|
||||
"state": {
|
||||
"description": "State of the IC",
|
||||
"type": "string"
|
||||
|
@ -3006,6 +3006,10 @@
|
|||
"uuid": {
|
||||
"description": "UUID of the IC",
|
||||
"type": "string"
|
||||
},
|
||||
"websocketurl": {
|
||||
"description": "WebsocketURL if the IC",
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -3334,7 +3338,7 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"infrastructure_component.addICRequest": {
|
||||
"infrastructure_component.AddICRequest": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"ic": {
|
||||
|
@ -3343,7 +3347,7 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"infrastructure_component.updateICRequest": {
|
||||
"infrastructure_component.UpdateICRequest": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"ic": {
|
||||
|
@ -3361,13 +3365,16 @@
|
|||
"UUID"
|
||||
],
|
||||
"properties": {
|
||||
"APIHost": {
|
||||
"APIURL": {
|
||||
"type": "string"
|
||||
},
|
||||
"Category": {
|
||||
"type": "string"
|
||||
},
|
||||
"Host": {
|
||||
"Description": {
|
||||
"type": "string"
|
||||
},
|
||||
"Location": {
|
||||
"type": "string"
|
||||
},
|
||||
"Name": {
|
||||
|
@ -3384,19 +3391,25 @@
|
|||
},
|
||||
"UUID": {
|
||||
"type": "string"
|
||||
},
|
||||
"WebsocketURL": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"infrastructure_component.validUpdatedIC": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"APIHost": {
|
||||
"APIURL": {
|
||||
"type": "string"
|
||||
},
|
||||
"Category": {
|
||||
"type": "string"
|
||||
},
|
||||
"Host": {
|
||||
"Description": {
|
||||
"type": "string"
|
||||
},
|
||||
"Location": {
|
||||
"type": "string"
|
||||
},
|
||||
"Name": {
|
||||
|
@ -3413,6 +3426,9 @@
|
|||
},
|
||||
"UUID": {
|
||||
"type": "string"
|
||||
},
|
||||
"WebsocketURL": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
basePath: http://localhost:4000/api/v2/
|
||||
basePath: /api/v2
|
||||
definitions:
|
||||
component_configuration.addConfigRequest:
|
||||
properties:
|
||||
|
@ -146,26 +146,26 @@ definitions:
|
|||
type: object
|
||||
database.InfrastructureComponent:
|
||||
properties:
|
||||
apihost:
|
||||
description: Host of API for IC
|
||||
apiurl:
|
||||
description: API URL of API for IC
|
||||
type: string
|
||||
category:
|
||||
description: Category of IC (simulator, gateway, database, etc.)
|
||||
type: string
|
||||
host:
|
||||
description: Host if the IC
|
||||
description:
|
||||
description: Description of the IC
|
||||
type: string
|
||||
id:
|
||||
type: integer
|
||||
location:
|
||||
description: Location of the IC
|
||||
type: string
|
||||
name:
|
||||
description: Name of the IC
|
||||
type: string
|
||||
properties:
|
||||
description: Properties of IC as JSON string
|
||||
type: string
|
||||
rawProperties:
|
||||
description: Raw properties of IC as JSON string
|
||||
type: string
|
||||
state:
|
||||
description: State of the IC
|
||||
type: string
|
||||
|
@ -181,6 +181,9 @@ definitions:
|
|||
uuid:
|
||||
description: UUID of the IC
|
||||
type: string
|
||||
websocketurl:
|
||||
description: WebsocketURL if the IC
|
||||
type: string
|
||||
type: object
|
||||
database.Scenario:
|
||||
properties:
|
||||
|
@ -404,13 +407,13 @@ definitions:
|
|||
$ref: '#/definitions/database.Widget'
|
||||
type: array
|
||||
type: object
|
||||
infrastructure_component.addICRequest:
|
||||
infrastructure_component.AddICRequest:
|
||||
properties:
|
||||
ic:
|
||||
$ref: '#/definitions/infrastructure_component.validNewIC'
|
||||
type: object
|
||||
type: object
|
||||
infrastructure_component.updateICRequest:
|
||||
infrastructure_component.UpdateICRequest:
|
||||
properties:
|
||||
ic:
|
||||
$ref: '#/definitions/infrastructure_component.validUpdatedIC'
|
||||
|
@ -418,11 +421,13 @@ definitions:
|
|||
type: object
|
||||
infrastructure_component.validNewIC:
|
||||
properties:
|
||||
APIHost:
|
||||
APIURL:
|
||||
type: string
|
||||
Category:
|
||||
type: string
|
||||
Host:
|
||||
Description:
|
||||
type: string
|
||||
Location:
|
||||
type: string
|
||||
Name:
|
||||
type: string
|
||||
|
@ -434,6 +439,8 @@ definitions:
|
|||
type: string
|
||||
UUID:
|
||||
type: string
|
||||
WebsocketURL:
|
||||
type: string
|
||||
required:
|
||||
- Category
|
||||
- Name
|
||||
|
@ -442,11 +449,13 @@ definitions:
|
|||
type: object
|
||||
infrastructure_component.validUpdatedIC:
|
||||
properties:
|
||||
APIHost:
|
||||
APIURL:
|
||||
type: string
|
||||
Category:
|
||||
type: string
|
||||
Host:
|
||||
Description:
|
||||
type: string
|
||||
Location:
|
||||
type: string
|
||||
Name:
|
||||
type: string
|
||||
|
@ -458,6 +467,8 @@ definitions:
|
|||
type: string
|
||||
UUID:
|
||||
type: string
|
||||
WebsocketURL:
|
||||
type: string
|
||||
type: object
|
||||
scenario.addScenarioRequest:
|
||||
properties:
|
||||
|
@ -1357,7 +1368,7 @@ paths:
|
|||
name: inputIC
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/infrastructure_component.addICRequest'
|
||||
$ref: '#/definitions/infrastructure_component.AddICRequest'
|
||||
type: object
|
||||
produces:
|
||||
- application/json
|
||||
|
@ -1470,7 +1481,7 @@ paths:
|
|||
name: inputIC
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/infrastructure_component.updateICRequest'
|
||||
$ref: '#/definitions/infrastructure_component.UpdateICRequest'
|
||||
type: object
|
||||
- description: InfrastructureComponent ID
|
||||
in: path
|
||||
|
|
|
@ -88,34 +88,36 @@ var NewUserC = UserRequest{
|
|||
|
||||
// Infrastructure components
|
||||
|
||||
var propertiesA = json.RawMessage(`{"location" : "ACSlab"}`)
|
||||
var propertiesB = json.RawMessage(`{"location" : "ACSlab"}`)
|
||||
var propertiesA = json.RawMessage(`{"prop1" : "a nice prop"}`)
|
||||
var propertiesB = json.RawMessage(`{"prop1" : "not so nice"}`)
|
||||
|
||||
var ICA = database.InfrastructureComponent{
|
||||
UUID: "4854af30-325f-44a5-ad59-b67b2597de68",
|
||||
Host: "xxx.yyy.zzz.aaa",
|
||||
Type: "DPsim",
|
||||
Category: "Simulator",
|
||||
Name: "Test DPsim Simulator",
|
||||
Uptime: 0,
|
||||
State: "running",
|
||||
StateUpdateAt: time.Now().Format(time.RFC1123),
|
||||
Properties: postgres.Jsonb{propertiesA},
|
||||
RawProperties: postgres.Jsonb{propertiesA},
|
||||
UUID: "4854af30-325f-44a5-ad59-b67b2597de68",
|
||||
WebsocketURL: "xxx.yyy.zzz.aaa",
|
||||
Type: "DPsim",
|
||||
Category: "Simulator",
|
||||
Name: "Test DPsim Simulator",
|
||||
Uptime: 0,
|
||||
State: "running",
|
||||
Location: "ACS Laboratory",
|
||||
Description: "This is a test description",
|
||||
//StateUpdateAt: time.Now().Format(time.RFC1123),
|
||||
Properties: postgres.Jsonb{propertiesA},
|
||||
}
|
||||
|
||||
var ICB = database.InfrastructureComponent{
|
||||
UUID: "7be0322d-354e-431e-84bd-ae4c9633138b",
|
||||
Host: "https://villas-new.k8s.eonerc.rwth-aachen.de/ws/ws_sig",
|
||||
APIHost: "https://villas-new.k8s.eonerc.rwth-aachen.de/ws/api",
|
||||
Type: "VILLASnode Signal Generator",
|
||||
Category: "Signal Generator",
|
||||
Name: "ACS Demo Signals",
|
||||
Uptime: 0,
|
||||
State: "idle",
|
||||
StateUpdateAt: time.Now().Format(time.RFC1123),
|
||||
Properties: postgres.Jsonb{propertiesB},
|
||||
RawProperties: postgres.Jsonb{propertiesB},
|
||||
UUID: "7be0322d-354e-431e-84bd-ae4c9633138b",
|
||||
WebsocketURL: "https://villas-new.k8s.eonerc.rwth-aachen.de/ws/ws_sig",
|
||||
APIURL: "https://villas-new.k8s.eonerc.rwth-aachen.de/ws/api",
|
||||
Type: "VILLASnode Signal Generator",
|
||||
Category: "Signal Generator",
|
||||
Name: "ACS Demo Signals",
|
||||
Uptime: 0,
|
||||
State: "idle",
|
||||
Location: "k8s",
|
||||
Description: "A signal generator for testing purposes",
|
||||
//StateUpdateAt: time.Now().Format(time.RFC1123),
|
||||
Properties: postgres.Jsonb{propertiesB},
|
||||
}
|
||||
|
||||
// Scenarios
|
||||
|
|
|
@ -49,13 +49,15 @@ type ConfigRequest struct {
|
|||
}
|
||||
|
||||
type ICRequest struct {
|
||||
UUID string `json:"uuid,omitempty"`
|
||||
Host string `json:"host,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Category string `json:"category,omitempty"`
|
||||
State string `json:"state,omitempty"`
|
||||
Properties postgres.Jsonb `json:"properties,omitempty"`
|
||||
UUID string `json:"uuid,omitempty"`
|
||||
WebsocketURL string `json:"websocketurl,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Category string `json:"category,omitempty"`
|
||||
State string `json:"state,omitempty"`
|
||||
Location string `json:"location,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Properties postgres.Jsonb `json:"properties,omitempty"`
|
||||
}
|
||||
|
||||
type ScenarioRequest struct {
|
||||
|
@ -72,13 +74,15 @@ func addScenarioAndIC() (scenarioID uint, ICID uint) {
|
|||
|
||||
// POST $newICA
|
||||
newICA := ICRequest{
|
||||
UUID: helper.ICA.UUID,
|
||||
Host: helper.ICA.Host,
|
||||
Type: helper.ICA.Type,
|
||||
Name: helper.ICA.Name,
|
||||
Category: helper.ICA.Category,
|
||||
State: helper.ICA.State,
|
||||
Properties: helper.ICA.Properties,
|
||||
UUID: helper.ICA.UUID,
|
||||
WebsocketURL: helper.ICA.WebsocketURL,
|
||||
Type: helper.ICA.Type,
|
||||
Name: helper.ICA.Name,
|
||||
Category: helper.ICA.Category,
|
||||
State: helper.ICA.State,
|
||||
Location: helper.ICA.Location,
|
||||
Description: helper.ICA.Description,
|
||||
Properties: helper.ICA.Properties,
|
||||
}
|
||||
_, resp, _ := helper.TestEndpoint(router, token,
|
||||
"/api/ic", "POST", helper.KeyModels{"ic": newICA})
|
||||
|
@ -88,13 +92,15 @@ func addScenarioAndIC() (scenarioID uint, ICID uint) {
|
|||
|
||||
// POST a second IC to change to that IC during testing
|
||||
newICB := ICRequest{
|
||||
UUID: helper.ICB.UUID,
|
||||
Host: helper.ICB.Host,
|
||||
Type: helper.ICB.Type,
|
||||
Name: helper.ICB.Name,
|
||||
Category: helper.ICB.Category,
|
||||
State: helper.ICB.State,
|
||||
Properties: helper.ICB.Properties,
|
||||
UUID: helper.ICB.UUID,
|
||||
WebsocketURL: helper.ICB.WebsocketURL,
|
||||
Type: helper.ICB.Type,
|
||||
Name: helper.ICB.Name,
|
||||
Category: helper.ICB.Category,
|
||||
State: helper.ICB.State,
|
||||
Location: helper.ICB.Location,
|
||||
Description: helper.ICB.Description,
|
||||
Properties: helper.ICB.Properties,
|
||||
}
|
||||
_, resp, _ = helper.TestEndpoint(router, token,
|
||||
"/api/ic", "POST", helper.KeyModels{"ic": newICB})
|
||||
|
|
|
@ -39,14 +39,16 @@ import (
|
|||
var router *gin.Engine
|
||||
|
||||
type ICRequest struct {
|
||||
UUID string `json:"uuid,omitempty"`
|
||||
Host string `json:"host,omitempty"`
|
||||
APIHost string `json:"apihost,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Category string `json:"category,omitempty"`
|
||||
State string `json:"state,omitempty"`
|
||||
Properties postgres.Jsonb `json:"properties,omitempty"`
|
||||
UUID string `json:"uuid,omitempty"`
|
||||
WebsocketURL string `json:"websocketurl,omitempty"`
|
||||
APIURL string `json:"apiurl,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Category string `json:"category,omitempty"`
|
||||
State string `json:"state,omitempty"`
|
||||
Location string `json:"location,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Properties postgres.Jsonb `json:"properties,omitempty"`
|
||||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
|
@ -100,13 +102,16 @@ func TestAddICAsAdmin(t *testing.T) {
|
|||
|
||||
// test POST ic/ $newIC
|
||||
newIC := ICRequest{
|
||||
UUID: helper.ICA.UUID,
|
||||
Host: helper.ICA.Host,
|
||||
Type: helper.ICA.Type,
|
||||
Name: helper.ICA.Name,
|
||||
Category: helper.ICA.Category,
|
||||
State: helper.ICA.State,
|
||||
Properties: helper.ICA.Properties,
|
||||
UUID: helper.ICA.UUID,
|
||||
WebsocketURL: helper.ICA.WebsocketURL,
|
||||
APIURL: helper.ICB.APIURL,
|
||||
Type: helper.ICA.Type,
|
||||
Name: helper.ICA.Name,
|
||||
Category: helper.ICA.Category,
|
||||
State: helper.ICA.State,
|
||||
Location: helper.ICA.Location,
|
||||
Description: helper.ICA.Description,
|
||||
Properties: helper.ICA.Properties,
|
||||
}
|
||||
code, resp, err = helper.TestEndpoint(router, token,
|
||||
"/api/ic", "POST", helper.KeyModels{"ic": newIC})
|
||||
|
@ -152,13 +157,15 @@ func TestAddICAsUser(t *testing.T) {
|
|||
|
||||
// test POST ic/ $newIC
|
||||
newIC := ICRequest{
|
||||
UUID: helper.ICA.UUID,
|
||||
Host: helper.ICA.Host,
|
||||
Type: helper.ICA.Type,
|
||||
Name: helper.ICA.Name,
|
||||
Category: helper.ICA.Category,
|
||||
State: helper.ICA.State,
|
||||
Properties: helper.ICA.Properties,
|
||||
UUID: helper.ICA.UUID,
|
||||
WebsocketURL: helper.ICA.WebsocketURL,
|
||||
Type: helper.ICA.Type,
|
||||
Name: helper.ICA.Name,
|
||||
Category: helper.ICA.Category,
|
||||
State: helper.ICA.State,
|
||||
Location: helper.ICA.Location,
|
||||
Description: helper.ICA.Description,
|
||||
Properties: helper.ICA.Properties,
|
||||
}
|
||||
|
||||
// This should fail with unprocessable entity 422 error code
|
||||
|
@ -181,13 +188,15 @@ func TestUpdateICAsAdmin(t *testing.T) {
|
|||
|
||||
// test POST ic/ $newIC
|
||||
newIC := ICRequest{
|
||||
UUID: helper.ICA.UUID,
|
||||
Host: helper.ICA.Host,
|
||||
Type: helper.ICA.Type,
|
||||
Name: helper.ICA.Name,
|
||||
Category: helper.ICA.Category,
|
||||
State: helper.ICA.State,
|
||||
Properties: helper.ICA.Properties,
|
||||
UUID: helper.ICA.UUID,
|
||||
WebsocketURL: helper.ICA.WebsocketURL,
|
||||
Type: helper.ICA.Type,
|
||||
Name: helper.ICA.Name,
|
||||
Category: helper.ICA.Category,
|
||||
State: helper.ICA.State,
|
||||
Location: helper.ICA.Location,
|
||||
Description: helper.ICA.Description,
|
||||
Properties: helper.ICA.Properties,
|
||||
}
|
||||
code, resp, err := helper.TestEndpoint(router, token,
|
||||
"/api/ic", "POST", helper.KeyModels{"ic": newIC})
|
||||
|
@ -210,7 +219,7 @@ func TestUpdateICAsAdmin(t *testing.T) {
|
|||
assert.Equalf(t, 400, code, "Response body: \n%v\n", resp)
|
||||
|
||||
// Test PUT IC
|
||||
newIC.Host = "ThisIsMyNewHost"
|
||||
newIC.WebsocketURL = "ThisIsMyNewURL"
|
||||
code, resp, err = helper.TestEndpoint(router, token,
|
||||
fmt.Sprintf("/api/ic/%v", newICID), "PUT", helper.KeyModels{"ic": newIC})
|
||||
assert.NoError(t, err)
|
||||
|
@ -245,13 +254,15 @@ func TestUpdateICAsUser(t *testing.T) {
|
|||
|
||||
// test POST ic/ $newIC
|
||||
newIC := ICRequest{
|
||||
UUID: helper.ICA.UUID,
|
||||
Host: helper.ICA.Host,
|
||||
Type: helper.ICA.Type,
|
||||
Name: helper.ICA.Name,
|
||||
Category: helper.ICA.Category,
|
||||
State: helper.ICA.State,
|
||||
Properties: helper.ICA.Properties,
|
||||
UUID: helper.ICA.UUID,
|
||||
WebsocketURL: helper.ICA.WebsocketURL,
|
||||
Type: helper.ICA.Type,
|
||||
Name: helper.ICA.Name,
|
||||
Category: helper.ICA.Category,
|
||||
State: helper.ICA.State,
|
||||
Location: helper.ICA.Location,
|
||||
Description: helper.ICA.Description,
|
||||
Properties: helper.ICA.Properties,
|
||||
}
|
||||
code, resp, err := helper.TestEndpoint(router, token,
|
||||
"/api/ic", "POST", helper.KeyModels{"ic": newIC})
|
||||
|
@ -269,7 +280,7 @@ func TestUpdateICAsUser(t *testing.T) {
|
|||
|
||||
// Test PUT IC
|
||||
// This should fail with unprocessable entity status code 422
|
||||
newIC.Host = "ThisIsMyNewHost"
|
||||
newIC.WebsocketURL = "ThisIsMyNewURL"
|
||||
code, resp, err = helper.TestEndpoint(router, token,
|
||||
fmt.Sprintf("/api/ic/%v", newICID), "PUT", helper.KeyModels{"ic": newIC})
|
||||
assert.NoError(t, err)
|
||||
|
@ -289,13 +300,15 @@ func TestDeleteICAsAdmin(t *testing.T) {
|
|||
|
||||
// test POST ic/ $newIC
|
||||
newIC := ICRequest{
|
||||
UUID: helper.ICA.UUID,
|
||||
Host: helper.ICA.Host,
|
||||
Type: helper.ICA.Type,
|
||||
Name: helper.ICA.Name,
|
||||
Category: helper.ICA.Category,
|
||||
State: helper.ICA.State,
|
||||
Properties: helper.ICA.Properties,
|
||||
UUID: helper.ICA.UUID,
|
||||
WebsocketURL: helper.ICA.WebsocketURL,
|
||||
Type: helper.ICA.Type,
|
||||
Name: helper.ICA.Name,
|
||||
Category: helper.ICA.Category,
|
||||
State: helper.ICA.State,
|
||||
Location: helper.ICA.Location,
|
||||
Description: helper.ICA.Description,
|
||||
Properties: helper.ICA.Properties,
|
||||
}
|
||||
code, resp, err := helper.TestEndpoint(router, token,
|
||||
"/api/ic", "POST", helper.KeyModels{"ic": newIC})
|
||||
|
@ -341,13 +354,15 @@ func TestDeleteICAsUser(t *testing.T) {
|
|||
|
||||
// test POST ic/ $newIC
|
||||
newIC := ICRequest{
|
||||
UUID: helper.ICA.UUID,
|
||||
Host: helper.ICA.Host,
|
||||
Type: helper.ICA.Type,
|
||||
Name: helper.ICA.Name,
|
||||
Category: helper.ICA.Category,
|
||||
State: helper.ICA.State,
|
||||
Properties: helper.ICA.Properties,
|
||||
UUID: helper.ICA.UUID,
|
||||
WebsocketURL: helper.ICA.WebsocketURL,
|
||||
Type: helper.ICA.Type,
|
||||
Name: helper.ICA.Name,
|
||||
Category: helper.ICA.Category,
|
||||
State: helper.ICA.State,
|
||||
Location: helper.ICA.Location,
|
||||
Description: helper.ICA.Description,
|
||||
Properties: helper.ICA.Properties,
|
||||
}
|
||||
code, resp, err := helper.TestEndpoint(router, token,
|
||||
"/api/ic", "POST", helper.KeyModels{"ic": newIC})
|
||||
|
@ -365,7 +380,7 @@ func TestDeleteICAsUser(t *testing.T) {
|
|||
|
||||
// Test DELETE ICs
|
||||
// This should fail with unprocessable entity status code 422
|
||||
newIC.Host = "ThisIsMyNewHost"
|
||||
newIC.WebsocketURL = "ThisIsMyNewURL"
|
||||
code, resp, err = helper.TestEndpoint(router, token,
|
||||
fmt.Sprintf("/api/ic/%v", newICID), "DELETE", nil)
|
||||
assert.NoError(t, err)
|
||||
|
@ -389,13 +404,15 @@ func TestGetAllICs(t *testing.T) {
|
|||
|
||||
// test POST ic/ $newICA
|
||||
newICA := ICRequest{
|
||||
UUID: helper.ICA.UUID,
|
||||
Host: helper.ICA.Host,
|
||||
Type: helper.ICA.Type,
|
||||
Name: helper.ICA.Name,
|
||||
Category: helper.ICA.Category,
|
||||
State: helper.ICA.State,
|
||||
Properties: helper.ICA.Properties,
|
||||
UUID: helper.ICA.UUID,
|
||||
WebsocketURL: helper.ICA.WebsocketURL,
|
||||
Type: helper.ICA.Type,
|
||||
Name: helper.ICA.Name,
|
||||
Category: helper.ICA.Category,
|
||||
State: helper.ICA.State,
|
||||
Location: helper.ICA.Location,
|
||||
Description: helper.ICA.Description,
|
||||
Properties: helper.ICA.Properties,
|
||||
}
|
||||
code, resp, err := helper.TestEndpoint(router, token,
|
||||
"/api/ic", "POST", helper.KeyModels{"ic": newICA})
|
||||
|
@ -404,13 +421,15 @@ func TestGetAllICs(t *testing.T) {
|
|||
|
||||
// test POST ic/ $newICB
|
||||
newICB := ICRequest{
|
||||
UUID: helper.ICB.UUID,
|
||||
Host: helper.ICB.Host,
|
||||
Type: helper.ICB.Type,
|
||||
Name: helper.ICB.Name,
|
||||
Category: helper.ICB.Category,
|
||||
State: helper.ICB.State,
|
||||
Properties: helper.ICB.Properties,
|
||||
UUID: helper.ICB.UUID,
|
||||
WebsocketURL: helper.ICB.WebsocketURL,
|
||||
Type: helper.ICB.Type,
|
||||
Name: helper.ICB.Name,
|
||||
Category: helper.ICB.Category,
|
||||
State: helper.ICB.State,
|
||||
Location: helper.ICB.Location,
|
||||
Description: helper.ICB.Description,
|
||||
Properties: helper.ICB.Properties,
|
||||
}
|
||||
code, resp, err = helper.TestEndpoint(router, token,
|
||||
"/api/ic", "POST", helper.KeyModels{"ic": newICB})
|
||||
|
@ -449,13 +468,15 @@ func TestGetConfigsOfIC(t *testing.T) {
|
|||
|
||||
// test POST ic/ $newICA
|
||||
newICA := ICRequest{
|
||||
UUID: helper.ICA.UUID,
|
||||
Host: helper.ICA.Host,
|
||||
Type: helper.ICA.Type,
|
||||
Name: helper.ICA.Name,
|
||||
Category: helper.ICA.Category,
|
||||
State: helper.ICA.State,
|
||||
Properties: helper.ICA.Properties,
|
||||
UUID: helper.ICA.UUID,
|
||||
WebsocketURL: helper.ICA.WebsocketURL,
|
||||
Type: helper.ICA.Type,
|
||||
Name: helper.ICA.Name,
|
||||
Category: helper.ICA.Category,
|
||||
State: helper.ICA.State,
|
||||
Location: helper.ICA.Location,
|
||||
Description: helper.ICA.Description,
|
||||
Properties: helper.ICA.Properties,
|
||||
}
|
||||
code, resp, err := helper.TestEndpoint(router, token,
|
||||
"/api/ic", "POST", helper.KeyModels{"ic": newICA})
|
||||
|
|
|
@ -32,25 +32,29 @@ import (
|
|||
var validate *validator.Validate
|
||||
|
||||
type validNewIC struct {
|
||||
UUID string `form:"UUID" validate:"required"`
|
||||
Host string `form:"Host" validate:"omitempty"`
|
||||
APIHost string `form:"APIHost" validate:"omitempty"`
|
||||
Type string `form:"Type" validate:"required"`
|
||||
Name string `form:"Name" validate:"required"`
|
||||
Category string `form:"Category" validate:"required"`
|
||||
Properties postgres.Jsonb `form:"Properties" validate:"omitempty"`
|
||||
State string `form:"State" validate:"omitempty"`
|
||||
UUID string `form:"UUID" validate:"required"`
|
||||
WebsocketURL string `form:"WebsocketURL" validate:"omitempty"`
|
||||
APIURL string `form:"APIURL" validate:"omitempty"`
|
||||
Type string `form:"Type" validate:"required"`
|
||||
Name string `form:"Name" validate:"required"`
|
||||
Category string `form:"Category" validate:"required"`
|
||||
Properties postgres.Jsonb `form:"Properties" validate:"omitempty"`
|
||||
State string `form:"State" validate:"omitempty"`
|
||||
Location string `form:"Location" validate:"omitempty"`
|
||||
Description string `form:"Description" validate:"omitempty"`
|
||||
}
|
||||
|
||||
type validUpdatedIC struct {
|
||||
UUID string `form:"UUID" validate:"omitempty"`
|
||||
Host string `form:"Host" validate:"omitempty"`
|
||||
APIHost string `form:"APIHost" validate:"omitempty"`
|
||||
Type string `form:"Type" validate:"omitempty"`
|
||||
Name string `form:"Name" validate:"omitempty"`
|
||||
Category string `form:"Category" validate:"omitempty"`
|
||||
Properties postgres.Jsonb `form:"Properties" validate:"omitempty"`
|
||||
State string `form:"State" validate:"omitempty"`
|
||||
UUID string `form:"UUID" validate:"omitempty"`
|
||||
WebsocketURL string `form:"WebsocketURL" validate:"omitempty"`
|
||||
APIURL string `form:"APIURL" validate:"omitempty"`
|
||||
Type string `form:"Type" validate:"omitempty"`
|
||||
Name string `form:"Name" validate:"omitempty"`
|
||||
Category string `form:"Category" validate:"omitempty"`
|
||||
Properties postgres.Jsonb `form:"Properties" validate:"omitempty"`
|
||||
State string `form:"State" validate:"omitempty"`
|
||||
Location string `form:"Location" validate:"omitempty"`
|
||||
Description string `form:"Description" validate:"omitempty"`
|
||||
}
|
||||
|
||||
type AddICRequest struct {
|
||||
|
@ -77,11 +81,13 @@ func (r *AddICRequest) CreateIC() InfrastructureComponent {
|
|||
var s InfrastructureComponent
|
||||
|
||||
s.UUID = r.InfrastructureComponent.UUID
|
||||
s.Host = r.InfrastructureComponent.Host
|
||||
s.APIHost = r.InfrastructureComponent.APIHost
|
||||
s.WebsocketURL = r.InfrastructureComponent.WebsocketURL
|
||||
s.APIURL = r.InfrastructureComponent.APIURL
|
||||
s.Type = r.InfrastructureComponent.Type
|
||||
s.Name = r.InfrastructureComponent.Name
|
||||
s.Category = r.InfrastructureComponent.Category
|
||||
s.Location = r.InfrastructureComponent.Location
|
||||
s.Description = r.InfrastructureComponent.Description
|
||||
s.Properties = r.InfrastructureComponent.Properties
|
||||
if r.InfrastructureComponent.State != "" {
|
||||
s.State = r.InfrastructureComponent.State
|
||||
|
@ -102,12 +108,12 @@ func (r *UpdateICRequest) UpdatedIC(oldIC InfrastructureComponent) Infrastructur
|
|||
s.UUID = r.InfrastructureComponent.UUID
|
||||
}
|
||||
|
||||
if r.InfrastructureComponent.Host != "" {
|
||||
s.Host = r.InfrastructureComponent.Host
|
||||
if r.InfrastructureComponent.WebsocketURL != "" {
|
||||
s.WebsocketURL = r.InfrastructureComponent.WebsocketURL
|
||||
}
|
||||
|
||||
if r.InfrastructureComponent.APIHost != "" {
|
||||
s.APIHost = r.InfrastructureComponent.APIHost
|
||||
if r.InfrastructureComponent.APIURL != "" {
|
||||
s.APIURL = r.InfrastructureComponent.APIURL
|
||||
}
|
||||
|
||||
if r.InfrastructureComponent.Type != "" {
|
||||
|
@ -126,6 +132,14 @@ func (r *UpdateICRequest) UpdatedIC(oldIC InfrastructureComponent) Infrastructur
|
|||
s.State = r.InfrastructureComponent.State
|
||||
}
|
||||
|
||||
if r.InfrastructureComponent.Location != "" {
|
||||
s.Location = r.InfrastructureComponent.Location
|
||||
}
|
||||
|
||||
if r.InfrastructureComponent.Description != "" {
|
||||
s.Description = r.InfrastructureComponent.Description
|
||||
}
|
||||
|
||||
// set last update time
|
||||
s.StateUpdateAt = time.Now().Format(time.RFC1123)
|
||||
|
||||
|
|
|
@ -56,13 +56,15 @@ type ConfigRequest struct {
|
|||
}
|
||||
|
||||
type ICRequest struct {
|
||||
UUID string `json:"uuid,omitempty"`
|
||||
Host string `json:"host,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Category string `json:"category,omitempty"`
|
||||
State string `json:"state,omitempty"`
|
||||
Properties postgres.Jsonb `json:"properties,omitempty"`
|
||||
UUID string `json:"uuid,omitempty"`
|
||||
WebsocketURL string `json:"websocketurl,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Category string `json:"category,omitempty"`
|
||||
State string `json:"state,omitempty"`
|
||||
Location string `json:"location,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Properties postgres.Jsonb `json:"properties,omitempty"`
|
||||
}
|
||||
|
||||
type ScenarioRequest struct {
|
||||
|
@ -79,13 +81,15 @@ func addScenarioAndICAndConfig() (scenarioID uint, ICID uint, configID uint) {
|
|||
|
||||
// POST $newICA
|
||||
newICA := ICRequest{
|
||||
UUID: helper.ICA.UUID,
|
||||
Host: helper.ICA.Host,
|
||||
Type: helper.ICA.Type,
|
||||
Name: helper.ICA.Name,
|
||||
Category: helper.ICA.Category,
|
||||
State: helper.ICA.State,
|
||||
Properties: helper.ICA.Properties,
|
||||
UUID: helper.ICA.UUID,
|
||||
WebsocketURL: helper.ICA.WebsocketURL,
|
||||
Type: helper.ICA.Type,
|
||||
Name: helper.ICA.Name,
|
||||
Category: helper.ICA.Category,
|
||||
State: helper.ICA.State,
|
||||
Location: helper.ICA.Location,
|
||||
Description: helper.ICA.Description,
|
||||
Properties: helper.ICA.Properties,
|
||||
}
|
||||
_, resp, _ := helper.TestEndpoint(router, token,
|
||||
"/api/ic", "POST", helper.KeyModels{"ic": newICA})
|
||||
|
|
Loading…
Add table
Reference in a new issue