Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ variables:
variants:
ac_config_field: "oci_repository_urls"
values: [ "newrelic/infrastructure-agent-artifacts" ]
public_key:
description: "Public key url"
type: string
required: false
default: ""
version:
description: "Agent version"
type: string
Expand Down Expand Up @@ -169,6 +174,7 @@ deployment:
registry: ${nr-var:oci.registry}
repository: ${nr-var:oci.repository}
version: ${nr-var:version}
public_key: ${nr-var:oci.public_key}
version:
path: ${nr-sub:packages.infra-agent.dir}\\newrelic-infra.exe
args:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ variables:
variants:
ac_config_field: "oci_nrdot_registry_repositories"
values: [ "newrelic/nrdot-agent-artifacts" ]
public_key:
description: "Public key url"
type: string
required: false
default: ""
version:
description: "Agent version"
type: string
Expand Down Expand Up @@ -136,6 +141,7 @@ deployment:
registry: ${nr-var:oci.registry}
repository: ${nr-var:oci.repository}
version: ${nr-var:version}
public_key: ${nr-var:oci.public_key}
version:
path: ${nr-sub:packages.nrdot.dir}\\nrdot-collector.exe
args:
Expand Down
1 change: 1 addition & 0 deletions agent-control/src/agent_type/definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ deployment:
oci:
registry: ${nr-var:registry}
repository: ${nr-var:repository}
public_key: ${nr-var:public_key}
version: ${nr-var:version}
"#;

Expand Down
7 changes: 7 additions & 0 deletions agent-control/src/agent_type/runtime_config/on_host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ mod tests {
"${nr-var:repository}".to_string(),
),
version: TemplateableValue::from_template("${nr-var:version}".to_string()),
public_key: TemplateableValue::from_template(
"${nr-var:public-key}".to_string(),
),
},
},
};
Expand Down Expand Up @@ -192,6 +195,7 @@ packages:
registry: my.registry
repository: my/repo
version: latest
public_key: https://a-public-key-path
"#;
let on_host: OnHost = serde_yaml::from_str(yaml).unwrap();

Expand Down Expand Up @@ -261,6 +265,7 @@ packages:
registry: my.registry
repository: my/repo
version: latest
public_key: https://a-public-key-path
"#;
let on_host: OnHost = serde_yaml::from_str(yaml).unwrap();

Expand Down Expand Up @@ -754,12 +759,14 @@ packages:
registry: ${nr-var:registry}
repository: ${nr-var:repository}
version: ${nr-var:version}
public_key: ${nr-var:public-key}
otel-second:
type: tar.gz
download:
oci:
registry: ${nr-var:registry}
repository: ${nr-var:repository}
version: ${nr-var:version}
public_key: ${nr-var:public-key}
"#;
}
29 changes: 24 additions & 5 deletions agent-control/src/agent_type/runtime_config/on_host/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::agent_type::templates::Templateable;
use oci_spec::distribution::Reference;
use serde::Deserialize;
use std::str::FromStr;

pub mod rendered;

#[derive(Debug, Deserialize, Default, Clone, PartialEq)]
Expand All @@ -31,6 +30,8 @@ pub struct Oci {
/// Package version including tag, digest or tag + digest.
#[serde(default)]
pub version: TemplateableValue<String>,
/// public key url.
pub public_key: TemplateableValue<String>,
}

impl Templateable for Package {
Expand All @@ -57,6 +58,7 @@ impl Templateable for Oci {
let registry = self.registry.template_with(variables)?;
let repository = self.repository.template_with(variables)?;
let mut version = self.version.template_with(variables)?;
let public_key = self.public_key.template_with(variables)?;

if !version.is_empty() && !version.starts_with('@') {
version = format!(":{}", version);
Expand All @@ -69,7 +71,10 @@ impl Templateable for Oci {
))
})?;

Ok(Self::Output { reference })
Ok(Self::Output {
reference,
public_key,
})
}
}

Expand All @@ -85,18 +90,26 @@ mod tests {
#[case::only_digest(
"@sha256:ec5f08ee7be8b557cd1fc5ae1a0ac985e8538da7c93f51a51eff4b277509a723",
None,
Some("sha256:ec5f08ee7be8b557cd1fc5ae1a0ac985e8538da7c93f51a51eff4b277509a723")
Some("sha256:ec5f08ee7be8b557cd1fc5ae1a0ac985e8538da7c93f51a51eff4b277509a723"),
"https://github.com/rust-lang/crates.io-index"
)]
#[case::tag_and_digest(
"a-tag@sha256:ec5f08ee7be8b557cd1fc5ae1a0ac985e8538da7c93f51a51eff4b277509a723",
Some("a-tag"),
Some("sha256:ec5f08ee7be8b557cd1fc5ae1a0ac985e8538da7c93f51a51eff4b277509a723")
Some("sha256:ec5f08ee7be8b557cd1fc5ae1a0ac985e8538da7c93f51a51eff4b277509a723"),
"https://github.com/rust-lang/crates.io-index"
)]
#[case::empty_version(
"",
Some("latest"),
None,
"https://github.com/rust-lang/crates.io-index"
)]
#[case::empty_version("", Some("latest"), None)]
fn oci_template(
#[case] version: &str,
#[case] tag: Option<&str>,
#[case] digest: Option<&str>,
#[case] public_key: &str,
) {
let mut variables = Variables::new();
variables.insert(
Expand All @@ -111,11 +124,16 @@ mod tests {
"nr-var:version".to_string(),
Variable::new_final_string_variable(version.to_string()),
);
variables.insert(
"nr-var:public-key".to_string(),
Variable::new_final_string_variable(public_key.to_string()),
);

let oci = Oci {
registry: TemplateableValue::from_template("${nr-var:registry}".to_string()),
repository: TemplateableValue::from_template("${nr-var:repository}".to_string()),
version: TemplateableValue::from_template("${nr-var:version}".to_string()),
public_key: TemplateableValue::from_template("${nr-var:public-key}".to_string()),
};

let rendered_oci = oci.template_with(&variables);
Expand All @@ -127,5 +145,6 @@ mod tests {
assert_eq!(rendered_oci.reference.repository(), "repo");
assert_eq!(rendered_oci.reference.tag(), tag);
assert_eq!(rendered_oci.reference.digest(), digest);
assert_eq!(rendered_oci.public_key, public_key);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ pub struct Download {
#[derive(Debug, Clone, PartialEq)]
pub struct Oci {
pub reference: Reference,
pub public_key: String,
}
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ fn create_agent_type(local_dir: &TempDir, agent_id: &str, platform: &Platform) -
registry: {OCI_TEST_REGISTRY_URL}
repository: test
version: ${{nr-var:fake_variable}}
public_key: https://public.key
"#
);

Expand Down
Loading