vars,facts: update_check -> needs_upload
This commit is contained in:
@@ -25,8 +25,8 @@ class SecretStoreBase(ABC):
|
|||||||
def exists(self, service: str, name: str) -> bool:
|
def exists(self, service: str, name: str) -> bool:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def update_check(self) -> bool:
|
def needs_upload(self) -> bool:
|
||||||
return False
|
return True
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def upload(self, output_dir: Path) -> None:
|
def upload(self, output_dir: Path) -> None:
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ class SecretStore(SecretStoreBase):
|
|||||||
return b"\n".join(hashes)
|
return b"\n".join(hashes)
|
||||||
|
|
||||||
@override
|
@override
|
||||||
def update_check(self) -> bool:
|
def needs_upload(self) -> bool:
|
||||||
local_hash = self.generate_hash()
|
local_hash = self.generate_hash()
|
||||||
remote_hash = self.machine.target_host.run(
|
remote_hash = self.machine.target_host.run(
|
||||||
# TODO get the path to the secrets from the machine
|
# TODO get the path to the secrets from the machine
|
||||||
@@ -103,9 +103,9 @@ class SecretStore(SecretStoreBase):
|
|||||||
|
|
||||||
if not remote_hash:
|
if not remote_hash:
|
||||||
print("remote hash is empty")
|
print("remote hash is empty")
|
||||||
return False
|
return True
|
||||||
|
|
||||||
return local_hash.decode() == remote_hash
|
return local_hash.decode() != remote_hash
|
||||||
|
|
||||||
def upload(self, output_dir: Path) -> None:
|
def upload(self, output_dir: Path) -> None:
|
||||||
os.umask(0o077)
|
os.umask(0o077)
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ def upload_secrets(machine: Machine) -> None:
|
|||||||
secret_facts_module = importlib.import_module(machine.secret_facts_module)
|
secret_facts_module = importlib.import_module(machine.secret_facts_module)
|
||||||
secret_facts_store = secret_facts_module.SecretStore(machine=machine)
|
secret_facts_store = secret_facts_module.SecretStore(machine=machine)
|
||||||
|
|
||||||
if secret_facts_store.update_check():
|
if not secret_facts_store.needs_upload():
|
||||||
log.info("Secrets already up to date")
|
log.info("Secrets already uploaded")
|
||||||
return
|
return
|
||||||
with TemporaryDirectory(prefix="facts-upload-") as tempdir:
|
with TemporaryDirectory(prefix="facts-upload-") as tempdir:
|
||||||
secret_facts_store.upload(Path(tempdir))
|
secret_facts_store.upload(Path(tempdir))
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ class SecretStoreBase(StoreBase):
|
|||||||
def is_secret_store(self) -> bool:
|
def is_secret_store(self) -> bool:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def update_check(self) -> bool:
|
def needs_upload(self) -> bool:
|
||||||
return False
|
return True
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def upload(self, output_dir: Path) -> None:
|
def upload(self, output_dir: Path) -> None:
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ class SecretStore(SecretStoreBase):
|
|||||||
return b"\n".join(hashes)
|
return b"\n".join(hashes)
|
||||||
|
|
||||||
@override
|
@override
|
||||||
def update_check(self) -> bool:
|
def needs_upload(self) -> bool:
|
||||||
local_hash = self.generate_hash()
|
local_hash = self.generate_hash()
|
||||||
remote_hash = self.machine.target_host.run(
|
remote_hash = self.machine.target_host.run(
|
||||||
# TODO get the path to the secrets from the machine
|
# TODO get the path to the secrets from the machine
|
||||||
@@ -135,9 +135,9 @@ class SecretStore(SecretStoreBase):
|
|||||||
|
|
||||||
if not remote_hash:
|
if not remote_hash:
|
||||||
print("remote hash is empty")
|
print("remote hash is empty")
|
||||||
return False
|
return True
|
||||||
|
|
||||||
return local_hash.decode() == remote_hash
|
return local_hash.decode() != remote_hash
|
||||||
|
|
||||||
def upload(self, output_dir: Path) -> None:
|
def upload(self, output_dir: Path) -> None:
|
||||||
for secret_var in self.get_all():
|
for secret_var in self.get_all():
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ def upload_secrets(machine: Machine) -> None:
|
|||||||
secret_store_module = importlib.import_module(machine.secret_facts_module)
|
secret_store_module = importlib.import_module(machine.secret_facts_module)
|
||||||
secret_store = secret_store_module.SecretStore(machine=machine)
|
secret_store = secret_store_module.SecretStore(machine=machine)
|
||||||
|
|
||||||
if secret_store.update_check():
|
if not secret_store.needs_upload():
|
||||||
log.info("Secrets already up to date")
|
log.info("Secrets already uploaded")
|
||||||
return
|
return
|
||||||
with TemporaryDirectory(prefix="vars-upload-") as tempdir:
|
with TemporaryDirectory(prefix="vars-upload-") as tempdir:
|
||||||
secret_store.upload(Path(tempdir))
|
secret_store.upload(Path(tempdir))
|
||||||
|
|||||||
Reference in New Issue
Block a user