github.com/akamai/AkamaiOPEN-edgegrid-golang@v1.2.2/api-endpoints-v2/versions.go (about) 1 package apiendpoints 2 3 import ( 4 "fmt" 5 6 "github.com/akamai/AkamaiOPEN-edgegrid-golang/client-v1" 7 ) 8 9 type Versions struct { 10 APIEndPointID int `json:"apiEndPointId"` 11 APIEndPointName string `json:"apiEndPointName"` 12 APIVersions []Version `json:"apiVersions"` 13 } 14 15 type Version struct { 16 CreatedBy string `json:"createdBy"` 17 CreateDate string `json:"createDate"` 18 UpdateDate string `json:"updateDate"` 19 UpdatedBy string `json:"updatedBy"` 20 APIEndPointVersionID int `json:"apiEndPointVersionId"` 21 BasePath string `json:"basePath"` 22 Description *string `json:"description` 23 BasedOn *int `json:"basedOn"` 24 StagingStatus *StatusValue `json:"stagingStatus"` 25 ProductionStatus *StatusValue `json:"productionStatus"` 26 StagingDate *string `json:"stagingDate"` 27 ProductionDate *string `json:"productionDate"` 28 IsVersionLocked bool `json:"isVersionLocked"` 29 AvailableActions []string `json:"availableActions"` 30 VersionNumber int `json:"versionNumber"` 31 LockVersion int `json:"lockVersion"` 32 } 33 34 type VersionSummary struct { 35 Status StatusValue `json:"status,omitempty"` 36 VersionNumber int `json:"versionNumber,omitempty"` 37 } 38 39 type StatusValue string 40 41 const ( 42 StatusPending string = "PENDING" 43 StatusActive string = "ACTIVE" 44 StatusDeactivated string = "DEACTIVATED" 45 StatusFailed string = "FAILED" 46 ) 47 48 type ListVersionsOptions struct { 49 EndpointId int 50 } 51 52 func ListVersions(options *ListVersionsOptions) (*Versions, error) { 53 req, err := client.NewJSONRequest( 54 Config, 55 "GET", 56 fmt.Sprintf( 57 "/api-definitions/v2/endpoints/%d/versions", 58 options.EndpointId, 59 ), 60 nil, 61 ) 62 63 if err != nil { 64 return nil, err 65 } 66 67 res, err := client.Do(Config, req) 68 69 if client.IsError(res) { 70 return nil, client.NewAPIError(res) 71 } 72 73 rep := &Versions{} 74 if err = client.BodyJSON(res, rep); err != nil { 75 return nil, err 76 } 77 78 return rep, nil 79 } 80 81 type GetVersionOptions struct { 82 EndpointId int 83 Version int 84 } 85 86 func GetVersion(options *GetVersionOptions) (*Endpoint, error) { 87 if options.Version == 0 { 88 versions, err := ListVersions(&ListVersionsOptions{EndpointId: options.EndpointId}) 89 if err != nil { 90 return nil, err 91 } 92 93 loc := len(versions.APIVersions) - 1 94 v := versions.APIVersions[loc] 95 options.Version = v.VersionNumber 96 } 97 98 req, err := client.NewJSONRequest( 99 Config, 100 "GET", 101 fmt.Sprintf( 102 "/api-definitions/v2/endpoints/%d/versions/%d/resources-detail", 103 options.EndpointId, 104 options.Version, 105 ), 106 nil, 107 ) 108 109 return call(req, err) 110 } 111 112 func ModifyVersion(endpoint *Endpoint) (*Endpoint, error) { 113 req, err := client.NewJSONRequest( 114 Config, 115 "PUT", 116 fmt.Sprintf( 117 "/api-definitions/v2/endpoints/%d/versions/%d", 118 endpoint.APIEndPointID, 119 endpoint.VersionNumber, 120 ), 121 endpoint, 122 ) 123 124 return call(req, err) 125 } 126 127 type CloneVersionOptions struct { 128 EndpointId int 129 Version int 130 } 131 132 func CloneVersion(options *CloneVersionOptions) (*Endpoint, error) { 133 req, err := client.NewJSONRequest( 134 Config, 135 "POST", 136 fmt.Sprintf( 137 "/api-definitions/v2/endpoints/%d/versions/%d/cloneVersion", 138 options.EndpointId, 139 options.Version, 140 ), 141 options, 142 ) 143 144 return call(req, err) 145 } 146 147 type RemoveVersionOptions struct { 148 EndpointId int 149 VersionNumber int 150 } 151 152 func RemoveVersion(options *RemoveVersionOptions) (*Endpoint, error) { 153 req, err := client.NewJSONRequest( 154 Config, 155 "DELETE", 156 fmt.Sprintf( 157 "/api-definitions/v2/endpoints/%d/versions/%d", 158 options.EndpointId, 159 options.VersionNumber, 160 ), 161 nil, 162 ) 163 164 return call(req, err) 165 }