mirror of
https://github.com/OCA/server-backend.git
synced 2025-02-18 09:52:42 +02:00
[ADD] base_external_system: Implement interface/adapter (#993)
* [ADD] base_external_system: Implement interface/adapter for external systems * base_external_system: Fix OS model, add inherits, add validate * base_external_system: Usability and private key pass * base_external_system: Use contextmanager in adapter client * base_external_system: Move contextmanager to interface * base_external_system: Include contextmanager on adapter and system * base_external_system: Unify client * Use password widget for password field * Add tests & security * Fix lint * Add plaintext note
This commit is contained in:
committed by
ntsirintanis
parent
ea3edcac6f
commit
c6b750c5f7
43
base_external_system/models/external_system_os.py
Normal file
43
base_external_system/models/external_system_os.py
Normal file
@@ -0,0 +1,43 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2017 LasLabs Inc.
|
||||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
|
||||
|
||||
import os
|
||||
|
||||
from odoo import api, models
|
||||
|
||||
|
||||
class ExternalSystemOs(models.Model):
|
||||
"""This is an Interface implementing the OS module.
|
||||
|
||||
For the most part, this is just a sample of how to implement an external
|
||||
system interface. This is still a fully usable implementation, however.
|
||||
"""
|
||||
|
||||
_name = 'external.system.os'
|
||||
_inherit = 'external.system.adapter'
|
||||
_description = 'External System OS'
|
||||
|
||||
previous_dir = None
|
||||
|
||||
@api.multi
|
||||
def external_get_client(self):
|
||||
"""Return a usable client representing the remote system."""
|
||||
super(ExternalSystemOs, self).external_get_client()
|
||||
if self.system_id.remote_path:
|
||||
self.previous_dir = os.getcwd()
|
||||
os.chdir(self.system_id.remote_path)
|
||||
return os
|
||||
|
||||
@api.multi
|
||||
def external_destroy_client(self, client):
|
||||
"""Perform any logic necessary to destroy the client connection.
|
||||
|
||||
Args:
|
||||
client (mixed): The client that was returned by
|
||||
``external_get_client``.
|
||||
"""
|
||||
super(ExternalSystemOs, self).external_destroy_client(client)
|
||||
if self.previous_dir:
|
||||
os.chdir(self.previous_dir)
|
||||
self.previous_dir = None
|
||||
Reference in New Issue
Block a user