Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/coverage/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ code does not implement. Machine-readable: [`coverage.json`](./coverage.json).
| `acm` | [ACM](./aws/acm.md) | - | - | - | 17 |
| `aks` | - | [AKS](./azure/aks.md) | - | - | 18 |
| `aoss` | [AOSS](./aws/aoss.md) | - | - | - | 18 |
| `apigateway` | [APIGateway](./aws/apigateway.md) | - | - | - | 29 |
| `apigateway` | [APIGateway](./aws/apigateway.md) | - | - | - | 50 |
| `apigatewaygcp` | - | - | [APIGateway](./gcp/apigateway.md) | - | 16 |
| `apigatewayv2` | [APIGatewayV2](./aws/apigatewayv2.md) | - | - | - | 28 |
| `appconfiguration` | - | [AppConfiguration](./azure/appconfiguration.md) | - | - | 9 |
Expand Down
2 changes: 1 addition & 1 deletion docs/coverage/aws/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Services cloudemu emulates for AWS, by native name. Back to the [cross-provider
| --- | --- | --- |
| [ACM](./acm.md) | `acm` | 17 |
| [AOSS](./aoss.md) | `aoss` | 18 |
| [APIGateway](./apigateway.md) | `apigateway` | 29 |
| [APIGateway](./apigateway.md) | `apigateway` | 50 |
| [APIGatewayV2](./apigatewayv2.md) | `apigatewayv2` | 28 |
| [APS](./aps.md) | `aps` | 21 |
| [AppFlow](./appflow.md) | `appflow` | 14 |
Expand Down
23 changes: 22 additions & 1 deletion docs/coverage/aws/apigateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,35 @@

AWS's `apigateway` service · portable interface `driver.APIGateway` · [AWS index](./README.md)

## Operations (29)
## Operations (50)

| Operation | Description |
| --- | --- |
| `CreateDeployment` | |
| `CreateDocumentationPart` | |
| `CreateDocumentationVersion` | CreateDocumentationVersion snapshots the API's current documentation |
| `CreateResource` | |
| `CreateRestAPI` | |
| `CreateStage` | |
| `DeleteClientCertificate` | DeleteClientCertificate removes a certificate. It fails while a stage |
| `DeleteDeployment` | DeleteDeployment removes a deployment. It fails with a FailedPrecondition |
| `DeleteDocumentationPart` | |
| `DeleteDocumentationVersion` | DeleteDocumentationVersion removes a version. It fails while a stage |
| `DeleteIntegration` | |
| `DeleteMethod` | |
| `DeleteResource` | DeleteResource removes a resource and its whole descendant subtree, as |
| `DeleteRestAPI` | |
| `DeleteStage` | |
| `GenerateClientCertificate` | GenerateClientCertificate creates a self-signed client certificate valid |
| `GetAccount` | |
| `GetClientCertificate` | |
| `GetClientCertificates` | |
| `GetDeployment` | |
| `GetDeployments` | |
| `GetDocumentationPart` | |
| `GetDocumentationParts` | |
| `GetDocumentationVersion` | |
| `GetDocumentationVersions` | |
| `GetIntegration` | |
| `GetMethod` | |
| `GetResource` | |
Expand All @@ -27,10 +40,18 @@ AWS's `apigateway` service · portable interface `driver.APIGateway` · [AWS ind
| `GetRestAPIs` | |
| `GetStage` | |
| `GetStages` | |
| `GetTags` | |
| `ImportDocumentationParts` | |
| `InvokeRoute` | InvokeRoute routes req through the tree its stage's deployment captured. |
| `PutIntegration` | |
| `PutMethod` | |
| `TagResource` | TagResource, UntagResource and GetTags manage tags on a REST API or client |
| `UntagResource` | |
| `UpdateAccount` | UpdateAccount applies a patchOperations document (/cloudwatchRoleArn |
| `UpdateClientCertificate` | UpdateClientCertificate applies a patchOperations document (only |
| `UpdateDeployment` | UpdateDeployment applies a patchOperations document to a deployment |
| `UpdateDocumentationPart` | UpdateDocumentationPart applies a patchOperations document (only |
| `UpdateDocumentationVersion` | UpdateDocumentationVersion applies a patchOperations document (only |
| `UpdateIntegration` | UpdateIntegration applies a patchOperations document to an integration. |
| `UpdateMethod` | UpdateMethod applies a patchOperations document to a method. |
| `UpdateResource` | UpdateResource applies a patchOperations document to a resource (rename via |
Expand Down
72 changes: 72 additions & 0 deletions docs/coverage/coverage.json
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,13 @@
{
"name": "CreateDeployment"
},
{
"name": "CreateDocumentationPart"
},
{
"name": "CreateDocumentationVersion",
"doc": "CreateDocumentationVersion snapshots the API's current documentation"
},
{
"name": "CreateResource"
},
Expand All @@ -278,10 +285,21 @@
{
"name": "CreateStage"
},
{
"name": "DeleteClientCertificate",
"doc": "DeleteClientCertificate removes a certificate. It fails while a stage"
},
{
"name": "DeleteDeployment",
"doc": "DeleteDeployment removes a deployment. It fails with a FailedPrecondition"
},
{
"name": "DeleteDocumentationPart"
},
{
"name": "DeleteDocumentationVersion",
"doc": "DeleteDocumentationVersion removes a version. It fails while a stage"
},
{
"name": "DeleteIntegration"
},
Expand All @@ -298,12 +316,37 @@
{
"name": "DeleteStage"
},
{
"name": "GenerateClientCertificate",
"doc": "GenerateClientCertificate creates a self-signed client certificate valid"
},
{
"name": "GetAccount"
},
{
"name": "GetClientCertificate"
},
{
"name": "GetClientCertificates"
},
{
"name": "GetDeployment"
},
{
"name": "GetDeployments"
},
{
"name": "GetDocumentationPart"
},
{
"name": "GetDocumentationParts"
},
{
"name": "GetDocumentationVersion"
},
{
"name": "GetDocumentationVersions"
},
{
"name": "GetIntegration"
},
Expand All @@ -328,6 +371,12 @@
{
"name": "GetStages"
},
{
"name": "GetTags"
},
{
"name": "ImportDocumentationParts"
},
{
"name": "InvokeRoute",
"doc": "InvokeRoute routes req through the tree its stage's deployment captured."
Expand All @@ -338,10 +387,33 @@
{
"name": "PutMethod"
},
{
"name": "TagResource",
"doc": "TagResource, UntagResource and GetTags manage tags on a REST API or client"
},
{
"name": "UntagResource"
},
{
"name": "UpdateAccount",
"doc": "UpdateAccount applies a patchOperations document (/cloudwatchRoleArn"
},
{
"name": "UpdateClientCertificate",
"doc": "UpdateClientCertificate applies a patchOperations document (only"
},
{
"name": "UpdateDeployment",
"doc": "UpdateDeployment applies a patchOperations document to a deployment"
},
{
"name": "UpdateDocumentationPart",
"doc": "UpdateDocumentationPart applies a patchOperations document (only"
},
{
"name": "UpdateDocumentationVersion",
"doc": "UpdateDocumentationVersion applies a patchOperations document (only"
},
{
"name": "UpdateIntegration",
"doc": "UpdateIntegration applies a patchOperations document to an integration."
Expand Down
99 changes: 99 additions & 0 deletions providers/aws/apigateway/account.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package apigateway

import (
"context"
"regexp"

cerrors "github.com/stackshy/cloudemu/v2/errors"
"github.com/stackshy/cloudemu/v2/services/apigateway/driver"
)

// Account defaults of a fresh region: 10000 requests/second with a burst of
// 5000, usage plans enabled and API key version 4.
const (
defaultRateLimit = 10000
defaultBurstLimit = 5000
featureUsagePlans = "UsagePlans"
defaultAPIKeyVersion = "4"

pathCloudWatchRoleARN = "/cloudwatchRoleArn"
pathFeatures = "/features"
)

// roleARNPattern is the shape of an IAM role ARN.
var roleARNPattern = regexp.MustCompile(`^arn:aws[a-zA-Z-]*:iam::\d{12}:role/.+$`)

func defaultAccount() driver.Account {
return driver.Account{
Throttle: driver.ThrottleSettings{BurstLimit: defaultBurstLimit, RateLimit: defaultRateLimit},
Features: []string{featureUsagePlans},
APIKeyVersion: defaultAPIKeyVersion,
}
}

// GetAccount returns the region's account settings.
func (m *Mock) GetAccount(_ context.Context) (*driver.Account, error) {
m.regionMu.RLock()
defer m.regionMu.RUnlock()

out := copyAccount(&m.account)

return &out, nil
}

// UpdateAccount applies a patch document. Only the CloudWatch role and the
// feature list are writable; throttle limits and the API key version are
// set by the service.
func (m *Mock) UpdateAccount(_ context.Context, ops []driver.PatchOperation) (*driver.Account, error) {
m.regionMu.Lock()
defer m.regionMu.Unlock()

next := copyAccount(&m.account)

for _, op := range ops {
if err := applyAccountPatch(&next, op); err != nil {
return nil, err
}
}

m.account = next
out := copyAccount(&m.account)

return &out, nil
}

func applyAccountPatch(acct *driver.Account, op driver.PatchOperation) error {
switch op.Path {
case pathCloudWatchRoleARN:
role := patchRef(op)
if role != "" && !roleARNPattern.MatchString(role) {
return cerrors.Newf(cerrors.InvalidArgument, "The role ARN is not well formed: %s", role)
}

acct.CloudWatchRoleARN = role
case pathFeatures:
if op.Value != featureUsagePlans {
return cerrors.Newf(cerrors.InvalidArgument, "Invalid feature '%s'. Must be one of: [%s]", op.Value, featureUsagePlans)
}

switch op.Op {
case opAdd:
acct.Features = patchStringSlice(acct.Features, opAdd, op.Value)
case opRemove:
acct.Features = patchStringSlice(acct.Features, opRemove, op.Value)
default:
return invalidPatchPath(op, pathCloudWatchRoleARN)
}
default:
return invalidPatchPath(op, pathCloudWatchRoleARN, pathFeatures)
}

return nil
}

func copyAccount(a *driver.Account) driver.Account {
out := *a
out.Features = append([]string{}, a.Features...)

return out
}
Loading
Loading