Skip to content

Commit

Permalink
fix: stop adding command mw repeatedly in resolveMiddleware() (#1883)
Browse files Browse the repository at this point in the history
When sending the same command multiple times, resolveMiddleware()
will be called many times. So adding serde middleware will throw
error because they are already added into stack. This change
prevents adding the serde middleware repeatedly.

Alternative is moving command middleware to the command constructor,
just like in client(that's why client doesn't have the problem). But
the command middleware also have depdency over client configs
supplied from resolveMiddleware(). So serde middleware and
customizations must live here.

ref: #1864
  • Loading branch information
AllanZhengYP committed Jan 8, 2021
1 parent b8542d8 commit d4c302b
Show file tree
Hide file tree
Showing 8,945 changed files with 45,024 additions and 9,244 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
Expand Up @@ -28,6 +28,7 @@ export class CreateAnalyzerCommand extends $Command<
CreateAnalyzerCommandOutput,
AccessAnalyzerClientResolvedConfig
> {
private resolved = false;
// Start section: command_properties
// End section: command_properties

Expand All @@ -45,7 +46,10 @@ export class CreateAnalyzerCommand extends $Command<
configuration: AccessAnalyzerClientResolvedConfig,
options?: __HttpHandlerOptions
): Handler<CreateAnalyzerCommandInput, CreateAnalyzerCommandOutput> {
this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize));
if (!this.resolved) {
this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize));
this.resolved = true;
}

const stack = clientStack.concat(this.middlewareStack);

Expand Down
Expand Up @@ -29,6 +29,7 @@ export class CreateArchiveRuleCommand extends $Command<
CreateArchiveRuleCommandOutput,
AccessAnalyzerClientResolvedConfig
> {
private resolved = false;
// Start section: command_properties
// End section: command_properties

Expand All @@ -46,7 +47,10 @@ export class CreateArchiveRuleCommand extends $Command<
configuration: AccessAnalyzerClientResolvedConfig,
options?: __HttpHandlerOptions
): Handler<CreateArchiveRuleCommandInput, CreateArchiveRuleCommandOutput> {
this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize));
if (!this.resolved) {
this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize));
this.resolved = true;
}

const stack = clientStack.concat(this.middlewareStack);

Expand Down
Expand Up @@ -30,6 +30,7 @@ export class DeleteAnalyzerCommand extends $Command<
DeleteAnalyzerCommandOutput,
AccessAnalyzerClientResolvedConfig
> {
private resolved = false;
// Start section: command_properties
// End section: command_properties

Expand All @@ -47,7 +48,10 @@ export class DeleteAnalyzerCommand extends $Command<
configuration: AccessAnalyzerClientResolvedConfig,
options?: __HttpHandlerOptions
): Handler<DeleteAnalyzerCommandInput, DeleteAnalyzerCommandOutput> {
this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize));
if (!this.resolved) {
this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize));
this.resolved = true;
}

const stack = clientStack.concat(this.middlewareStack);

Expand Down
Expand Up @@ -28,6 +28,7 @@ export class DeleteArchiveRuleCommand extends $Command<
DeleteArchiveRuleCommandOutput,
AccessAnalyzerClientResolvedConfig
> {
private resolved = false;
// Start section: command_properties
// End section: command_properties

Expand All @@ -45,7 +46,10 @@ export class DeleteArchiveRuleCommand extends $Command<
configuration: AccessAnalyzerClientResolvedConfig,
options?: __HttpHandlerOptions
): Handler<DeleteArchiveRuleCommandInput, DeleteArchiveRuleCommandOutput> {
this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize));
if (!this.resolved) {
this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize));
this.resolved = true;
}

const stack = clientStack.concat(this.middlewareStack);

