-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for vendor override files
- Loading branch information
Showing
4 changed files
with
196 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
use crate::{lock::LockedImage, project::Vendor}; | ||
use std::{collections::HashMap, hash::Hash}; | ||
|
||
#[derive(Debug, Clone, Eq)] | ||
pub struct UniqueLockedImage<'lock> { | ||
image: &'lock LockedImage, | ||
vendor_overrides: &'lock HashMap<String, Vendor>, | ||
} | ||
|
||
impl<'lock> UniqueLockedImage<'lock> { | ||
pub(crate) fn new( | ||
image: &'lock LockedImage, | ||
overrides: &'lock HashMap<String, Vendor>, | ||
) -> Self { | ||
Self { | ||
image, | ||
vendor_overrides: overrides, | ||
} | ||
} | ||
} | ||
// 247242824936.dkr.ecr.us-west-2.amazonaws.com | ||
impl<'lock> PartialEq for UniqueLockedImage<'lock> { | ||
fn eq(&self, other: &Self) -> bool { | ||
if self.image.digest != other.image.digest || self.image.vendor != other.image.vendor { | ||
// Always fail if the digest has changed or if the vendors are different | ||
return false; | ||
} | ||
if !self.vendor_overrides.contains_key(&other.image.vendor) { | ||
// If there is no vendor override the resolved source uri's should match | ||
return self.image.source == other.image.source; | ||
} | ||
true | ||
} | ||
} | ||
|
||
impl<'lock> Hash for UniqueLockedImage<'lock> { | ||
fn hash<H: std::hash::Hasher>(&self, state: &mut H) { | ||
state.write(self.image.name.as_bytes()); | ||
state.write(self.image.vendor.as_bytes()); | ||
state.write(self.image.digest.as_bytes()); | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use std::collections::HashMap; | ||
|
||
use semver::Version; | ||
|
||
use crate::{lock::LockedImage, project::Vendor}; | ||
|
||
use super::UniqueLockedImage; | ||
|
||
#[test] | ||
fn test_equivalency() { | ||
let left = UniqueLockedImage { | ||
image: &LockedImage { | ||
name: "foo".to_string(), | ||
version: Version::new(1, 2, 3), | ||
vendor: "bar".to_string(), | ||
source: "fake.ecr.aws/foo:v1.2.3".to_string(), | ||
digest: "abcdef".to_string(), | ||
manifest: Vec::new(), | ||
}, | ||
vendor_overrides: &HashMap::new(), | ||
}; | ||
let right = UniqueLockedImage { | ||
image: &LockedImage { | ||
name: "foo".to_string(), | ||
version: Version::new(1, 2, 3), | ||
vendor: "bar".to_string(), | ||
source: "fake.ecr.aws/foo:v1.2.3".to_string(), | ||
digest: "abcdef".to_string(), | ||
manifest: Vec::new(), | ||
}, | ||
vendor_overrides: &HashMap::new(), | ||
}; | ||
assert_eq!(left, right, "basic equivalency"); | ||
let left = UniqueLockedImage { | ||
image: &LockedImage { | ||
name: "foo".to_string(), | ||
version: Version::new(1, 2, 3), | ||
vendor: "bar".to_string(), | ||
source: "fake2.ecr.aws/foo:v1.2.3".to_string(), | ||
digest: "abcdef".to_string(), | ||
manifest: Vec::new(), | ||
}, | ||
vendor_overrides: &HashMap::from([( | ||
"bar".to_string(), | ||
Vendor { | ||
registry: "fake.ecr.aws".to_string(), | ||
}, | ||
)]), | ||
}; | ||
assert_eq!(left, right, "vendor override equivalency"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters