Skip to content

Commit

Permalink
fix(api): Don't make assumptions about which resources link to artifa…
Browse files Browse the repository at this point in the history
…cts (#1459)
  • Loading branch information
luispollo committed Aug 25, 2020
1 parent 336ac83 commit 659c996
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface ArtifactProvider {
val artifactName: String?
val artifactType: ArtifactType?

@JvmDefault
fun completeArtifactOrNull() =
if (artifactName != null && artifactType != null) {
CompleteArtifact(artifactName!!, artifactType!!)
Expand All @@ -28,6 +29,7 @@ interface ArtifactProvider {
interface VersionedArtifactProvider : ArtifactProvider {
val artifactVersion: String?

@JvmDefault
fun completeVersionedArtifactOrNull() =
if (artifactName != null && artifactType != null && artifactVersion != null) {
CompleteVersionedArtifact(artifactName!!, artifactType!!, artifactVersion!!)
Expand All @@ -44,6 +46,7 @@ interface ArtifactReferenceProvider {
val artifactReference: String?
val artifactType: ArtifactType?

@JvmDefault
fun completeArtifactReferenceOrNull() =
if (artifactReference != null && artifactType != null) {
CompleteArtifactReference(artifactReference!!, artifactType!!)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,18 @@ data class Resource<out T : ResourceSpec>(
* Attempts to find an artifact in the delivery config based on information in this resource's spec.
*/
fun findAssociatedArtifact(deliveryConfig: DeliveryConfig) =
if (spec is ComputeResourceSpec) {
// prefer reference-based artifact info
spec.completeArtifactReferenceOrNull()
?.let { ref ->
deliveryConfig.matchingArtifactByReference(ref.artifactReference)
}
// if not found, then try old-style image provider info
?: spec.completeArtifactOrNull()
when (spec) {
is ArtifactReferenceProvider ->
spec.completeArtifactReferenceOrNull()
?.let { ref ->
deliveryConfig.matchingArtifactByReference(ref.artifactReference)
}
is ArtifactProvider ->
spec.completeArtifactOrNull()
?.let { art ->
deliveryConfig.matchingArtifactByName(art.artifactName, art.artifactType)
}
} else {
null
else -> null
}

// TODO: this is kinda dirty, but because we add uid to the metadata when persisting we don't really want to consider it in equality checks
Expand Down

0 comments on commit 659c996

Please sign in to comment.