fetch_mapping_file.py 2.07 KB
Newer Older
Matthias's avatar
Matthias committed
1
2
from flask_restful import Resource, current_app

Jonas Waeber's avatar
Jonas Waeber committed
3
from import_api_app.helpers.mapping import MappingFileHandler
Matthias's avatar
Matthias committed
4
5
6
7


class FetchMappingFile(Resource):

Jonas Waeber's avatar
Jonas Waeber committed
8
9
10
11
12
13
    def __init__(self):
        self.host = current_app.config["sftp_host"]
        self.port = current_app.config["sftp_port"]
        self.user = current_app.config["sftp_user"]
        self.password = current_app.config["sftp_password"]
        self.base_path = current_app.config['sftp_base_path']
Jonas Waeber's avatar
Jonas Waeber committed
14
        self.topic = current_app.config['topic-configs']
Jonas Waeber's avatar
Jonas Waeber committed
15
16
17
18
19
20
21
22
23
24
25
26
27
        self.kafka_broker_url = current_app.config['kafka-broker-url']

        self.mapping_file_handler = MappingFileHandler(
            self.host,
            self.port,
            self.user,
            self.password,
            self.base_path,
            self.kafka_broker_url,
            self.topic,
            current_app.logger
        )

Jonas Waeber's avatar
Jonas Waeber committed
28
    def get(self, recordset_id, session_id):
Matthias's avatar
Matthias committed
29
30
31
32
33
34
35
36
37
38
39
40
        """
        Fetches the mapping file form the sftp-server
        ---
        tags:
          - fetch mapping file
        parameters:
          - in: path
            name: recordset_id
            required: true
            description: The name of the record set (matches folder name on sftp)
            example: AfZ-Becker-Audiovisuals
            type: string
Jonas Waeber's avatar
Jonas Waeber committed
41
          - in: path
Jonas Waeber's avatar
Jonas Waeber committed
42
            name: session_id
Jonas Waeber's avatar
Jonas Waeber committed
43
44
45
46
            required: true
            description: A session id used to distinguish between different runs.
            example: uuid
            type: string
Matthias's avatar
Matthias committed
47
48
49
50
51
52
53
54
55
56
57
58
59
60
        responses:
          200:
            description: Success, the mapping file has been retrieved
            schema:
              properties:
                status:
                  type: string
                  example: SUCCESS/FAILURE
                  enum: ['SUCCESS', 'FAILURE']
                contents:
                  type: string/yml
                  example: the contents of the mapping file...

        """
Jonas Waeber's avatar
Jonas Waeber committed
61
62
63
64
65
        result = self.mapping_file_handler.process_mapping_files(recordset_id)
        if result['status'] == 'SUCCESS':
            return result, 200
        else:
            return result, 500