|
| 1 | +import logging |
| 2 | + |
1 | 3 | import cterasdk.settings |
2 | 4 | from ...clients import clients |
3 | 5 | from ..services import Management |
4 | 6 | from ..endpoints import EndpointBuilder |
5 | 7 | from .. import authenticators |
6 | | -from ...common import modules |
| 8 | +from ...common import modules, parse_base_object_ref |
7 | 9 | from ...lib.session.edge import Session |
8 | 10 |
|
9 | 11 |
|
10 | 12 | from ...edge import ( |
11 | 13 | afp, aio, antivirus, array, audit, backup, cache, cli, config, connection, ctera_migrate, |
12 | 14 | dedup, directoryservice, drive, files, firmware, ftp, groups, licenses, login, |
13 | 15 | logs, mail, network, nfs, ntp, power, remote, rsync, ransom_protect, services, |
14 | | - shares, shell, smb, snmp, ssh, ssl, support, sync, syslog, tasks, telnet, |
| 16 | + shares, shell, smb, snmp, ssh, ssl, stats, support, sync, syslog, tasks, telnet, |
15 | 17 | timezone, users, volumes, |
16 | 18 | ) |
17 | 19 |
|
18 | 20 |
|
| 21 | +logger = logging.getLogger('cterasdk.edge') |
| 22 | + |
| 23 | + |
19 | 24 | class Clients: |
20 | 25 |
|
21 | 26 | def __init__(self, edge, Portal): |
| 27 | + self._edge = edge |
| 28 | + self._Portal = Portal |
| 29 | + self._authenticated = False |
22 | 30 | if Portal: |
23 | 31 | edge._Portal = Portal |
24 | 32 | edge.default.close() |
25 | 33 | edge._ctera_session.start_remote_session(Portal.session()) |
26 | | - self.api = Portal.default.clone(clients.API, EndpointBuilder.new(edge.base), authenticator=lambda *_: True) |
| 34 | + self._api = Portal.default.clone(clients.API, EndpointBuilder.new(edge.base, '/admingui/api'), authenticator=lambda *_: True) |
27 | 35 | else: |
28 | 36 | self.migrate = edge.default.clone(clients.Migrate, EndpointBuilder.new(edge.base, '/migration/rest/v1')) |
29 | | - self.api = edge.default.clone(clients.API, EndpointBuilder.new(edge.base, '/admingui/api')) |
| 37 | + self._api = edge.default.clone(clients.API, EndpointBuilder.new(edge.base, '/admingui/api')) |
30 | 38 | self.io = IO(edge) |
31 | 39 |
|
| 40 | + @property |
| 41 | + def api(self): |
| 42 | + if self._Portal and not self._authenticated: |
| 43 | + tenant = parse_base_object_ref(self._edge.portal).name |
| 44 | + device_name = self._edge.name |
| 45 | + logger.debug('Auto-SSO login via relay channel. %s', {'tenant': tenant, 'device': device_name}) |
| 46 | + token = self._Portal.api.execute(f'/portals/{tenant}/devices/{device_name}', 'singleSignOn') |
| 47 | + if token: |
| 48 | + self._api.get('/ssologin', params={'ticket': token}) |
| 49 | + self._authenticated = True |
| 50 | + return self._api |
| 51 | + |
32 | 52 |
|
33 | 53 | class IO: |
34 | 54 |
|
@@ -106,6 +126,7 @@ def __init__(self, host=None, port=None, https=True, Portal=None, *, base=None): |
106 | 126 | self.shell = shell.Shell(self) |
107 | 127 | self.smb = smb.SMB(self) |
108 | 128 | self.snmp = snmp.SNMP(self) |
| 129 | + self.stats = stats.Stats(self) |
109 | 130 | self.ssh = ssh.SSH(self) |
110 | 131 | self.ssl = modules.initialize(ssl.SSLModule, self) |
111 | 132 | self.support = support.Support(self) |
@@ -164,5 +185,5 @@ def _omit_fields(self): |
164 | 185 | return super()._omit_fields + ['afp', 'aio', 'array', 'audit', 'antivirus', 'backup', 'cache', 'cli', 'config', 'ctera_migrate', |
165 | 186 | 'dedup', 'directoryservice', 'drive', 'files', 'firmware', 'ftp', 'groups', 'licenses', 'logs', |
166 | 187 | 'mail', 'network', 'nfs', 'ntp', 'power', 'ransom_protect', 'rsync', 'services', 'shares', 'shell', |
167 | | - 'smb', 'snmp', 'ssh', 'ssl', 'support', 'sync', 'syslog', 'tasks', 'telnet', 'timezone', |
| 188 | + 'smb', 'snmp', 'ssh', 'ssl', 'stats', 'support', 'sync', 'syslog', 'tasks', 'telnet', 'timezone', |
168 | 189 | 'users', 'volumes'] |
0 commit comments