feat:[AH-926]: router changes for generic artifacts (#3330)

* feat:[AH-926]: review changes
* feat:[AH-926]: review changes
* feat:[AH-926]: router changes for generic artifacts
* feat:[AH-926]: router changes for generic artifacts
pull/3616/head
Sourabh Awashti 2025-01-28 05:47:52 +00:00 committed by Harness
parent d194dc1446
commit 1b70a9407c
6 changed files with 18 additions and 6 deletions

View File

@ -128,6 +128,7 @@ import (
"github.com/harness/gitness/registry/app/pkg"
"github.com/harness/gitness/registry/app/pkg/docker"
"github.com/harness/gitness/registry/app/pkg/filemanager"
"github.com/harness/gitness/registry/app/pkg/generic"
"github.com/harness/gitness/registry/app/pkg/maven"
database2 "github.com/harness/gitness/registry/app/store/database"
"github.com/harness/gitness/registry/gc"
@ -494,7 +495,11 @@ func initSystem(ctx context.Context, config *types.Config) (*server.System, erro
controller2 := maven.ControllerProvider(mavenLocalRegistry, mavenRemoteRegistry, authorizer, mavenDBStore)
mavenHandler := api2.NewMavenHandlerProvider(controller2, spaceStore, tokenStore, controller, authenticator, authorizer)
handler2 := router.MavenHandlerProvider(mavenHandler)
appRouter := router.AppRouterProvider(registryOCIHandler, apiHandler, handler2)
genericDBStore := generic.DBStoreProvider(imageRepository, artifactRepository, bandwidthStatRepository, downloadStatRepository, registryRepository)
genericController := generic.ControllerProvider(spaceStore, authorizer, fileManager, genericDBStore, transactor)
genericHandler := api2.NewGenericHandlerProvider(spaceStore, genericController, tokenStore, controller, authenticator, provider, authorizer)
handler3 := router.GenericHandlerProvider(genericHandler)
appRouter := router.AppRouterProvider(registryOCIHandler, apiHandler, handler2, handler3)
sender := usage.ProvideMediator(ctx, config, spaceStore, usageMetricStore)
routerRouter := router2.ProvideRouter(ctx, config, authenticator, repoController, reposettingsController, executionController, logsController, spaceController, pipelineController, secretController, triggerController, connectorController, templateController, pluginController, pullreqController, webhookController, githookController, gitInterface, serviceaccountController, controller, principalController, usergroupController, checkController, systemController, uploadController, keywordsearchController, infraproviderController, gitspaceController, migrateController, aiagentController, capabilitiesController, provider, openapiService, appRouter, sender)
serverServer := server2.ProvideServer(config, routerRouter)

View File

@ -241,7 +241,7 @@ func (c *APIController) generateGenericClientSetupDetail(ctx context.Context, bl
header2 := "Upload Artifact"
section2step1Header := "Run this curl command in your terminal to push the artifact."
//nolint:lll
pushValue := "curl --location --request PUT '<HOSTNAME>/<REGISTRY_NAME>/<ARTIFACT_NAME>/<VERSION>' \\\n--form 'filename=\"<FILENAME>\"' \\\n--form 'file=@\"<FILE_PATH>\"'\n--header 'x-api-key: <API_KEY>'"
pushValue := "curl --location --request PUT '<HOSTNAME>/<REGISTRY_NAME>/<ARTIFACT_NAME>/<VERSION>' \\\n--form 'filename=\"<FILENAME>\"' \\\n--form 'file=@\"<FILE_PATH>\"' \\\n--form 'description=\"<DESC>\"' \\\n--header 'x-api-key: <API_KEY>'"
section2step1Commands := []artifact.ClientSetupStepCommand{
{Label: &blankString, Value: &pushValue},
}
@ -263,7 +263,7 @@ func (c *APIController) generateGenericClientSetupDetail(ctx context.Context, bl
section3step1Header := "Run this command in your terminal to download the artifact."
//nolint:lll
pullValue := "curl --location '<HOSTNAME>/<REGISTRY_NAME>/<ARTIFACT_NAME>:<VERSION>:<FILENAME>' --header 'x-api-key: <API_KEY>' " +
"--O"
"-J -O"
section3step1Commands := []artifact.ClientSetupStepCommand{
{Label: &blankString, Value: &pullValue},
}

View File

@ -385,7 +385,7 @@ func GetHelmPullCommand(image string, tag string, registryURL string) string {
func GetGenericArtifactFileDownloadCommand(regURL, artifact, version, filename string) string {
downloadCommand := "curl --location '<HOSTNAME>/<ARTIFACT>:<VERSION>:<FILENAME>' --header 'x-api-key: <API_KEY>'" +
" --output <TARGET_FILENAME>"
" -J -O"
// Replace the placeholders with the actual values
replacements := map[string]string{

View File

@ -21,6 +21,7 @@ import (
"github.com/harness/gitness/app/api/middleware/address"
"github.com/harness/gitness/app/api/middleware/logging"
"github.com/harness/gitness/registry/app/api/handler/swagger"
generic2 "github.com/harness/gitness/registry/app/api/router/generic"
"github.com/harness/gitness/registry/app/api/router/harness"
"github.com/harness/gitness/registry/app/api/router/maven"
"github.com/harness/gitness/registry/app/api/router/oci"
@ -38,6 +39,7 @@ func GetAppRouter(
appHandler harness.APIHandler,
baseURL string,
mavenHandler maven.Handler,
genericHandler generic2.Handler,
) AppRouter {
r := chi.NewRouter()
r.Use(hlog.URLHandler("http.url"))
@ -50,6 +52,7 @@ func GetAppRouter(
r.Handle(fmt.Sprintf("%s/*", baseURL), appHandler)
r.Handle("/v2/*", ociHandler)
r.Handle("/maven/*", mavenHandler)
r.Handle("/generic/*", genericHandler)
r.Handle("/registry/swagger*", swagger.GetSwaggerHandler("/registry"))
})

View File

@ -40,8 +40,9 @@ func AppRouterProvider(
ocir oci.RegistryOCIHandler,
appHandler harness.APIHandler,
mavenHandler mavenRouter.Handler,
genericHandler generic2.Handler,
) AppRouter {
return GetAppRouter(ocir, appHandler, config.APIURL, mavenHandler)
return GetAppRouter(ocir, appHandler, config.APIURL, mavenHandler, genericHandler)
}
func APIHandlerProvider(

View File

@ -396,7 +396,10 @@ func (t tagDao) GetAllArtifactsByParentID(
t.tag_registry_id ORDER BY t.tag_updated_at DESC) AS tag_rank
FROM tags t
JOIN manifests m ON t.tag_manifest_id = m.manifest_id) AS tag_q
ON decode(ar.artifact_version, 'hex') = tag_q.manifest_digest
ON CASE
WHEN ar.artifact_version ~ '^[0-9A-Fa-f]+$' THEN decode(ar.artifact_version, 'hex')
ELSE NULL
END = tag_q.manifest_digest
AND i.image_name = tag_q.tag_image_name
AND i.image_registry_id = tag_q.tag_registry_id AND tag_q.tag_rank = 1`,
)