/
search.go
75 lines (61 loc) · 1.87 KB
/
search.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package papi
import (
"time"
"github.com/akamai/AkamaiOPEN-edgegrid-golang/client-v1"
edge "github.com/akamai/AkamaiOPEN-edgegrid-golang/edgegrid"
)
type SearchKey string
const (
SearchByPropertyName SearchKey = "propertyName"
SearchByHostname SearchKey = "hostname"
SearchByEdgeHostname SearchKey = "edgeHostname"
)
type SearchResult struct {
Versions struct {
Items []struct {
UpdatedByUser string `json:"updatedByUser"`
StagingStatus string `json:"stagingStatus"`
AssetID string `json:"assetId"`
PropertyName string `json:"propertyName"`
PropertyVersion int `json:"propertyVersion"`
UpdatedDate time.Time `json:"updatedDate"`
ContractID string `json:"contractId"`
AccountID string `json:"accountId"`
GroupID string `json:"groupId"`
PropertyID string `json:"propertyId"`
ProductionStatus string `json:"productionStatus"`
} `json:"items"`
} `json:"versions"`
}
// Search searches for properties
//
// API Docs: https://developer.akamai.com/api/luna/papi/resources.html#postfindbyvalue
// Endpoint: POST /papi/v1/search/find-by-value
func Search(searchBy SearchKey, propertyName string, correlationid string) (*SearchResult, error) {
req, err := client.NewJSONRequest(
Config,
"POST",
"/papi/v1/search/find-by-value",
map[string]string{(string)(searchBy): propertyName},
)
if err != nil {
return nil, err
}
edge.PrintHttpRequestCorrelation(req, true, correlationid)
res, err := client.Do(Config, req)
if err != nil {
return nil, err
}
edge.PrintHttpResponseCorrelation(res, true, correlationid)
if client.IsError(res) {
return nil, client.NewAPIError(res)
}
results := &SearchResult{}
if err = client.BodyJSON(res, results); err != nil {
return nil, err
}
if len(results.Versions.Items) == 0 {
return nil, nil
}
return results, nil
}