Expand Down
Expand Up @@ -28,6 +28,7 @@ export class GetAnalyzedResourceCommand extends $Command<
GetAnalyzedResourceCommandOutput,
AccessAnalyzerClientResolvedConfig
> {
private resolved = false;
// Start section: command_properties
// End section: command_properties

Expand All @@ -45,7 +46,10 @@ export class GetAnalyzedResourceCommand extends $Command<
configuration: AccessAnalyzerClientResolvedConfig,
options?: __HttpHandlerOptions
): Handler<GetAnalyzedResourceCommandInput, GetAnalyzedResourceCommandOutput> {
this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize));
if (!this.resolved) {
this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize));
this.resolved = true;
}

const stack = clientStack.concat(this.middlewareStack);

Expand Down
6 changes: 5 additions & 1 deletion clients/client-accessanalyzer/commands/GetAnalyzerCommand.ts
Expand Up @@ -28,6 +28,7 @@ export class GetAnalyzerCommand extends $Command<
GetAnalyzerCommandOutput,
AccessAnalyzerClientResolvedConfig
> {
private resolved = false;
// Start section: command_properties
// End section: command_properties

Expand All @@ -45,7 +46,10 @@ export class GetAnalyzerCommand extends $Command<
configuration: AccessAnalyzerClientResolvedConfig,
options?: __HttpHandlerOptions
): Handler<GetAnalyzerCommandInput, GetAnalyzerCommandOutput> {
this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize));
if (!this.resolved) {
this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize));
this.resolved = true;
}

const stack = clientStack.concat(this.middlewareStack);

Expand Down
Expand Up @@ -28,6 +28,7 @@ export class GetArchiveRuleCommand extends $Command<
GetArchiveRuleCommandOutput,
AccessAnalyzerClientResolvedConfig
> {
private resolved = false;
// Start section: command_properties
// End section: command_properties

Expand All @@ -45,7 +46,10 @@ export class GetArchiveRuleCommand extends $Command<
configuration: AccessAnalyzerClientResolvedConfig,
options?: __HttpHandlerOptions
): Handler<GetArchiveRuleCommandInput, GetArchiveRuleCommandOutput> {
this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize));
if (!this.resolved) {
this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize));
this.resolved = true;
}

const stack = clientStack.concat(this.middlewareStack);

Expand Down
6 changes: 5 additions & 1 deletion clients/client-accessanalyzer/commands/GetFindingCommand.ts
Expand Up @@ -28,6 +28,7 @@ export class GetFindingCommand extends $Command<
GetFindingCommandOutput,
AccessAnalyzerClientResolvedConfig
> {
private resolved = false;
// Start section: command_properties
// End section: command_properties

Expand All @@ -45,7 +46,10 @@ export class GetFindingCommand extends $Command<
configuration: AccessAnalyzerClientResolvedConfig,
options?: __HttpHandlerOptions
): Handler<GetFindingCommandInput, GetFindingCommandOutput> {
this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize));
if (!this.resolved) {
this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize));
this.resolved = true;
}

const stack = clientStack.concat(this.middlewareStack);

Expand Down
Expand Up @@ -29,6 +29,7 @@ export class ListAnalyzedResourcesCommand extends $Command<
ListAnalyzedResourcesCommandOutput,
AccessAnalyzerClientResolvedConfig
> {
private resolved = false;
// Start section: command_properties
// End section: command_properties

Expand All @@ -46,7 +47,10 @@ export class ListAnalyzedResourcesCommand extends $Command<
configuration: AccessAnalyzerClientResolvedConfig,
options?: __HttpHandlerOptions
): Handler<ListAnalyzedResourcesCommandInput, ListAnalyzedResourcesCommandOutput> {
this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize));
if (!this.resolved) {
this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize));
this.resolved = true;
}

const stack = clientStack.concat(this.middlewareStack);

