chenjunkai 5 years ago
parent
commit
36ba184b8d
4 changed files with 65 additions and 6 deletions
  1. 8 0
      Ansjer/test/coposs_sts.py
  2. 42 3
      Ansjer/test/kbt.py
  3. 14 1
      Controller/DetectController.py
  4. 1 2
      Controller/Test.py

+ 8 - 0
Ansjer/test/coposs_sts.py

@@ -1,6 +1,14 @@
 # -*- coding: utf-8 -*-
 '''
 生成sts上传授权
+'''
+'''
+
+
+
+
+tar -cvpzf ubuntu_backup@`date +%Y-%m+%d`.tar.gz --exclude=/proc --exclude=/tmp --exclude=/boot --exclude=/home --exclude=/lost+found --exclude=/media --exclude=/mnt --exclude=/run --exclude=/home/sda1 / --warning=no-file-change
+
 '''
 from aliyunsdkcore import client
 from aliyunsdksts.request.v20150401 import AssumeRoleRequest

+ 42 - 3
Ansjer/test/kbt.py

@@ -1,8 +1,47 @@
-'''
+import boto3
 
+REGION_NAME = 'us-east-1'  # e.g
+import json
 
 
+def generate_sts_boto3():
+    sts = boto3.client(
+        'sts',
+        aws_access_key_id='AKIA2E67UIMD45Y3HL53',
+        aws_secret_access_key='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',
+        region_name=REGION_NAME
+    )
 
-tar -cvpzf ubuntu_backup@`date +%Y-%m+%d`.tar.gz --exclude=/proc --exclude=/tmp --exclude=/boot --exclude=/home --exclude=/lost+found --exclude=/media --exclude=/mnt --exclude=/run --exclude=/home/sda1 / --warning=no-file-change
+    Policy = {"Version": "2012-10-17",
+              "Statement": [{"Effect": "Allow", "Action": "kinesisvideo:*", "Resource": ['*']}]}
+    credentials = sts.get_federation_token(
+        Name='chanjunkai@163.com',  # or any unique text related to user
+        Policy=json.dumps(Policy),
+        DurationSeconds=3600,
+    )
 
-'''
+    print(credentials)
+    access_key_id = credentials['Credentials']['AccessKeyId']
+    session_token = credentials['Credentials']['SessionToken']
+    secret_access_key = credentials['Credentials']['SecretAccessKey']
+    res = {
+        'access_key_id': access_key_id,
+        'secret_access_key': secret_access_key,
+        'session_token': session_token,
+    }
+    print(res)
+
+
+token_dict = {'access_key_id': 'ASIA2E67UIMDVTHGAEEV', 'secret_access_key': 'GncLAqpmcPS+4OjZt+xfg5hZrXDVYDH0jvaulunY',
+              'session_token': 'FwoGZXIvYXdzEBAaDKypPx1gg3gqmDdzfCK+AZ1Z/DS1ZK8jSzrOQnAeB70PnMBK+B7rVPXyiqIilx7gqCAg/xVne9X2bHAItg3b02dGkRrD57CWqHnAeLkpsLMXYxAZsZhgEXW11NmjIAQVc5ZiNyRI8LIvp8s8FrsLLm7zs57TdbPy6i9o1di1silEiwYRQc65iKMOfVH8cOg0iZA0mfDYksuxAmeAo5lQF6JX/7DujtJR/LNzqetv83F400I47vIStBbXtXkqp/qBVMfNIrN9wVA4fmLpvBEop8Gu7gUyKT34Cd4XhwvxdXt4bq8bKm3Bya553WMEsqh0xbG7WJLWP4+8GitU8YWb'}
+
+key = token_dict['access_key_id']
+secret = token_dict['secret_access_key']
+token = token_dict['session_token']
+
+boto3_session = boto3.Session(aws_access_key_id=key, aws_secret_access_key=secret, aws_session_token=token,
+                              region_name='us-east-1')
+
+kv_client = boto3_session.client('kinesisvideo')
+res = kv_client.describe_stream(StreamName='test_stream')
+print(res)

+ 14 - 1
Controller/DetectController.py

@@ -429,13 +429,26 @@ class NotificationView(View):
                 self.do_bulk_create_info(uid_push_qs, n_time, channel, event_type, is_st, uid)
                 if is_st == '0' or is_st == '2':
                     return JsonResponse(status=200, data={'code': 0, 'msg': 'success'})
-                else:
+                elif is_st == '1':
                     # Endpoint以杭州为例,其它Region请按实际情况填写。
                     obj = '{uid}/{channel}/{filename}.jpeg'.format(uid=uid, channel=channel, filename=n_time)
                     # 设置此签名URL在60秒内有效。
                     url = bucket.sign_url('PUT', obj, 7200)
                     res_data = {'code': 0, 'img_push': url, 'msg': 'success'}
                     return JsonResponse(status=200, data=res_data)
+                elif is_st == '3':
+                    # 人形检测带动图
+                    # Endpoint以杭州为例,其它Region请按实际情况填写。
+                    for i in range(int(is_st)-1):
+                        pass
+                    obj = '{uid}/{channel}/{filename}.jpeg'.format(uid=uid, channel=channel, filename=n_time)
+                    # 设置此签名URL在60秒内有效。
+                    url = bucket.sign_url('PUT', obj, 7200)
+                    res_data = {'code': 0, 'img_push': url, 'msg': 'success'}
+                    res_data = {
+
+                    }
+                    return JsonResponse(status=200, data=res_data)
             else:
                 return JsonResponse(status=200, data={'code': 404, 'msg': 'data is not exist'})
         else:

+ 1 - 2
Controller/Test.py

@@ -57,8 +57,7 @@ class Test(View):
         )
 
         Policy = {"Version": "2012-10-17",
-                  "Statement": [{"Effect": "Allow", "Action": "kinesisvideo:*", "Resource": [
-                      "arn:aws:kinesisvideo:us-east-1:697864307463:stream/wpy_stream/1573460250304"]}]}
+                  "Statement": [{"Effect": "Allow", "Action": "kinesisvideo:*", "Resource": ["*"]}]}
         credentials = sts.get_federation_token(
             Name='chanjunkai@163.com',  # or any unique text related to user
             Policy=json.dumps(Policy),