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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
|
package apiendpoints
import (
"fmt"
"github.com/akamai/AkamaiOPEN-edgegrid-golang/client-v1"
)
type Versions struct {
APIEndPointID int `json:"apiEndPointId"`
APIEndPointName string `json:"apiEndPointName"`
APIVersions []Version `json:"apiVersions"`
}
type Version struct {
CreatedBy string `json:"createdBy"`
CreateDate string `json:"createDate"`
UpdateDate string `json:"updateDate"`
UpdatedBy string `json:"updatedBy"`
APIEndPointVersionID int `json:"apiEndPointVersionId"`
BasePath string `json:"basePath"`
Description *string `json:"description`
BasedOn *int `json:"basedOn"`
StagingStatus *StatusValue `json:"stagingStatus"`
ProductionStatus *StatusValue `json:"productionStatus"`
StagingDate *string `json:"stagingDate"`
ProductionDate *string `json:"productionDate"`
IsVersionLocked bool `json:"isVersionLocked"`
AvailableActions []string `json:"availableActions"`
VersionNumber int `json:"versionNumber"`
LockVersion int `json:"lockVersion"`
}
type VersionSummary struct {
Status StatusValue `json:"status,omitempty"`
VersionNumber int `json:"versionNumber,omitempty"`
}
type StatusValue string
const (
StatusPending string = "PENDING"
StatusActive string = "ACTIVE"
StatusDeactivated string = "DEACTIVATED"
StatusFailed string = "FAILED"
)
type ListVersionsOptions struct {
EndpointId int
}
func ListVersions(options *ListVersionsOptions) (*Versions, error) {
req, err := client.NewJSONRequest(
Config,
"GET",
fmt.Sprintf(
"/api-definitions/v2/endpoints/%d/versions",
options.EndpointId,
),
nil,
)
if err != nil {
return nil, err
}
res, err := client.Do(Config, req)
if client.IsError(res) {
return nil, client.NewAPIError(res)
}
rep := &Versions{}
if err = client.BodyJSON(res, rep); err != nil {
return nil, err
}
return rep, nil
}
type GetVersionOptions struct {
EndpointId int
Version int
}
func GetVersion(options *GetVersionOptions) (*Endpoint, error) {
if options.Version == 0 {
versions, err := ListVersions(&ListVersionsOptions{EndpointId: options.EndpointId})
if err != nil {
return nil, err
}
loc := len(versions.APIVersions) - 1
v := versions.APIVersions[loc]
options.Version = v.VersionNumber
}
req, err := client.NewJSONRequest(
Config,
"GET",
fmt.Sprintf(
"/api-definitions/v2/endpoints/%d/versions/%d/resources-detail",
options.EndpointId,
options.Version,
),
nil,
)
return call(req, err)
}
func ModifyVersion(endpoint *Endpoint) (*Endpoint, error) {
req, err := client.NewJSONRequest(
Config,
"PUT",
fmt.Sprintf(
"/api-definitions/v2/endpoints/%d/versions/%d",
endpoint.APIEndPointID,
endpoint.VersionNumber,
),
endpoint,
)
return call(req, err)
}
type CloneVersionOptions struct {
EndpointId int
Version int
}
func CloneVersion(options *CloneVersionOptions) (*Endpoint, error) {
req, err := client.NewJSONRequest(
Config,
"POST",
fmt.Sprintf(
"/api-definitions/v2/endpoints/%d/versions/%d/cloneVersion",
options.EndpointId,
options.Version,
),
options,
)
return call(req, err)
}
type RemoveVersionOptions struct {
EndpointId int
VersionNumber int
}
func RemoveVersion(options *RemoveVersionOptions) (*Endpoint, error) {
req, err := client.NewJSONRequest(
Config,
"DELETE",
fmt.Sprintf(
"/api-definitions/v2/endpoints/%d/versions/%d",
options.EndpointId,
options.VersionNumber,
),
nil,
)
return call(req, err)
}
|