Expand Down
Expand Up @@ -28,6 +28,7 @@ export class ListAnalyzersCommand extends $Command<
ListAnalyzersCommandOutput,
AccessAnalyzerClientResolvedConfig
> {
private resolved = false;
// Start section: command_properties
// End section: command_properties

Expand All @@ -45,7 +46,10 @@ export class ListAnalyzersCommand extends $Command<
configuration: AccessAnalyzerClientResolvedConfig,
options?: __HttpHandlerOptions
): Handler<ListAnalyzersCommandInput, ListAnalyzersCommandOutput> {
this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize));
if (!this.resolved) {
this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize));
this.resolved = true;
}

const stack = clientStack.concat(this.middlewareStack);

Expand Down
Expand Up @@ -28,6 +28,7 @@ export class ListArchiveRulesCommand extends $Command<
ListArchiveRulesCommandOutput,
AccessAnalyzerClientResolvedConfig
> {
private resolved = false;
// Start section: command_properties
// End section: command_properties

Expand All @@ -45,7 +46,10 @@ export class ListArchiveRulesCommand extends $Command<
configuration: AccessAnalyzerClientResolvedConfig,
options?: __HttpHandlerOptions
): Handler<ListArchiveRulesCommandInput, ListArchiveRulesCommandOutput> {
this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize));
if (!this.resolved) {
this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize));
this.resolved = true;
}

const stack = clientStack.concat(this.middlewareStack);

Expand Down
Expand Up @@ -28,6 +28,7 @@ export class ListFindingsCommand extends $Command<
ListFindingsCommandOutput,
AccessAnalyzerClientResolvedConfig
> {
private resolved = false;
// Start section: command_properties
// End section: command_properties

Expand All @@ -45,7 +46,10 @@ export class ListFindingsCommand extends $Command<
configuration: AccessAnalyzerClientResolvedConfig,
options?: __HttpHandlerOptions
): Handler<ListFindingsCommandInput, ListFindingsCommandOutput> {
this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize));
if (!this.resolved) {
this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize));
this.resolved = true;
}

const stack = clientStack.concat(this.middlewareStack);

Expand Down
Expand Up @@ -28,6 +28,7 @@ export class ListTagsForResourceCommand extends $Command<
ListTagsForResourceCommandOutput,
AccessAnalyzerClientResolvedConfig
> {
private resolved = false;
// Start section: command_properties
// End section: command_properties

Expand All @@ -45,7 +46,10 @@ export class ListTagsForResourceCommand extends $Command<
configuration: AccessAnalyzerClientResolvedConfig,
options?: __HttpHandlerOptions
): Handler<ListTagsForResourceCommandInput, ListTagsForResourceCommandOutput> {
this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize));
if (!this.resolved) {
this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize));
this.resolved = true;
}

const stack = clientStack.concat(this.middlewareStack);

Expand Down
Expand Up @@ -28,6 +28,7 @@ export class StartResourceScanCommand extends $Command<
StartResourceScanCommandOutput,
AccessAnalyzerClientResolvedConfig
> {
private resolved = false;
// Start section: command_properties
// End section: command_properties

Expand All @@ -45,7 +46,10 @@ export class StartResourceScanCommand extends $Command<
configuration: AccessAnalyzerClientResolvedConfig,
options?: __HttpHandlerOptions
): Handler<StartResourceScanCommandInput, StartResourceScanCommandOutput> {
this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize));
if (!this.resolved) {
this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize));
this.resolved = true;
}

const stack = clientStack.concat(this.middlewareStack);

Expand Down
6 changes: 5 additions & 1 deletion clients/client-accessanalyzer/commands/TagResourceCommand.ts
Expand Up @@ -28,6 +28,7 @@ export class TagResourceCommand extends $Command<
TagResourceCommandOutput,
AccessAnalyzerClientResolvedConfig
> {
private resolved = false;
// Start section: command_properties
// End section: command_properties

Expand All @@ -45,7 +46,10 @@ export class TagResourceCommand extends $Command<
configuration: AccessAnalyzerClientResolvedConfig,
options?: __HttpHandlerOptions
): Handler<TagResourceCommandInput, TagResourceCommandOutput> {
this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize));
if (!this.resolved) {
this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize));
this.resolved = true;
}

