Beispiel #1
0
def access(image):
    if '/' not in image:
        return True
    hub, image_name = image.split('/', 1)
    if ':' in image_name:
        image_name, image_tag = image_name.split(':', 1)
    else:
        image_tag = 'latest'
    url = 'https://%s/v2/%s/manifests/%s' % (hub, image_name, image_tag)
    username = password = ucr_get('uuid/license')
    auth = encodestring('%s:%s' % (username, password)).replace('\n', '')
    request = urllib_request.Request(
        url, headers={'Authorization': 'Basic %s' % auth})
    try:
        urlopen(request)
    except urllib_request.HTTPError as exc:
        if exc.getcode() == 401:
            return False
        else:
            return False  # TODO
    except (urllib_request.URLError, ssl.CertificateError,
            http_client.BadStatusLine):
        return False  # TODO
    else:
        return True
Beispiel #2
0
	def main(self, args):
		meta_inf_dir = os.path.join(args.path, 'meta-inf', args.ucs_version)
		repo_dir = os.path.join(args.path, 'univention-repository', args.ucs_version)
		if args.revert:
			try:
				shutil.rmtree(os.path.dirname(meta_inf_dir))
			except OSError as exc:
				self.warn(exc)
			try:
				shutil.rmtree(os.path.dirname(repo_dir))
			except OSError as exc:
				self.warn(exc)
			use_test_appcenter = get_action('dev-use-test-appcenter')
			use_test_appcenter.call_safe(revert=True)
		else:
			mkdir(meta_inf_dir)
			mkdir(os.path.join(repo_dir, 'maintained', 'component'))
			for supra_file in ['categories.ini', 'rating.ini', 'license_types.ini', 'ucs.ini']:
				with open(os.path.join(meta_inf_dir, '..', supra_file), 'wb') as f:
					categories = urlopen('%s/meta-inf/%s' % (default_server(), supra_file)).read()
					f.write(categories)
			server = 'http://%s' % args.appcenter_host
			use_test_appcenter = get_action('dev-use-test-appcenter')
			use_test_appcenter.call_safe(appcenter_host=server)
			DevRegenerateMetaInf.call_safe(ucs_version=args.ucs_version, path=args.path, appcenter_host=server)
			self.log('Local App Center server is set up at %s.' % server)
			self.log('If this server should serve as an App Center server for other computers in the UCS domain, the following command has to be executed on each computer:')
			self.log('  univention-app dev-use-test-appcenter --appcenter-host="%s"' % server)
Beispiel #3
0
	def _download_file(self, server, app, fname):
		url = os.path.join(server or app.get_server(), 'univention-repository', app.get_ucs_version(), 'maintained', 'component', app.component_id, 'test')
		self.log('Downloading "%s"...' % url)
		request = Request(url)
		response = urlopen(request)
		content = response.read()
		self.log('Writing to "%s"...' % fname)
		with open(fname, 'wb') as f:
			f.write(content)
		os.chmod(fname, 0o755)
Beispiel #4
0
	def _download_file(self, base_url, filename, cache_dir, etag, ucs_version=None):
		url = os.path.join(base_url, 'meta-inf', ucs_version or '', filename)
		self.log('Downloading "%s"...' % url)
		headers = {}
		if etag:
			headers['If-None-Match'] = etag
		request = Request(url, headers=headers)
		try:
			response = urlopen(request)
		except HTTPError as exc:
			if exc.getcode() == 304:
				self.debug('  ... Not Modified')
				return None
			raise
		etag = response.headers.get('etag')
		content = response.read()
		with open(os.path.join(cache_dir, '.%s' % filename), 'wb') as f:
			f.write(content)
		return etag
Beispiel #5
0
	def _download_directly(self, app_cache, files_to_download):
		for filename_url, filename, remote_md5sum in files_to_download:
			# dont forget to quote: 'foo & bar.ini' -> 'foo%20&%20bar.ini'
			# but dont quote https:// -> https%3A//
			path = quote(urlsplit(filename_url).path)
			filename_url = '%s%s' % (app_cache.get_server(), path)

			cached_filename = os.path.join(app_cache.get_cache_dir(), filename)

			self.debug('Downloading %s' % filename_url)
			try:
				urlcontent = urlopen(filename_url)
			except Exception as e:
				self.fatal('Error downloading %s: %s' % (filename_url, e))
			else:
				with open(cached_filename, 'wb') as f:
					f.write(urlcontent.read())
				local_md5sum = get_md5_from_file(cached_filename)
				if local_md5sum != remote_md5sum:
					self.fatal('Checksum for %s should be %r but was %r! Rather removing this file...' % (filename, remote_md5sum, local_md5sum))
					os.unlink(cached_filename)
				self._files_downloaded[filename] = remote_md5sum
Beispiel #6
0
	def _download_archive(self, app_cache, files_to_download):
		# a lot of files to download? Do not download them
		#   one at a time. Download the full archive!
		files_still_to_download = []
		archive_url = os.path.join(app_cache.get_server(), 'meta-inf', app_cache.get_ucs_version(), 'all.tar.gz')
		try:
			self.log('Downloading "%s"...' % archive_url)
			# for some reason saving this in memory is flawed.
			# using StringIO and GZip objects has issues
			# with "empty" files in tar.gz archives, i.e.
			# doublets like .png logos
			with open(os.path.join(app_cache.get_cache_dir(), 'all.tar.gz'), 'wb') as f:
				f.write(urlopen(archive_url).read())
			archive = tarfile.open(f.name, 'r:*')
			try:
				for filename_url, filename, remote_md5sum in files_to_download:
					self.debug('Extracting %s' % filename)
					try:
						archive.extract(filename, path=app_cache.get_cache_dir())
						absolute_filename = os.path.join(app_cache.get_cache_dir(), filename)
						os.chown(absolute_filename, 0, 0)
						os.chmod(absolute_filename, 0o664)
						local_md5sum = get_md5_from_file(absolute_filename)
						if local_md5sum != remote_md5sum:
							self.warn('Checksum for %s should be %r but was %r! Download manually' % (filename, remote_md5sum, local_md5sum))
							raise KeyError(filename)
						self._files_downloaded[filename] = remote_md5sum
					except KeyError:
						self.warn('%s not found in archive!' % filename)
						files_still_to_download.append((filename_url, filename, remote_md5sum))
			finally:
				archive.close()
				os.unlink(f.name)
			return files_still_to_download
		except Exception as exc:
			self.fatal('Could not read "%s": %s' % (archive_url, exc))
			return files_to_download