2022-01-19 11:26:09 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import base
|
2023-06-01 10:34:40 +02:00
|
|
|
import os
|
2022-01-19 11:26:09 +01:00
|
|
|
|
|
|
|
def generate_key_pair():
|
2023-06-01 10:34:40 +02:00
|
|
|
config_key_file = "cosign.key"
|
|
|
|
config_pub_file = "cosign.pub"
|
|
|
|
if os.path.exists(config_key_file) and os.path.exists(config_pub_file):
|
|
|
|
os.remove(config_key_file)
|
|
|
|
os.remove(config_pub_file)
|
2022-01-19 11:26:09 +01:00
|
|
|
command = ["cosign", "generate-key-pair"]
|
|
|
|
base.run_command(command)
|
|
|
|
|
|
|
|
def sign_artifact(artifact):
|
2023-05-29 05:55:14 +02:00
|
|
|
command = ["cosign", "sign", "-y", "--allow-insecure-registry", "--key", "cosign.key", artifact]
|
2022-01-19 11:26:09 +01:00
|
|
|
base.run_command(command)
|
2023-06-01 10:34:40 +02:00
|
|
|
|
|
|
|
def push_artifact_sbom(artifact, sbom_path, type="spdx"):
|
|
|
|
command = ["cosign", "attach", "sbom", "--allow-insecure-registry", "--registry-referrers-mode", "oci-1-1",
|
|
|
|
"--type", type, "--sbom", sbom_path, artifact]
|
|
|
|
base.run_command(command)
|