# Buggy code
def init_api_resources(api):
    api.add_resource(Root, "/api")
    api.add_resource(Monkey, "/api/monkey", "/api/monkey/", "/api/monkey/<string:guid>")
    api.add_resource(LocalRun, "/api/local-monkey", "/api/local-monkey/")
    api.add_resource(ClientRun, "/api/client-monkey", "/api/client-monkey/")
    api.add_resource(
        Telemetry,
        "/api/telemetry",
        "/api/telemetry/",
        "/api/telemetry/<string:monkey_guid>",
    )
    api.add_resource(MonkeyConfiguration, "/api/configuration", "/api/configuration/")
    api.add_resource(
        IslandConfiguration, "/api/configuration/island", "/api/configuration/island/"
    )
    api.add_resource(
        MonkeyDownload,
        "/api/monkey/download",
        "/api/monkey/download/",
        "/api/monkey/download/<string:path>",
    )
    api.add_resource(NetMap, "/api/netmap", "/api/netmap/")
    api.add_resource(Edge, "/api/netmap/edge", "/api/netmap/edge/")
    api.add_resource(Node, "/api/netmap/node", "/api/netmap/node/")

    # report_type: zero_trust or security
    api.add_resource(
        Report,
        "/api/report/<string:report_type>",
        "/api/report/<string:report_type>/<string:report_data>",
    )

    api.add_resource(TelemetryFeed, "/api/telemetry-feed", "/api/telemetry-feed/")
    api.add_resource(Log, "/api/log", "/api/log/")
    api.add_resource(IslandLog, "/api/log/island/download", "/api/log/island/download/")
    api.add_resource(PBAFileDownload, "/api/pba/download/<string:path>")
    api.add_resource(
        FileUpload,
        "/api/fileUpload/<string:file_type>",
        "/api/fileUpload/<string:file_type>?load=<string:filename>",
        "/api/fileUpload/<string:file_type>?restore=<string:filename>",
    )
    api.add_resource(RemoteRun, "/api/remote-monkey", "/api/remote-monkey/")
    api.add_resource(AttackConfiguration, "/api/attack")
    api.add_resource(AttackReport, "/api/attack/report")
    api.add_resource(VersionUpdate, "/api/version-update", "/api/version-update/")

    api.add_resource(MonkeyTest, "/api/test/monkey")
    api.add_resource(ClearCaches, "/api/test/clear_caches")
    api.add_resource(LogTest, "/api/test/log")


# Traceback (OSError)
2020-01-17 10:14:45,982 - iostream.py:1518 - _do_ssl_handshake() - WARNING - SSL Error on 1504 ('1.1.1.2', 4469): [SSL: NO_SHARED_CIPHER] no shared cipher (_ssl.c:1076)
2020-01-17 10:14:46,055 - iostream.py:1518 - _do_ssl_handshake() - WARNING - SSL Error on 1500 ('1.1.1.2', 4470): [SSL: VERSION_TOO_LOW] version too low (_ssl.c:1076)
2020-01-17 10:14:46,136 - iostream.py:744 - _handle_events() - ERROR - Uncaught exception, closing connection.
Traceback (most recent call last):
File "C:\Users\Vakaris\AppData\Local\Programs\Python\Python37\lib\site-packages\tornado\iostream.py", line 709, in _handle_events
self._handle_read()
File "C:\Users\Vakaris\AppData\Local\Programs\Python\Python37\lib\site-packages\tornado\iostream.py", line 1581, in _handle_read
self._do_ssl_handshake()
File "C:\Users\Vakaris\AppData\Local\Programs\Python\Python37\lib\site-packages\tornado\iostream.py", line 1501, in _do_ssl_handshake
self.socket.do_handshake()
File "C:\Users\Vakaris\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 1139, in do_handshake
self._sslobj.do_handshake()
OSError: [Errno 0] Error
2020-01-17 10:14:46,163 - base_events.py:1604 - default_exception_handler() - ERROR - Exception in callback None()
handle: <Handle cancelled>
Traceback (most recent call last):
File "C:\Users\Vakaris\AppData\Local\Programs\Python\Python37\lib\asyncio\events.py", line 88, in _run
self._context.run(self._callback, *self._args)
File "C:\Users\Vakaris\AppData\Local\Programs\Python\Python37\lib\site-packages\tornado\platform\asyncio.py", line 122, in _handle_events
handler_func(fileobj, events)
File "C:\Users\Vakaris\AppData\Local\Programs\Python\Python37\lib\site-packages\tornado\stack_context.py", line 300, in null_wrapper
return fn(*args, **kwargs)
File "C:\Users\Vakaris\AppData\Local\Programs\Python\Python37\lib\site-packages\tornado\iostream.py", line 709, in _handle_events
self._handle_read()
File "C:\Users\Vakaris\AppData\Local\Programs\Python\Python37\lib\site-packages\tornado\iostream.py", line 1581, in _handle_read
self._do_ssl_handshake()
File "C:\Users\Vakaris\AppData\Local\Programs\Python\Python37\lib\site-packages\tornado\iostream.py", line 1501, in _do_ssl_handshake
self.socket.do_handshake()
File "C:\Users\Vakaris\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 1139, in do_handshake
self._sslobj.do_handshake()
OSError: [Errno 0] Error

# Fixed code
def init_api_resources(api):
    api.add_resource(Root, "/api")
    api.add_resource(Monkey, "/api/monkey", "/api/monkey/", "/api/monkey/<string:guid>")
    api.add_resource(Bootloader, "/api/bootloader/<string:os>")
    api.add_resource(LocalRun, "/api/local-monkey", "/api/local-monkey/")
    api.add_resource(ClientRun, "/api/client-monkey", "/api/client-monkey/")
    api.add_resource(
        Telemetry,
        "/api/telemetry",
        "/api/telemetry/",
        "/api/telemetry/<string:monkey_guid>",
    )
    api.add_resource(MonkeyConfiguration, "/api/configuration", "/api/configuration/")
    api.add_resource(
        IslandConfiguration, "/api/configuration/island", "/api/configuration/island/"
    )
    api.add_resource(
        MonkeyDownload,
        "/api/monkey/download",
        "/api/monkey/download/",
        "/api/monkey/download/<string:path>",
    )
    api.add_resource(NetMap, "/api/netmap", "/api/netmap/")
    api.add_resource(Edge, "/api/netmap/edge", "/api/netmap/edge/")
    api.add_resource(Node, "/api/netmap/node", "/api/netmap/node/")
    api.add_resource(NodeStates, "/api/netmap/nodeStates")

    # report_type: zero_trust or security
    api.add_resource(
        Report,
        "/api/report/<string:report_type>",
        "/api/report/<string:report_type>/<string:report_data>",
    )

    api.add_resource(TelemetryFeed, "/api/telemetry-feed", "/api/telemetry-feed/")
    api.add_resource(Log, "/api/log", "/api/log/")
    api.add_resource(IslandLog, "/api/log/island/download", "/api/log/island/download/")
    api.add_resource(PBAFileDownload, "/api/pba/download/<string:path>")
    api.add_resource(
        FileUpload,
        "/api/fileUpload/<string:file_type>",
        "/api/fileUpload/<string:file_type>?load=<string:filename>",
        "/api/fileUpload/<string:file_type>?restore=<string:filename>",
    )
    api.add_resource(RemoteRun, "/api/remote-monkey", "/api/remote-monkey/")
    api.add_resource(AttackConfiguration, "/api/attack")
    api.add_resource(AttackReport, "/api/attack/report")
    api.add_resource(VersionUpdate, "/api/version-update", "/api/version-update/")

    api.add_resource(MonkeyTest, "/api/test/monkey")
    api.add_resource(ClearCaches, "/api/test/clear_caches")
    api.add_resource(LogTest, "/api/test/log")