Browse Source

返回iot_credential_provider_endpoint

locky 1 month ago
parent
commit
1c6388f818
2 changed files with 22 additions and 2 deletions
  1. 12 2
      Controller/AWS/KVSController.py
  2. 10 0
      Object/IOTCore/IotObject.py

+ 12 - 2
Controller/AWS/KVSController.py

@@ -19,9 +19,10 @@ from django.views import View
 
 from Model.models import KVS, Device_User, Device_Info
 from Object.AWS.AmazonKinesisVideoUtil import AmazonKinesisVideoObject, AmazonKVAMObject
+from Object.IOTCore.IotObject import IOTClient
 from Object.RedisObject import RedisObject
 from Object.ResponseObject import ResponseObject
-from Ansjer.config import ACCESS_KEY_ID, SECRET_ACCESS_KEY, SERVER_DOMAIN, LOGGER, KVS_REGION
+from Ansjer.config import ACCESS_KEY_ID, SECRET_ACCESS_KEY, SERVER_DOMAIN, LOGGER, KVS_REGION, REGION_ID_LIST
 from Object.TokenObject import TokenObject
 from botocore.auth import SigV4Auth
 from botocore.awsrequest import AWSRequest
@@ -534,10 +535,19 @@ class KVSView(View):
         if not all([serial]):
             return response.json(444)
         try:
+            # 获取并判断region_id是否有效
+            region_id = CommonService.confirm_region_id()
+            if region_id not in REGION_ID_LIST:
+                return response.json(444, {'invalid region_id': region_id})
+            # 获取iot:CredentialProvider
+            endpoint_type = 'iot:CredentialProvider'
+            iot_client = IOTClient(region_id)
+            iot_credential_provider_endpoint = iot_client.describe_iot_endpoint(endpoint_type)
             # 已有数据直接返回
             res = {
                 'region': KVS_REGION,
-                'role_alias': 'KvsCameraIoTRoleAlias'
+                'role_alias': 'KvsCameraIoTRoleAlias',
+                'iot_credential_provider_endpoint': iot_credential_provider_endpoint,
             }
             kvs = KVS.objects.filter(channel_name=serial)
             if kvs.exists():

+ 10 - 0
Object/IOTCore/IotObject.py

@@ -141,3 +141,13 @@ class IOTClient:
         except Exception as e:
             print(e)
             return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
+
+    def describe_iot_endpoint(self, endpoint_type):
+        """
+        获取iot endpoint
+        https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/iot/client/describe_endpoint.html#
+        @param endpoint_type: endpoint类型
+        @return:
+        """
+        res = self.client.describe_endpoint(endpointType=endpoint_type)
+        return res['endpointAddress']