Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove extra _catalog call when installing from oras repo #669

Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,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
-
Expand Down
99 changes: 37 additions & 62 deletions src/cls/IPM/Repo/Oras/PackageService.cls
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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 ""
}
Expand Down
Loading