1
/*
2
 * Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5
 * the License. A copy of the License is located at
6
 *
7
 *     http://aws.amazon.com/apache2.0/
8
 *
9
 * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10
 * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11
 * and limitations under the License.
12
 */
13 1
import { MqttOverWSProvider } from './MqttOverWSProvider';
14 1
import { Signer, Credentials } from '@aws-amplify/core';
15

16 1
const SERVICE_NAME = 'iotdevicegateway';
17

18 1
export class AWSIoTProvider extends MqttOverWSProvider {
19 1
	protected get region() {
20 1
		return this.options.aws_pubsub_region;
21
	}
22

23 1
	public getProviderName() {
24 1
		return 'AWSIoTProvider';
25
	}
26

27 1
	protected get endpoint() {
28 1
		return (async () => {
29 1
			const endpoint = this.options.aws_pubsub_endpoint;
30

31 1
			const serviceInfo = {
32
				service: SERVICE_NAME,
33
				region: this.region,
34
			};
35 1
			const {
36
				accessKeyId: access_key,
37
				secretAccessKey: secret_key,
38
				sessionToken: session_token,
39 1
			} = await Credentials.get();
40

41 1
			const result = Signer.signUrl(
42
				endpoint,
43
				{ access_key, secret_key, session_token },
44
				serviceInfo
45
			);
46

47 1
			return result;
48
		})();
49
	}
50 1
}

Read our documentation on viewing source code .

Loading