Esempio n. 1
0
class WebDavConnection:
    def __init__(self, host, username, password):
        self.host = host
        self.username = username
        self.password = password

    def connect(self):
        options = {
            'webdav_hostname': self.host,
            'webdav_login': self.username,
            'webdav_password': self.password
        }
        self.connection = WebdavClient(options)

    def get_modified(self, path):
        modified = self.connection.info(path)['modified']
        format = '%a, %d %b %Y %X %Z'
        timestamp_tzaware = parser.parse(modified)
        # fromtimestamp() does not include the timezone.
        # So stripping it here.
        return datetime.datetime.fromtimestamp(timestamp_tzaware.timestamp())

    def download(self, remote_path, local_path):
        self.connection.download_file(remote_path, local_path)

    def upload(self, remote_path, local_path):
        self.connection.upload_file(remote_path, local_path)
Esempio n. 2
0
def certs_from_webdav():
    store_type = os.environ.get("GLUU_DOCUMENT_STORE_TYPE", "LOCAL")
    if store_type != "JCA":
        return

    url = get_jackrabbit_url()

    username = os.environ.get("GLUU_JACKRABBIT_ADMIN_ID", "admin")
    password = ""

    password_file = os.environ.get(
        "GLUU_JACKRABBIT_ADMIN_PASSWORD_FILE",
        "/etc/gluu/conf/jackrabbit_admin_password",
    )
    with contextlib.suppress(FileNotFoundError):
        with open(password_file) as f:
            password = f.read().strip()
    password = password or username

    client = Client({
        "webdav_hostname": url,
        "webdav_login": username,
        "webdav_password": password,
        "webdav_root": "/repository/default",
    })

    certs = [
        "/etc/certs/otp_configuration.json",
        "/etc/certs/super_gluu_creds.json",
    ]
    try:
        for cert in certs:
            client.download_file(cert, cert)
    except (RemoteResourceNotFound, NoConnection):
        pass
Esempio n. 3
0
class WebDev(object):
    def __init__(self, options ):
        # self.client = wc.Client(options)
        self.client = Client(options)


    def read(self, name):
        with BytesIO() as buf:
            self.client.download_from(buf, name)
            return buf.getvalue()


    def write(self,content, target):
        data = self.read(target)

        with BytesIO() as buf:
            buf.write(data)
            buf.write(content.encode())
            self.client.upload_to(buf.getvalue(), target)


    def mkdir(self, dir_name):
        self.client.mkdir(dir_name)


    def list(self):
        data = self.client.list()
        print(data)


    def clear(self, target):
        self.client.clean(target)


    def check(self,remote_path):
        data = self.client.check(remote_path)
        if data:
            print('{} is exists'.format(remote_path))
        else:
            print('{} is not exists'.format(remote_path))


    def upload(self,remote_path, local_path):
        self.client.upload(remote_path, local_path)


    def help_dev(self):
        print(dir(self.client))


    def mkfile(self, remote_path):
        with BytesIO() as buf:
            buf.write(b'')
            self.client.upload_to(buf.getvalue(), remote_path)


    def download_file(self, remote_path):
        self.client.download_file(remote_path, remote_path)


    def rename(self, old_name, new_name):
        self.client.copy(old_name, old_name)
        self.client.clean(old_name)


    def set_property(self,remote_path, option):
        self.client.set_property(remote_path, option=[option])