const stack = clientStack.concat(this.middlewareStack);

Expand Down
Expand Up @@ -28,6 +28,7 @@ export class UntagResourceCommand extends $Command<
UntagResourceCommandOutput,
AccessAnalyzerClientResolvedConfig
> {
private resolved = false;
// Start section: command_properties
// End section: command_properties

Expand All @@ -45,7 +46,10 @@ export class UntagResourceCommand extends $Command<
configuration: AccessAnalyzerClientResolvedConfig,
options?: __HttpHandlerOptions
): Handler<UntagResourceCommandInput, UntagResourceCommandOutput> {
this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize));
if (!this.resolved) {
this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize));
this.resolved = true;
}

const stack = clientStack.concat(this.middlewareStack);

Expand Down
Expand Up @@ -28,6 +28,7 @@ export class UpdateArchiveRuleCommand extends $Command<
UpdateArchiveRuleCommandOutput,
AccessAnalyzerClientResolvedConfig
> {
private resolved = false;
// Start section: command_properties
// End section: command_properties

Expand All @@ -45,7 +46,10 @@ export class UpdateArchiveRuleCommand extends $Command<
configuration: AccessAnalyzerClientResolvedConfig,
options?: __HttpHandlerOptions
): Handler<UpdateArchiveRuleCommandInput, UpdateArchiveRuleCommandOutput> {
this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize));
if (!this.resolved) {
this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize));
this.resolved = true;
}

const stack = clientStack.concat(this.middlewareStack);

Expand Down
Expand Up @@ -28,6 +28,7 @@ export class UpdateFindingsCommand extends $Command<
UpdateFindingsCommandOutput,
AccessAnalyzerClientResolvedConfig
> {
private resolved = false;
// Start section: command_properties
// End section: command_properties

Expand All @@ -45,7 +46,10 @@ export class UpdateFindingsCommand extends $Command<
configuration: AccessAnalyzerClientResolvedConfig,
options?: __HttpHandlerOptions
): Handler<UpdateFindingsCommandInput, UpdateFindingsCommandOutput> {
this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize));
if (!this.resolved) {
this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize));
this.resolved = true;
}

const stack = clientStack.concat(this.middlewareStack);

Expand Down
Expand Up @@ -47,6 +47,7 @@ export class CreateCertificateAuthorityAuditReportCommand extends $Command<
CreateCertificateAuthorityAuditReportCommandOutput,
ACMPCAClientResolvedConfig
> {
private resolved = false;
// Start section: command_properties
// End section: command_properties

Expand All @@ -64,7 +65,10 @@ export class CreateCertificateAuthorityAuditReportCommand extends $Command<
configuration: ACMPCAClientResolvedConfig,
options?: __HttpHandlerOptions
): Handler<CreateCertificateAuthorityAuditReportCommandInput, CreateCertificateAuthorityAuditReportCommandOutput> {
this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize));
if (!this.resolved) {
this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize));
this.resolved = true;
}

const stack = clientStack.concat(this.middlewareStack);

Expand Down
Expand Up @@ -46,6 +46,7 @@ export class CreateCertificateAuthorityCommand extends $Command<
CreateCertificateAuthorityCommandOutput,
ACMPCAClientResolvedConfig
> {
private resolved = false;
// Start section: command_properties
// End section: command_properties

Expand All @@ -63,7 +64,10 @@ export class CreateCertificateAuthorityCommand extends $Command<
configuration: ACMPCAClientResolvedConfig,
options?: __HttpHandlerOptions
): Handler<CreateCertificateAuthorityCommandInput, CreateCertificateAuthorityCommandOutput> {
this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize));
if (!this.resolved) {
this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize));
this.resolved = true;
}

const stack = clientStack.concat(this.middlewareStack);

Expand Down

0 comments on commit d4c302b

Please sign in to comment.