Skip to content

Commit

Permalink
feat(client-iot): AWS IoT - AWS IoT Device Defender adds support to l…
Browse files Browse the repository at this point in the history
…ist metric datapoints collected for IoT devices through the ListMetricValues API
  • Loading branch information
awstools committed Apr 4, 2022
1 parent 8d798a8 commit 0964244
Show file tree
Hide file tree
Showing 12 changed files with 626 additions and 68 deletions.
38 changes: 38 additions & 0 deletions clients/client-iot/src/IoT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,11 @@ import {
ListManagedJobTemplatesCommandInput,
ListManagedJobTemplatesCommandOutput,
} from "./commands/ListManagedJobTemplatesCommand";
import {
ListMetricValuesCommand,
ListMetricValuesCommandInput,
ListMetricValuesCommandOutput,
} from "./commands/ListMetricValuesCommand";
import {
ListMitigationActionsCommand,
ListMitigationActionsCommandInput,
Expand Down Expand Up @@ -6385,6 +6390,39 @@ export class IoT extends IoTClient {
}
}

/**
* <p>Lists the values reported for an IoT Device Defender metric (device-side metric, cloud-side metric, or custom metric)
* by the given thing during the specified time period.</p>
*/
public listMetricValues(
args: ListMetricValuesCommandInput,
options?: __HttpHandlerOptions
): Promise<ListMetricValuesCommandOutput>;
public listMetricValues(
args: ListMetricValuesCommandInput,
cb: (err: any, data?: ListMetricValuesCommandOutput) => void
): void;
public listMetricValues(
args: ListMetricValuesCommandInput,
options: __HttpHandlerOptions,
cb: (err: any, data?: ListMetricValuesCommandOutput) => void
): void;
public listMetricValues(
args: ListMetricValuesCommandInput,
optionsOrCb?: __HttpHandlerOptions | ((err: any, data?: ListMetricValuesCommandOutput) => void),
cb?: (err: any, data?: ListMetricValuesCommandOutput) => void
): Promise<ListMetricValuesCommandOutput> | void {
const command = new ListMetricValuesCommand(args);
if (typeof optionsOrCb === "function") {
this.send(command, optionsOrCb);
} else if (typeof cb === "function") {
if (typeof optionsOrCb !== "object") throw new Error(`Expect http options but get ${typeof optionsOrCb}`);
this.send(command, optionsOrCb || {}, cb);
} else {
return this.send(command, optionsOrCb);
}
}

/**
* <p>Gets a list of all mitigation actions that match the specified filter criteria.</p>
* <p>Requires permission to access the <a href="https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsiot.html#awsiot-actions-as-permissions">ListMitigationActions</a> action.</p>
Expand Down
3 changes: 3 additions & 0 deletions clients/client-iot/src/IoTClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ import {
ListManagedJobTemplatesCommandInput,
ListManagedJobTemplatesCommandOutput,
} from "./commands/ListManagedJobTemplatesCommand";
import { ListMetricValuesCommandInput, ListMetricValuesCommandOutput } from "./commands/ListMetricValuesCommand";
import {
ListMitigationActionsCommandInput,
ListMitigationActionsCommandOutput,
Expand Down Expand Up @@ -859,6 +860,7 @@ export type ServiceInputTypes =
| ListJobTemplatesCommandInput
| ListJobsCommandInput
| ListManagedJobTemplatesCommandInput
| ListMetricValuesCommandInput
| ListMitigationActionsCommandInput
| ListOTAUpdatesCommandInput
| ListOutgoingCertificatesCommandInput
Expand Down Expand Up @@ -1097,6 +1099,7 @@ export type ServiceOutputTypes =
| ListJobTemplatesCommandOutput
| ListJobsCommandOutput
| ListManagedJobTemplatesCommandOutput
| ListMetricValuesCommandOutput
| ListMitigationActionsCommandOutput
| ListOTAUpdatesCommandOutput
| ListOutgoingCertificatesCommandOutput
Expand Down
96 changes: 96 additions & 0 deletions clients/client-iot/src/commands/ListMetricValuesCommand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { getSerdePlugin } from "@aws-sdk/middleware-serde";
import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@aws-sdk/protocol-http";
import { Command as $Command } from "@aws-sdk/smithy-client";
import {
FinalizeHandlerArguments,
Handler,
HandlerExecutionContext,
HttpHandlerOptions as __HttpHandlerOptions,
MetadataBearer as __MetadataBearer,
MiddlewareStack,
SerdeContext as __SerdeContext,
} from "@aws-sdk/types";

import { IoTClientResolvedConfig, ServiceInputTypes, ServiceOutputTypes } from "../IoTClient";
import { ListMetricValuesRequest, ListMetricValuesResponse } from "../models/models_1";
import {
deserializeAws_restJson1ListMetricValuesCommand,
serializeAws_restJson1ListMetricValuesCommand,
} from "../protocols/Aws_restJson1";

export interface ListMetricValuesCommandInput extends ListMetricValuesRequest {}
export interface ListMetricValuesCommandOutput extends ListMetricValuesResponse, __MetadataBearer {}

/**
* <p>Lists the values reported for an IoT Device Defender metric (device-side metric, cloud-side metric, or custom metric)
* by the given thing during the specified time period.</p>
* @example
* Use a bare-bones client and the command you need to make an API call.
* ```javascript
* import { IoTClient, ListMetricValuesCommand } from "@aws-sdk/client-iot"; // ES Modules import
* // const { IoTClient, ListMetricValuesCommand } = require("@aws-sdk/client-iot"); // CommonJS import
* const client = new IoTClient(config);
* const command = new ListMetricValuesCommand(input);
* const response = await client.send(command);
* ```
*
* @see {@link ListMetricValuesCommandInput} for command's `input` shape.
* @see {@link ListMetricValuesCommandOutput} for command's `response` shape.
* @see {@link IoTClientResolvedConfig | config} for IoTClient's `config` shape.
*
*/
export class ListMetricValuesCommand extends $Command<
ListMetricValuesCommandInput,
ListMetricValuesCommandOutput,
IoTClientResolvedConfig
> {
// Start section: command_properties
// End section: command_properties

constructor(readonly input: ListMetricValuesCommandInput) {
// Start section: command_constructor
super();
// End section: command_constructor
}

/**
* @internal
*/
resolveMiddleware(
clientStack: MiddlewareStack<ServiceInputTypes, ServiceOutputTypes>,
configuration: IoTClientResolvedConfig,
options?: __HttpHandlerOptions
): Handler<ListMetricValuesCommandInput, ListMetricValuesCommandOutput> {
this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize));

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

