|
@@ -0,0 +1,102 @@
|
|
|
+#!/usr/bin/env python3
|
|
|
+# -*- coding: utf-8 -*-
|
|
|
+from abc import ABCMeta,abstractmethod
|
|
|
+
|
|
|
+import boto3
|
|
|
+
|
|
|
+from Ansjer.config import AWS_IOT_SES_ACCESS_CHINA_REGION, AWS_IOT_SES_ACCESS_CHINA_ID, AWS_IOT_SES_ACCESS_CHINA_SECRET, \
|
|
|
+ AWS_IOT_SES_ACCESS_FOREIGN_REGION_AMERICA, AWS_IOT_SES_ACCESS_FOREIGN_ID, AWS_IOT_SES_ACCESS_FOREIGN_SECRET, \
|
|
|
+ AWS_IOT_SES_ACCESS_FOREIGN_REGION_EUROPE, AWS_IOT_SES_ACCESS_FOREIGN_REGION_ASIA
|
|
|
+
|
|
|
+
|
|
|
+class IOTObject(metaclass=ABCMeta):
|
|
|
+
|
|
|
+ @abstractmethod
|
|
|
+ def create_provisioning_claim(self, templateName):
|
|
|
+ pass
|
|
|
+
|
|
|
+
|
|
|
+class ChinaIOTClient(IOTObject):
|
|
|
+
|
|
|
+ def __init__(self):
|
|
|
+ self.client = boto3.client('iot', region_name=AWS_IOT_SES_ACCESS_CHINA_REGION,
|
|
|
+ aws_access_key_id=AWS_IOT_SES_ACCESS_CHINA_ID,
|
|
|
+ aws_secret_access_key=AWS_IOT_SES_ACCESS_CHINA_SECRET)
|
|
|
+
|
|
|
+ def create_provisioning_claim(self, templateName):
|
|
|
+
|
|
|
+ result = self.client.create_provisioning_claim(templateName=templateName)
|
|
|
+
|
|
|
+ res = {
|
|
|
+ 'certificateId': result['certificateId'],
|
|
|
+ 'certificatePem': result['certificatePem'],
|
|
|
+ 'publicKey': result['keyPair']['PublicKey'],
|
|
|
+ 'privateKey': result['keyPair']['PrivateKey'],
|
|
|
+ 'endpoint': 'a250bbr0p9u7as-ats.iot.cn-northwest-1.amazonaws.com.cn'
|
|
|
+ }
|
|
|
+
|
|
|
+ return res
|
|
|
+
|
|
|
+
|
|
|
+class AmericaIOTClient(IOTObject):
|
|
|
+
|
|
|
+ def __init__(self):
|
|
|
+ self.client = boto3.client('iot', region_name=AWS_IOT_SES_ACCESS_FOREIGN_REGION_AMERICA,
|
|
|
+ aws_access_key_id=AWS_IOT_SES_ACCESS_FOREIGN_ID,
|
|
|
+ aws_secret_access_key=AWS_IOT_SES_ACCESS_FOREIGN_SECRET)
|
|
|
+
|
|
|
+ def create_provisioning_claim(self, templateName):
|
|
|
+
|
|
|
+ result = self.client.create_provisioning_claim(templateName=templateName)
|
|
|
+
|
|
|
+ res = {
|
|
|
+ 'certificateId': result['certificateId'],
|
|
|
+ 'certificatePem': result['certificatePem'],
|
|
|
+ 'publicKey': result['keyPair']['PublicKey'],
|
|
|
+ 'privateKey': result['keyPair']['PrivateKey'],
|
|
|
+ 'endpoint': 'a2rqy12o004ad8-ats.iot.us-east-1.amazonaws.com'
|
|
|
+ }
|
|
|
+
|
|
|
+ return res
|
|
|
+
|
|
|
+
|
|
|
+class AsiaIOTClient(IOTObject):
|
|
|
+
|
|
|
+ def __init__(self):
|
|
|
+ self.client = boto3.client('iot', region_name=AWS_IOT_SES_ACCESS_FOREIGN_REGION_ASIA,
|
|
|
+ aws_access_key_id=AWS_IOT_SES_ACCESS_FOREIGN_ID,
|
|
|
+ aws_secret_access_key=AWS_IOT_SES_ACCESS_FOREIGN_SECRET)
|
|
|
+
|
|
|
+ def create_provisioning_claim(self, templateName):
|
|
|
+ result = self.client.create_provisioning_claim(templateName=templateName)
|
|
|
+
|
|
|
+ res = {
|
|
|
+ 'certificateId': result['certificateId'],
|
|
|
+ 'certificatePem': result['certificatePem'],
|
|
|
+ 'publicKey': result['keyPair']['PublicKey'],
|
|
|
+ 'privateKey': result['keyPair']['PrivateKey'],
|
|
|
+ 'endpoint': 'a2rqy12o004ad8-ats.iot.ap-southeast-1.amazonaws.com'
|
|
|
+ }
|
|
|
+
|
|
|
+ return res
|
|
|
+
|
|
|
+
|
|
|
+class EuropeIOTClient(IOTObject):
|
|
|
+
|
|
|
+ def __init__(self):
|
|
|
+ self.client = boto3.client('iot', region_name=AWS_IOT_SES_ACCESS_FOREIGN_REGION_EUROPE,
|
|
|
+ aws_access_key_id=AWS_IOT_SES_ACCESS_FOREIGN_ID,
|
|
|
+ aws_secret_access_key=AWS_IOT_SES_ACCESS_FOREIGN_SECRET)
|
|
|
+
|
|
|
+ def create_provisioning_claim(self, templateName):
|
|
|
+ result = self.client.create_provisioning_claim(templateName=templateName)
|
|
|
+
|
|
|
+ res = {
|
|
|
+ 'certificateId': result['certificateId'],
|
|
|
+ 'certificatePem': result['certificatePem'],
|
|
|
+ 'publicKey': result['keyPair']['PublicKey'],
|
|
|
+ 'privateKey': result['keyPair']['PrivateKey'],
|
|
|
+ 'endpoint': 'a2rqy12o004ad8-ats.iot.eu-west-1.amazonaws.com'
|
|
|
+ }
|
|
|
+
|
|
|
+ return res
|