def edit_validation_sets(account_id: str, set_name: str, sequence: int, key_name: str): """Edit the list of validations for <set-name>. Refer to https://snapcraft.io/docs/validation-sets for further information on Validation Sets. """ store_client = StoreClientCLI() asserted_validation_sets = store_client.get_validation_sets( name=set_name, sequence=str(sequence)) try: # assertions should only have one item since a specific # sequence was requested. revision = asserted_validation_sets.assertions[0].revision snaps = yaml_utils.dump({ "snaps": [ s.marshal() for s in asserted_validation_sets.assertions[0].snaps ] }) except IndexError: # If there is no assertion for a given sequence, the store API # will return an empty list. revision = "0" snaps = _VALIDATIONS_SETS_SNAPS_TEMPLATE unverified_validation_sets = _VALIDATION_SETS_TEMPLATE.format( account_id=account_id, set_name=set_name, sequence=sequence, revision=revision, snaps=snaps, ) edited_validation_sets = _edit_validation_sets(unverified_validation_sets) if edited_validation_sets == yaml_utils.load(unverified_validation_sets): echo.warning("No changes made.") else: build_assertion = store_client.post_validation_sets_build_assertion( validation_sets=edited_validation_sets) signed_validation_sets = _sign_assertion(build_assertion.marshal(), key_name=key_name) store_client.post_validation_sets( signed_validation_sets=signed_validation_sets)
def list_validation_sets(name, sequence): """Get the list of validation sets. The sequence option can be a sequence number or a keyword. \b Examples: snapcraft list-validation-sets snapcraft list-validation-sets --sequence all snapcraft list-validation-sets --name my-set --sequence 1 Refer to https://snapcraft.io/docs/validation-sets for further information on Validation Sets. """ store_client = StoreClientCLI() asserted_validation_sets = store_client.get_validation_sets( name=name, sequence=sequence, ) if not asserted_validation_sets.assertions and (name or sequence): echo.warning( "No validation sets found for the requested name or sequence.") elif not asserted_validation_sets.assertions: echo.warning("No validation sets found for this account.") else: headers = ["Account-ID", "Name", "Sequence", "Revision", "When"] assertions = list() for assertion in asserted_validation_sets.assertions: assertions.append([ assertion.account_id, assertion.name, assertion.sequence, assertion.revision, datetime.strptime(assertion.timestamp, "%Y-%m-%dT%H:%M:%SZ").strftime("%Y-%m-%d"), ]) click.echo( tabulate(assertions, numalign="left", headers=headers, tablefmt="plain"))