-
Notifications
You must be signed in to change notification settings - Fork 8
/
property_value.go
38 lines (27 loc) · 1.15 KB
/
property_value.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package api
import (
"context"
"github.com/grafana/iot-sitewise-datasource/pkg/framer"
"github.com/grafana/iot-sitewise-datasource/pkg/sitewise/client"
"github.com/aws/aws-sdk-go/service/iotsitewise"
"github.com/grafana/iot-sitewise-datasource/pkg/models"
)
func valueQueryToInput(query models.AssetPropertyValueQuery) *iotsitewise.GetAssetPropertyValueInput {
return &iotsitewise.GetAssetPropertyValueInput{
AssetId: getAssetId(query.BaseQuery),
PropertyId: getPropertyId(query.BaseQuery),
PropertyAlias: getPropertyAlias(query.BaseQuery),
}
}
func GetAssetPropertyValue(ctx context.Context, client client.SitewiseClient, query models.AssetPropertyValueQuery) (models.AssetPropertyValueQuery, *framer.AssetPropertyValue, error) {
modifiedQuery, err := getAssetIdAndPropertyId(query, client, ctx)
if err != nil {
return models.AssetPropertyValueQuery{}, nil, err
}
awsReq := valueQueryToInput(modifiedQuery)
resp, err := client.GetAssetPropertyValueWithContext(ctx, awsReq)
if err != nil {
return models.AssetPropertyValueQuery{}, nil, err
}
return modifiedQuery, &framer.AssetPropertyValue{PropertyValue: resp.PropertyValue}, nil
}