def main(): args = parse_arguments() # configure our instance of the grafeas api swagger_client.configuration.host = args.target api_instance = swagger_client.GrafeasApi() try: pubkey = util.import_rsa_public_keys_from_files_as_dict([args.key]) layout = fetch_layout(args.project_id, api_instance) except Exception as e: print("Exception when fetching the in-toto layout\n{}: {}".format( type(e).__name__, e)) sys.exit(1) # fetch the link metadata for every step for step in layout.signed.steps: for keyid in step.pubkeys: try: fetch_occurrence(args.project_id, step.name, keyid, api_instance) except ApiException as e: raise e pass try: verifylib.in_toto_verify(layout, pubkey) except Exception as e: print("Exception when verifying the supply chain\n{}: {}".format( type(e).__name__, e)) sys.exit(1)
def main(): args = parse_arguments() # configure our instance of the grafeas api swagger_client.configuration.host = args.target api_instance = swagger_client.GrafeasApi() project_id = args.project_id try: # Create and return an unsigned link (not dumping to disk) link = runlib.in_toto_run(args.name, args.materials, args.products, args.link_cmd) # Now sign the link with the passed key key = util.import_rsa_key_from_file(args.key) link.sign(key) except Exception as e: print("Exception when calling in-toto runlib: {}".format(e)) sys.exit(1) # Create an occurrence from the link link_dict = attr.asdict(link) # We need to cast return-value to string or else parsing breaks mysteriously link_dict["signed"]["byproducts"]["return-value"] = \ str(link_dict["signed"]["byproducts"]["return-value"]) # Create the in-toto link extended occurrence metadata signable = swagger_client.LinkSignable(**(link_dict["signed"])) grafeas_link = swagger_client.LinkMetadata(signable, link.signatures) # Create the occurrence object that is posted to the server occurrence = swagger_client.Occurrence() # Occurrences/links use the step name + signing keyid as id # There can be multiple occurrences per note (links per step) occurrence_id = "{}-{}".format(args.name, link.signatures[0]["keyid"][:8]) occurrence_name = "projects/{}/occurrences/{}".format( project_id, occurrence_id) # Notes/steps only use the step name as id note_name = "projects/{}/notes/{}".format(project_id, args.name) occurrence.name = occurrence_name occurrence.note_name = note_name occurrence.link_metadata = grafeas_link try: api_response = api_instance.create_occurrence(project_id, occurrence=occurrence) pprint(api_response) except ApiException as e: print( "Exception when calling GrafeasApi->create_occurrence: {}".format( e)) sys.exit(1)
def list_note_occurrences(self, project_id, note_id): graf = swagger_client.GrafeasApi() try: resp = graf.list_note_occurrences(project_id, note_id) except ApiException as e: print "Exception when calling GrafeasApi->list_note_occurrences: %s\n" % e return resp
def get_occurrence(self, project_id, occurrence_id): graf = swagger_client.GrafeasApi() try: resp = graf.get_occurrence(project_id, occurrence_id) except ApiException as e: print "Exception when calling GrafeasApi->get_occurrence: %s\n" % e return resp
def push_note(self, project_id, note_id, data): self.note_data = data graf = swagger_client.GrafeasApi() try: resp = graf.create_note(project_id, note_id=note_id, note=self.note_data) except ApiException as e: print "Exception when calling GrafeasApi->create_note: %s\n" % e return resp
def main(): args = parse_arguments() # Load passed in-toto layout layout = in_toto.models.metadata.Metablock.load(args.layout) layout_json_string = json.dumps(attr.asdict(layout)) # Configure our instance of the grafeas api swagger_client.configuration.host = args.target api_instance = swagger_client.GrafeasApi() # Pass these as args? Make constants? project_id = args.project_id operation_id = LAYOUT_OPERATION_ID operation_name = "projects/{}/operations/{}".format( project_id, operation_id) # Let's create an operation and post it to the server operation = swagger_client.Operation( name=operation_name, metadata={"in-toto": layout_json_string}, done=False) try: api_response = api_instance.create_operation(project_id, operation_id, operation=operation) pprint(api_response) except ApiException as e: print("Exception when calling GrafeasApi->create_operation: {}".format( e)) sys.exit(1) # Create notes for every step in the loaded layout and post them to the # server for step in layout.signed.steps: note = swagger_client.Note() note.step = json.dumps(attr.asdict(step)) note.name = "projects/{}/notes/{}".format(project_id, step.name) note.kind = "CUSTOM" try: api_response = api_instance.create_note(project_id, note_id=step.name, note=note) pprint(api_response) except ApiException as e: print( "Exception when calling GrafeasApi->create_note: {}".format(e)) sys.exit(1)
import time import swagger_client from swagger_client.rest import ApiException from pprint import pprint # create an instance of the API class api_client = swagger_client.ApiClient(host="http://localhost:8080") api_instance = swagger_client.GrafeasApi(api_client) try: projects_id = 'projects_id_example' # str | Part of `parent`. This field contains the projectId for example: \"project/{project_id} note_id = 'note_id_example' # str | The ID to use for this note. (optional) # occurrence = swagger_client.Occurrence(name='projects/project_one/occurrences/occurrence_one', note_name='note_one') # api_response = api_instance.create_occurrence('project_one', occurrence=occurrence) # Create a note in this format # format: = fmt.Sprintf("%s/{project_id}/%s/{entity_id}", projectKeyword, resourceKeyword) note = swagger_client.Note(name='projects/project_one/notes/note_one' ) # Note | The Note to be inserted (optional) api_response = api_instance.create_note('project_one', note_id='note_one', note=note) api_response = api_instance.list_notes('project_one') pprint(api_response) except ApiException as e: print("Exception when calling GrafeasApi-> : %s\n" % e)