Commit eb6dd293 authored by Rafael Monnerat's avatar Rafael Monnerat

[slapos.package] Include support for keys (WIP)

  Include API Support for download keys/gpg slapos.
parent d10612bc
......@@ -98,6 +98,10 @@ class PackageManager:
""" Add a repository """
return self._getDistribitionHandler().addRepository(self._call, url, alias)
def _addKey(self, url, alias):
""" Add a gpg or a key """
return self._getDistributionHandler().addKey(self.call, url)
def _updateRepository(self):
""" Add a repository """
return self._getDistribitionHandler().updateRepository(self._call)
......@@ -114,12 +118,14 @@ class PackageManager:
""" Dist-Upgrade of system """
return self._getDistribitionHandler().updateSystem(self._call)
def update(self, repository_list=[], package_list=[]):
def update(self, repository_list=[], package_list=[], key_list=[]):
""" Perform upgrade """
self._purgeRepository()
for alias, url in repository_list:
self._addRepository(url, alias)
self._updateRepository()
for alias, url in key_list:
self._addKey(url, alias)
if len(package_list):
self._installSoftwareList(package_list)
......@@ -128,12 +134,14 @@ class AptGet:
source_list_path = "/etc/apt/sources.list"
source_list_d_path = "/etc/apt/sources.list.d"
trusted_gpg_d_path = "/etc/apt/trusted.gpg.d"
def purgeRepository(self, caller):
""" Remove all repositories """
# Aggressive removal
os.remove(self.source_list_path)
open("/etc/apt/sources.list", "w+").write("# Removed all")
open(self.source_list_path, "w+").write("# Removed all")
for file_path in glob.glob("%s/*" % self.source_list_d_path):
os.remove(file_path)
......@@ -146,6 +154,14 @@ class AptGet:
repos_file.write(prefix + url)
repos_file.close()
def addKey(self, caller, url, alias):
""" Download and add a gpg key """
gpg_path = open("%s/%s.gpg" % self.trusted_gpg_d_path, alias)
if os.path.exists(gpg_path):
# File already exists, skip
return
raise NotImplementedError("Download part is missing")
def updateRepository(self, caller):
""" Add a repository """
caller(['apt-get', 'update'], stdout=None)
......@@ -189,6 +205,10 @@ class Zypper:
base_command.extend([url, alias])
output, err = caller(base_command, stdout=None)
def addKey(self, caller, url, alias):
""" Add gpg or key """
raise NotImplementedError("Not implemented for this distribution")
def updateRepository(self, caller):
""" Add a repository """
caller(['zypper', '--gpg-auto-import-keys', 'in', '-Dly'], stdout=None)
......@@ -220,4 +240,3 @@ def do_discover():
package_manager = PackageManager()
print "The signature for your current system is: %s" % package_manager.getOSSignature()
......@@ -50,7 +50,14 @@ class Promise(BasePromise):
alias, url = repository.split("=")
repository_tuple_list.append((alias.strip(), url.strip()))
self.update(repository_tuple_list, upgrade_goal['filter-package-list'])
key_tuple_list = []
for key in upgrade_goal['key-list']:
alias, url = key.split("=")
key_tuple_list.append((alias.strip(), url.strip()))
self.update(repository_tuple_list,
upgrade_goal['filter-package-list'],
key_tuple_list)
if upgrade and boot:
signature.update(reboot=today, upgrade=today)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment