Skip to content

Commit

Permalink
Merge pull request #669 from EricChen1248/v0.10.x-fix-extra-catalog-o…
Browse files Browse the repository at this point in the history
…n-install

Remove extra _catalog call when installing from oras repo
isc-tleavitt authored Jan 21, 2025
2 parents 8e138dd + 52f1e28 commit bf68aa1
Showing 2 changed files with 38 additions and 62 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- #635: When calling the "package" command, the directory is now normalized to include trailing slash (or backslash).
- #696: Fix a bug that caused error status to be ignored when publishing a module.
- #700: Fix a bug due to incompatible conventions between SemVer and OCI tags
- #669: Work with a wider variety of ORAS repos (removes _catalog call)

### Security
-
99 changes: 37 additions & 62 deletions src/cls/IPM/Repo/Oras/PackageService.cls
Original file line number Diff line number Diff line change
@@ -62,7 +62,6 @@ Method ListModules(pSearchCriteria As %IPM.Repo.SearchCriteria) As %ListOfObject
Set client = ..GetClient(..Location, ..Username, ..Password, ..Token, ..TokenAuthMethod)

#; Parse search criteria
// The OCI /v2/_catalog endpoint always returns all packages. We will filter by name and version on the client side.
Set name = $$$lcase(pSearchCriteria.Name)
Set tVersionExpression = pSearchCriteria.VersionExpression
Set tSC = ##class(%IPM.General.SemanticVersionExpression).FromString(pSearchCriteria.VersionExpression, .tVersionExpression)
@@ -75,69 +74,42 @@ Method ListModules(pSearchCriteria As %IPM.Repo.SearchCriteria) As %ListOfObject

#; Get all modules
Set tList = ##class(%Library.ListOfObjects).%New()
Set request = ..GetHttpRequest()

#; Make GET request
// response is a JSON structure like {"repositories":["package1", "package2", ...]}
Set tSC=request.Get(..PathPrefix _ "/v2/_catalog")
$$$ThrowOnError(tSC)
Set response=request.HttpResponse
If response.StatusCode'=200 {
// todo improve error processing
Set data = response.Data.Read()
Write !, "Error! " _ response.StatusCode _ ": " _ response.ReasonPhrase
Return ""
}

#; Handle results
Set json = response.Data.ReadLine()
Set data = ##class(%DynamicAbstractObject).%FromJSON(json)
Set iter = data.repositories.%GetIterator()
While iter.%GetNext(.key, .package, .type) {
If (package="") {
Continue
}
#; filter by module name
If (name'="") && (package'=name) {

#; get all versions
Set allTagsString = ..GetAllTagsPy(..Location, name, "", client)
Set allTagsList = $LISTFROMSTRING(allTagsString, ", ")
Set pointer = 0
While $ListNext(allTagsList,pointer,tag) {
#; filter by version
Set tVersion = ##class(%IPM.General.SemanticVersion).FromString(tag)
If 'tVersion.Satisfies(tVersionExpression) {
Continue
}

#; get metadata from annotations
Set metadata = ..GetPackageMetadataPy(..Location, name, "", tag, client)
set artifactMetadata = ##class(%IPM.Repo.Oras.ArtifactMetadata).%New()
Do artifactMetadata.%JSONImport(metadata)

Set tModRef = ##class(%IPM.Storage.ModuleInfo).%New()
Set tModRef.Name = artifactMetadata.ImageTitle
Set tModRef.Repository = artifactMetadata.ImageSource
Set tModRef.VersionString = artifactMetadata.ImageVersion
Set tModRef.Description = artifactMetadata.ImageDescription
Set tModRef.Deployed = artifactMetadata.IPMDeployed
#; If $IsObject(item."platform_versions") {
#; Set tIterPVer = item."platform_versions".%GetIterator()
#; While tIterPVer.%GetNext(.tPVerKey, .platformVersion) {
#; Do tModRef.PlatformVersions.Insert(platformVersion)
#; }
#; }
Set tModRef.AllVersions = allTagsString
Set tModRef.Origin = artifactMetadata.IPMOrigin
Do tList.Insert(tModRef)

#; get all versions
Set allTagsString = ..GetAllTagsPy(..Location, package, "", client)
Set allTagsList = $LISTFROMSTRING(allTagsString, ", ")
Set pointer = 0
While $ListNext(allTagsList,pointer,tag) {
#; filter by version
Set tVersion = ##class(%IPM.General.SemanticVersion).FromString(tag)
If 'tVersion.Satisfies(tVersionExpression) {
Continue
}

#; get metadata from annotations
Set metadata = ..GetPackageMetadataPy(..Location, package, "", tag, client)
set artifactMetadata = ##class(%IPM.Repo.Oras.ArtifactMetadata).%New()
Do artifactMetadata.%JSONImport(metadata)

Set tModRef = ##class(%IPM.Storage.ModuleInfo).%New()
Set tModRef.Name = artifactMetadata.ImageTitle
Set tModRef.Repository = artifactMetadata.ImageSource
Set tModRef.VersionString = artifactMetadata.ImageVersion
Set tModRef.Description = artifactMetadata.ImageDescription
Set tModRef.Deployed = artifactMetadata.IPMDeployed
#; If $IsObject(item."platform_versions") {
#; Set tIterPVer = item."platform_versions".%GetIterator()
#; While tIterPVer.%GetNext(.tPVerKey, .platformVersion) {
#; Do tModRef.PlatformVersions.Insert(platformVersion)
#; }
#; }
Set tModRef.AllVersions = allTagsString
Set tModRef.Origin = artifactMetadata.IPMOrigin
Do tList.Insert(tModRef)

#; If not all versions are requested, return the latest one
If 'pSearchCriteria.AllVersions, name="" {
Quit
}
#; If not all versions are requested, return the latest one
If 'pSearchCriteria.AllVersions, name="" {
Quit
}
}
Quit tList
@@ -344,7 +316,10 @@ ClassMethod GetAllTagsPy(registry As %String, package As %String, namespace As %

# convert from list to comma separated string
return ", ".join(str(x) for x in tags)
except e:
except ValueError:
# ValueError indicates the package is missing and has no tags. Fail silently with no tags returned
return ""
except Exception as e:
print("Error: ", repr(e))
return ""
}

0 comments on commit bf68aa1

Please sign in to comment.