Ejemplo n.º 1
0
def UploadArtifactYamlFile(file_content,
                           base_urn=None,
                           token=None,
                           overwrite=True):
    """Upload a yaml or json file as an artifact to the datastore."""
    _ = overwrite
    loaded_artifacts = []
    if not base_urn:
        base_urn = aff4.ROOT_URN.Add("artifact_store")

    with aff4.FACTORY.Create(base_urn,
                             aff4_type="RDFValueCollection",
                             token=token,
                             mode="rw") as artifact_coll:

        # Iterate through each artifact adding it to the collection.
        for artifact_value in artifact_lib.ArtifactsFromYaml(file_content):
            artifact_value.ValidateSyntax()
            artifact_coll.Add(artifact_value)
            artifact_lib.ArtifactRegistry.RegisterArtifact(
                artifact_value,
                source="datastore:%s" % base_urn,
                overwrite_if_exists=overwrite)
            loaded_artifacts.append(artifact_value)
            logging.info("Uploaded artifact %s to %s", artifact_value.name,
                         base_urn)

    # Once all artifacts are loaded we can validate, as validation of dependencies
    # requires the group are all loaded before doing the validation.
    for artifact_value in loaded_artifacts:
        artifact_value.Validate()

    return base_urn
Ejemplo n.º 2
0
 def testArtifactConversion(self):
     for art_obj in artifact_registry.ArtifactRegistry.artifacts.values():
         # Exercise conversions to ensure we can move back and forth between the
         # different forms.
         art_json = art_obj.ToPrettyJson(extended=False)
         new_art_obj = artifact_lib.ArtifactsFromYaml(art_json)[0]
         self.assertEqual(new_art_obj.ToPrimitiveDict(),
                          art_obj.ToPrimitiveDict())
Ejemplo n.º 3
0
def UploadArtifactYamlFile(file_content,
                           base_urn=None,
                           token=None,
                           overwrite=True):
    """Upload a yaml or json file as an artifact to the datastore."""
    _ = overwrite
    if not base_urn:
        base_urn = aff4.ROOT_URN.Add("artifact_store")
    with aff4.FACTORY.Create(base_urn,
                             aff4_type="RDFValueCollection",
                             token=token,
                             mode="rw") as artifact_coll:

        # Iterate through each artifact adding it to the collection.
        for artifact_value in artifact_lib.ArtifactsFromYaml(file_content):
            artifact_coll.Add(artifact_value)
            logging.info("Uploaded artifact %s to %s", artifact_value.name,
                         base_urn)

    return base_urn