const { logger } = configuration;
const clientName = "IoTClient";
const commandName = "ListMetricValuesCommand";
const handlerExecutionContext: HandlerExecutionContext = {
logger,
clientName,
commandName,
inputFilterSensitiveLog: ListMetricValuesRequest.filterSensitiveLog,
outputFilterSensitiveLog: ListMetricValuesResponse.filterSensitiveLog,
};
const { requestHandler } = configuration;
return stack.resolve(
(request: FinalizeHandlerArguments<any>) =>
requestHandler.handle(request.request as __HttpRequest, options || {}),
handlerExecutionContext
);
}

private serialize(input: ListMetricValuesCommandInput, context: __SerdeContext): Promise<__HttpRequest> {
return serializeAws_restJson1ListMetricValuesCommand(input, context);
}

private deserialize(output: __HttpResponse, context: __SerdeContext): Promise<ListMetricValuesCommandOutput> {
return deserializeAws_restJson1ListMetricValuesCommand(output, context);
}

// Start section: command_body_extra
// End section: command_body_extra
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from "@aws-sdk/types";

import { IoTClientResolvedConfig, ServiceInputTypes, ServiceOutputTypes } from "../IoTClient";
import { ListThingPrincipalsRequest, ListThingPrincipalsResponse } from "../models/models_1";
import { ListThingPrincipalsRequest, ListThingPrincipalsResponse } from "../models/models_2";
import {
deserializeAws_restJson1ListThingPrincipalsCommand,
serializeAws_restJson1ListThingPrincipalsCommand,
Expand Down
1 change: 1 addition & 0 deletions clients/client-iot/src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ export * from "./ListJobExecutionsForThingCommand";
export * from "./ListJobTemplatesCommand";
export * from "./ListJobsCommand";
export * from "./ListManagedJobTemplatesCommand";
export * from "./ListMetricValuesCommand";
export * from "./ListMitigationActionsCommand";
export * from "./ListOTAUpdatesCommand";
export * from "./ListOutgoingCertificatesCommand";
Expand Down
4 changes: 2 additions & 2 deletions clients/client-iot/src/models/models_0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5505,12 +5505,12 @@ export interface CustomCodeSigning {
certificateChain?: CodeSigningCertificateChain;

/**
* <p>The hash algorithm used to code sign the file. You can use a string as the algorithm name if the target over-the-air (OTA) update devices are able to verify the signature that was generated using the same signature algorithm. For example, FreeRTOS uses <code>SHA256</code> or <code>SHA1</code>, so you can pass either of them based on which was used for generating the signature.</p>
* <p>The hash algorithm used to code sign the file.</p>
*/
hashAlgorithm?: string;

/**
* <p>The signature algorithm used to code sign the file. You can use a string as the algorithm name if the target over-the-air (OTA) update devices are able to verify the signature that was generated using the same signature algorithm. For example, FreeRTOS uses <code>ECDSA</code> or <code>RSA</code>, so you can pass either of them based on which was used for generating the signature.</p>
* <p>The signature algorithm used to code sign the file.</p>
*/
signatureAlgorithm?: string;
}
Expand Down
159 changes: 99 additions & 60 deletions clients/client-iot/src/models/models_1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ import {
CustomMetricType,
DayOfWeek,
DimensionType,
DimensionValueOperator,
FleetMetricUnit,
JobExecutionsRetryConfig,
JobExecutionsRolloutConfig,
LogLevel,
MetricToRetain,
MetricValue,
MitigationActionParams,
OTAUpdateFile,
OTAUpdateStatus,
Expand Down Expand Up @@ -6895,6 +6897,103 @@ export namespace ListManagedJobTemplatesResponse {
});
}

