def get(self, local_port, protocol): mappings_list = self.load() mapping = next( (m for m in mappings_list if m.local_port == local_port and m.protocol == protocol), None) mapping_for_log = convertible.to_json(mapping) if mapping else mapping self.logger.info('getting port mapping for local_port={0}: {1}'.format( local_port, mapping_for_log)) return mapping
def sync(self, external_ip, web_port, web_local_port, web_protocol, update_token, external_access): map_local_address = not external_access version = self.versions.platform_version() local_ip = linux.local_ip() data = { 'token': update_token, 'platform_version': version, 'local_ip': local_ip, 'map_local_address': map_local_address, 'web_protocol': web_protocol, 'web_port': web_port, 'web_local_port': web_local_port } if not external_ip: external_ip = linux.public_ip_v4() self.logger.warn("getting external ip: {0}".format(external_ip)) if external_ip: iptype = linux.ip_type(external_ip) if iptype != 'PUBLIC': external_ip = None self.logger.warn( "External ip is not public: {0}".format(iptype)) if not map_local_address: if external_ip: data['ip'] = external_ip else: self.logger.warn("Will try server side client ip detection") local_ip_v6 = linux.local_ip_v6() if local_ip_v6: data['ipv6'] = local_ip_v6 dkim_key = self.user_platform_config.get_dkim_key() if dkim_key: data['dkim_key'] = dkim_key url = urljoin(self.user_platform_config.get_redirect_api_url(), "/domain/update") self.logger.debug('url: ' + url) json = convertible.to_json(data) self.logger.info('request: ' + json) response = requests.post(url, json) util.check_http_error(response)
def test_port_mapping(): expected = '{"external_port": "8080", "local_port": "80", "protocol": "TCP"}' actual = to_json(Port("80", "8080", "TCP")) assert str(expected) == str(actual)
def test_port_mapping(): expected = '{"protocol": "TCP", "external_port": "8080", "local_port": "80"}' actual = to_json(Port("80", "8080", "TCP")) assert expected == actual