-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
284 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Copyright 2020 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package apigee | ||
|
||
import ( | ||
"net/url" | ||
"path" | ||
) | ||
|
||
const cachePath = "caches" | ||
|
||
// CacheService is an interface for interfacing with the Apigee Edge Admin API | ||
// dealing with caches. | ||
type CacheService interface { | ||
Get(cachename string) (*Cache, *Response, error) | ||
Create(cache Cache) (*Response, error) | ||
} | ||
|
||
// Cache represents a cache definition | ||
type Cache struct { | ||
Name string `json:"-,omitempty"` | ||
Description string `json:"description,omitempty"` | ||
ExpirySettings *expirySettings `json:"expirySettings,omitempty"` | ||
OverflowToDisk *bool `json:"overflowToDisk,omitempty"` | ||
SkipCacheIfElementSizeInKBExceeds *string `json:"skipCacheIfElementSizeInKBExceeds,omitempty"` | ||
} | ||
|
||
type expirySettings struct { | ||
ExpiryDate expiryDate `json:"expiryDate,omitempty"` | ||
ValuesNull string `json:"valuesNull,omitempty"` | ||
} | ||
|
||
type expiryDate struct { | ||
Value string `json:"value,omitempty"` | ||
} | ||
|
||
// CacheServiceOp represents a cache service operation | ||
type CacheServiceOp struct { | ||
client *EdgeClient | ||
} | ||
|
||
var _ CacheService = &CacheServiceOp{} | ||
|
||
// Get returns a response given a cache name | ||
func (s *CacheServiceOp) Get(cachename string) (*Cache, *Response, error) { | ||
path := path.Join(cachePath, cachename) | ||
req, e := s.client.NewRequest("GET", path, nil) | ||
if e != nil { | ||
return nil, nil, e | ||
} | ||
returnedCache := Cache{} | ||
resp, e := s.client.Do(req, &returnedCache) | ||
if e != nil { | ||
return nil, resp, e | ||
} | ||
return &returnedCache, resp, e | ||
} | ||
|
||
// Create creates a cache and returns a response | ||
func (s *CacheServiceOp) Create(cache Cache) (*Response, error) { | ||
path := path.Join(cachePath) | ||
u, _ := url.Parse(path) | ||
q := u.Query() | ||
q.Set("name", cache.Name) | ||
u.RawQuery = q.Encode() | ||
req, e := s.client.NewRequest("POST", u.String(), cache) | ||
if e != nil { | ||
return nil, e | ||
} | ||
resp, e := s.client.Do(req, &cache) | ||
return resp, e | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
proxies/remote-proxy-gcp/apiproxy/policies/Lookup-Products.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<LookupCache async="false" continueOnError="false" enabled="true" name="Lookup-Products"> | ||
<DisplayName>Lookup Products</DisplayName> | ||
<CacheKey> | ||
<KeyFragment ref="request.uri"/> | ||
</CacheKey> | ||
<Scope>Exclusive</Scope> | ||
<AssignTo>productlist</AssignTo> | ||
<CacheResource>remote-service</CacheResource> | ||
</LookupCache> |
15 changes: 15 additions & 0 deletions
15
proxies/remote-proxy-gcp/apiproxy/policies/Populate-Product-List.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<PopulateCache async="false" continueOnError="false" enabled="true" name="Populate-Product-List"> | ||
<DisplayName>Populate Product List</DisplayName> | ||
<Properties/> | ||
<CacheKey> | ||
<Prefix/> | ||
<KeyFragment ref="request.uri"/> | ||
</CacheKey> | ||
<CacheResource>remote-service</CacheResource> | ||
<Scope>Exclusive</Scope> | ||
<ExpirySettings> | ||
<TimeoutInSec>120</TimeoutInSec> | ||
</ExpirySettings> | ||
<Source>response.content</Source> | ||
</PopulateCache> |
14 changes: 14 additions & 0 deletions
14
proxies/remote-proxy-gcp/apiproxy/policies/Send-Product-List.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<AssignMessage async="false" continueOnError="false" enabled="true" name="Send-Product-List"> | ||
<DisplayName>Send Product List</DisplayName> | ||
<Properties/> | ||
<Set> | ||
<Headers> | ||
<Header name="Cache-Control">no-store</Header> | ||
<Header name="Pragma">no-cache</Header> | ||
</Headers> | ||
<Payload contentType="application/json" variablePrefix="@" variableSuffix="#">@productlist#</Payload> | ||
</Set> | ||
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables> | ||
<AssignTo createNew="false" transport="http" type="response"/> | ||
</AssignMessage> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,52 @@ | ||
<APIProxy revision="1" name="remote-service"> | ||
<DisplayName>remote-service</DisplayName> | ||
<Description>remote-service</Description> | ||
<CreatedAt>1586561070679</CreatedAt> | ||
<LastModifiedAt>1586561070679</LastModifiedAt> | ||
<CreatedAt>1587832719075</CreatedAt> | ||
<LastModifiedAt>1587832876047</LastModifiedAt> | ||
<BasePaths>/remote-service</BasePaths> | ||
<Policies> | ||
<Policy>Clear-API-Key</Policy> | ||
<Policy>Access-App-Info</Policy> | ||
<Policy>JavaCallout</Policy> | ||
<Policy>Set-Quota-Response</Policy> | ||
<Policy>Create-Refresh-Request</Policy> | ||
<Policy>Set-Quota-Variables</Policy> | ||
<Policy>Generate-VerifyKey-Token</Policy> | ||
<Policy>DistributedQuota</Policy> | ||
<Policy>RevokeRefreshToken</Policy> | ||
<Policy>Extract-API-Key</Policy> | ||
<Policy>Create-Refresh-Request</Policy> | ||
<Policy>Set-JWT-Variables</Policy> | ||
<Policy>Clear-API-Key</Policy> | ||
<Policy>Set-Response</Policy> | ||
<Policy>AccessTokenRequest</Policy> | ||
<Policy>Raise-Fault-Unknown-Request</Policy> | ||
<Policy>Raise-Fault-Missing-Secret</Policy> | ||
<Policy>RefreshAccessToken</Policy> | ||
<Policy>JavaCallout</Policy> | ||
<Policy>Extract-Refresh-Params</Policy> | ||
<Policy>Generate-VerifyKey-Token</Policy> | ||
<Policy>Eval-Quota-Result</Policy> | ||
<Policy>Extract-API-Key</Policy> | ||
<Policy>Verify-API-Key</Policy> | ||
<Policy>Products-to-JSON</Policy> | ||
<Policy>Create-OAuth-Request</Policy> | ||
<Policy>Raise-Fault-Unknown-Request</Policy> | ||
<Policy>Extract-Revoke-Params</Policy> | ||
<Policy>Set-Quota-Variables</Policy> | ||
<Policy>Generate-Access-Token</Policy> | ||
<Policy>Extract-Refresh-Params</Policy> | ||
<Policy>Extract-OAuth-Params</Policy> | ||
<Policy>Send-Version</Policy> | ||
<Policy>Set-Response</Policy> | ||
<Policy>Extract-Revoke-Params</Policy> | ||
<Policy>Set-JWT-Variables</Policy> | ||
<Policy>Decode-Basic-Authentication</Policy> | ||
<Policy>Products-to-JSON</Policy> | ||
<Policy>Verify-API-Key</Policy> | ||
<Policy>AccessTokenRequest</Policy> | ||
<Policy>Access-App-Info</Policy> | ||
<Policy>Eval-Quota-Result</Policy> | ||
<Policy>DistributedQuota</Policy> | ||
<Policy>Send-JWKs-Message</Policy> | ||
<Policy>Raise-Fault-Missing-Secret</Policy> | ||
<Policy>Assign-Debug</Policy> | ||
<Policy>Send-JWKs-Message</Policy> | ||
<Policy>Decode-Basic-Authentication</Policy> | ||
<Policy>Send-Version</Policy> | ||
<Policy>Lookup-Products</Policy> | ||
<Policy>Populate-Product-List</Policy> | ||
<Policy>Send-Product-List</Policy> | ||
</Policies> | ||
<ProxyEndpoints> | ||
<ProxyEndpoint>default</ProxyEndpoint> | ||
</ProxyEndpoints> | ||
<Resources> | ||
<Resource>java://products-javacallout-2.0.0.jar</Resource> | ||
<Resource>jsc://set-quota-variables.js</Resource> | ||
<Resource>jsc://set-jwt-variables.js</Resource> | ||
<Resource>jsc://eval-quota-result.js</Resource> | ||
<Resource>jsc://set-response.js</Resource> | ||
<Resource>jsc://set-jwt-variables.js</Resource> | ||
</Resources> | ||
<TargetServers></TargetServers> | ||
<TargetEndpoints></TargetEndpoints> | ||
</APIProxy> | ||
</APIProxy> |
Oops, something went wrong.