export interface ListMetricValuesRequest {
/**
* <p>The name of the thing for which security profile metric values are returned.</p>
*/
thingName: string | undefined;

/**
* <p>The name of the security profile metric for which values are returned.</p>
*/
metricName: string | undefined;

/**
* <p>The dimension name.</p>
*/
dimensionName?: string;

/**
* <p>The dimension value operator.</p>
*/
dimensionValueOperator?: DimensionValueOperator | string;

/**
* <p>The start of the time period for which metric values are returned.</p>
*/
startTime: Date | undefined;

/**
* <p>The end of the time period for which metric values are returned.</p>
*/
endTime: Date | undefined;

/**
* <p>The maximum number of results to return at one time.</p>
*/
maxResults?: number;

/**
* <p>The token for the next set of results.</p>
*/
nextToken?: string;
}

export namespace ListMetricValuesRequest {
/**
* @internal
*/
export const filterSensitiveLog = (obj: ListMetricValuesRequest): any => ({
...obj,
});
}

/**
* <p>A metric.</p>
*/
export interface MetricDatum {
/**
* <p>The time the metric value was reported.</p>
*/
timestamp?: Date;

/**
* <p>The value reported for the metric.</p>
*/
value?: MetricValue;
}

export namespace MetricDatum {
/**
* @internal
*/
export const filterSensitiveLog = (obj: MetricDatum): any => ({
...obj,
});
}

export interface ListMetricValuesResponse {
/**
* <p>The data the thing reports for the metric during the specified time period.</p>
*/
metricDatumList?: MetricDatum[];

/**
* <p>A token that can be used to retrieve the next set of results, or <code>null</code>
* if there are no additional results.</p>
*/
nextToken?: string;
}

export namespace ListMetricValuesResponse {
/**
* @internal
*/
export const filterSensitiveLog = (obj: ListMetricValuesResponse): any => ({
...obj,
});
}

export interface ListMitigationActionsRequest {
/**
* <p>Specify a value to limit the result to mitigation actions with a specific action type.</p>
Expand Down Expand Up @@ -8242,63 +8341,3 @@ export namespace ListThingGroupsForThingResponse {
...obj,
});
}

/**
* <p>The input for the ListThingPrincipal operation.</p>
*/
export interface ListThingPrincipalsRequest {
/**
* <p>To retrieve the next set of results, the <code>nextToken</code>
* value from a previous response; otherwise <b>null</b> to receive
* the first set of results.</p>
*/
nextToken?: string;

/**
* <p>The maximum number of results to return in this operation.</p>
*/
maxResults?: number;

/**
* <p>The name of the thing.</p>
*/
thingName: string | undefined;
}

export namespace ListThingPrincipalsRequest {
/**
* @internal
*/
export const filterSensitiveLog = (obj: ListThingPrincipalsRequest): any => ({
...obj,
});
}

/**
* <p>The output from the ListThingPrincipals operation.</p>
*/
export interface ListThingPrincipalsResponse {
/**
* <p>The principals associated with the thing.</p>
*/
principals?: string[];

/**
* <p>The token to use to get the next set of results, or <b>null</b> if there are no additional results.</p>
*/
nextToken?: string;
}

export namespace ListThingPrincipalsResponse {
/**
* @internal
*/
export const filterSensitiveLog = (obj: ListThingPrincipalsResponse): any => ({
...obj,
});
}

export enum ReportType {
ERRORS = "ERRORS",
RESULTS = "RESULTS",
}
Loading

0 comments on commit 0964244

Please sign in to comment.