mirror of
https://github.com/harness/drone.git
synced 2025-05-13 23:50:47 +08:00
feat: [AH-895]: Added support for upstream registries to not show push commands (#3564)
* [AH-895]: Added support for upstream registries to not show push commands
This commit is contained in:
parent
70823cc3b4
commit
e6ac0ef996
@ -26,6 +26,8 @@ import (
|
|||||||
"github.com/harness/gitness/registry/app/api/openapi/contracts/artifact"
|
"github.com/harness/gitness/registry/app/api/openapi/contracts/artifact"
|
||||||
"github.com/harness/gitness/registry/app/common"
|
"github.com/harness/gitness/registry/app/common"
|
||||||
"github.com/harness/gitness/types/enum"
|
"github.com/harness/gitness/types/enum"
|
||||||
|
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *APIController) GetClientSetupDetails(
|
func (c *APIController) GetClientSetupDetails(
|
||||||
@ -74,11 +76,21 @@ func (c *APIController) GetClientSetupDetails(
|
|||||||
|
|
||||||
packageType := string(reg.PackageType)
|
packageType := string(reg.PackageType)
|
||||||
|
|
||||||
return artifact.GetClientSetupDetails200JSONResponse{
|
response := c.GenerateClientSetupDetails(
|
||||||
ClientSetupDetailsResponseJSONResponse: *c.GenerateClientSetupDetails(
|
|
||||||
ctx, packageType, imageParam, tagParam, regInfo.RegistryRef,
|
ctx, packageType, imageParam, tagParam, regInfo.RegistryRef,
|
||||||
|
regInfo.RegistryType,
|
||||||
|
)
|
||||||
|
|
||||||
|
if response == nil {
|
||||||
|
return artifact.GetClientSetupDetails400JSONResponse{
|
||||||
|
BadRequestJSONResponse: artifact.BadRequestJSONResponse(
|
||||||
|
*GetErrorResponse(http.StatusBadRequest, "Package type not supported"),
|
||||||
),
|
),
|
||||||
}, nil
|
}, nil
|
||||||
|
}
|
||||||
|
return artifact.GetClientSetupDetails200JSONResponse{
|
||||||
|
ClientSetupDetailsResponseJSONResponse: *response,
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *APIController) GenerateClientSetupDetails(
|
func (c *APIController) GenerateClientSetupDetails(
|
||||||
@ -87,6 +99,7 @@ func (c *APIController) GenerateClientSetupDetails(
|
|||||||
image *artifact.ArtifactParam,
|
image *artifact.ArtifactParam,
|
||||||
tag *artifact.VersionParam,
|
tag *artifact.VersionParam,
|
||||||
registryRef string,
|
registryRef string,
|
||||||
|
registryType artifact.RegistryType,
|
||||||
) *artifact.ClientSetupDetailsResponseJSONResponse {
|
) *artifact.ClientSetupDetailsResponseJSONResponse {
|
||||||
session, _ := request.AuthSessionFrom(ctx)
|
session, _ := request.AuthSessionFrom(ctx)
|
||||||
username := session.Principal.Email
|
username := session.Principal.Email
|
||||||
@ -96,15 +109,36 @@ func (c *APIController) GenerateClientSetupDetails(
|
|||||||
blankString := ""
|
blankString := ""
|
||||||
switch packageType {
|
switch packageType {
|
||||||
case string(artifact.PackageTypeMAVEN):
|
case string(artifact.PackageTypeMAVEN):
|
||||||
return c.generateMavenClientSetupDetail(ctx, image, tag, registryRef, username)
|
return c.generateMavenClientSetupDetail(ctx, image, tag, registryRef, username, registryType)
|
||||||
case string(artifact.PackageTypeHELM):
|
case string(artifact.PackageTypeHELM):
|
||||||
return c.generateHelmClientSetupDetail(ctx, blankString, loginUsernameLabel, loginUsernameValue,
|
return c.generateHelmClientSetupDetail(ctx, blankString, loginUsernameLabel, loginUsernameValue,
|
||||||
loginPasswordLabel, username, registryRef, image, tag)
|
loginPasswordLabel, username, registryRef, image, tag, registryType)
|
||||||
case string(artifact.PackageTypeGENERIC):
|
case string(artifact.PackageTypeGENERIC):
|
||||||
return c.generateGenericClientSetupDetail(ctx, blankString, registryRef, image, tag)
|
return c.generateGenericClientSetupDetail(ctx, blankString, registryRef, image, tag, registryType)
|
||||||
case string(artifact.PackageTypePYTHON):
|
case string(artifact.PackageTypePYTHON):
|
||||||
return c.generatePythonClientSetupDetail(ctx, registryRef, username, image, tag)
|
return c.generatePythonClientSetupDetail(ctx, registryRef, username, image, tag, registryType)
|
||||||
|
case string(artifact.PackageTypeDOCKER):
|
||||||
|
return c.generateDockerClientSetupDetail(ctx, blankString, loginUsernameLabel, loginUsernameValue,
|
||||||
|
loginPasswordLabel, registryType,
|
||||||
|
username, registryRef, image, tag)
|
||||||
|
default:
|
||||||
|
log.Debug().Ctx(ctx).Msgf("Unknown package type for client details: %s", packageType)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *APIController) generateDockerClientSetupDetail(
|
||||||
|
ctx context.Context,
|
||||||
|
blankString string,
|
||||||
|
loginUsernameLabel string,
|
||||||
|
loginUsernameValue string,
|
||||||
|
loginPasswordLabel string,
|
||||||
|
registryType artifact.RegistryType,
|
||||||
|
username string,
|
||||||
|
registryRef string,
|
||||||
|
image *artifact.ArtifactParam,
|
||||||
|
tag *artifact.VersionParam,
|
||||||
|
) *artifact.ClientSetupDetailsResponseJSONResponse {
|
||||||
header1 := "Login to Docker"
|
header1 := "Login to Docker"
|
||||||
section1step1Header := "Run this Docker command in your terminal to authenticate the client."
|
section1step1Header := "Run this Docker command in your terminal to authenticate the client."
|
||||||
dockerLoginValue := "docker login <LOGIN_HOSTNAME>"
|
dockerLoginValue := "docker login <LOGIN_HOSTNAME>"
|
||||||
@ -184,14 +218,23 @@ func (c *APIController) GenerateClientSetupDetails(
|
|||||||
_ = section3.FromClientSetupStepConfig(artifact.ClientSetupStepConfig{
|
_ = section3.FromClientSetupStepConfig(artifact.ClientSetupStepConfig{
|
||||||
Steps: §ion3Steps,
|
Steps: §ion3Steps,
|
||||||
})
|
})
|
||||||
clientSetupDetails := artifact.ClientSetupDetails{
|
sections := []artifact.ClientSetupSection{
|
||||||
MainHeader: "Docker Client Setup",
|
|
||||||
SecHeader: "Follow these instructions to install/use Docker artifacts or compatible packages.",
|
|
||||||
Sections: []artifact.ClientSetupSection{
|
|
||||||
section1,
|
section1,
|
||||||
section2,
|
section2,
|
||||||
section3,
|
section3,
|
||||||
},
|
}
|
||||||
|
|
||||||
|
if registryType == artifact.RegistryTypeUPSTREAM {
|
||||||
|
sections = []artifact.ClientSetupSection{
|
||||||
|
section1,
|
||||||
|
section2,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
clientSetupDetails := artifact.ClientSetupDetails{
|
||||||
|
MainHeader: "Docker Client Setup",
|
||||||
|
SecHeader: "Follow these instructions to install/use Docker artifacts or compatible packages.",
|
||||||
|
Sections: sections,
|
||||||
}
|
}
|
||||||
|
|
||||||
c.replacePlaceholders(ctx, &clientSetupDetails.Sections, username, registryRef, image, tag, "", "", "")
|
c.replacePlaceholders(ctx, &clientSetupDetails.Sections, username, registryRef, image, tag, "", "", "")
|
||||||
@ -204,8 +247,12 @@ func (c *APIController) GenerateClientSetupDetails(
|
|||||||
|
|
||||||
//nolint:lll
|
//nolint:lll
|
||||||
func (c *APIController) generateGenericClientSetupDetail(
|
func (c *APIController) generateGenericClientSetupDetail(
|
||||||
ctx context.Context, blankString string,
|
ctx context.Context,
|
||||||
registryRef string, image *artifact.ArtifactParam, tag *artifact.VersionParam,
|
blankString string,
|
||||||
|
registryRef string,
|
||||||
|
image *artifact.ArtifactParam,
|
||||||
|
tag *artifact.VersionParam,
|
||||||
|
registryType artifact.RegistryType,
|
||||||
) *artifact.ClientSetupDetailsResponseJSONResponse {
|
) *artifact.ClientSetupDetailsResponseJSONResponse {
|
||||||
header1 := "Generate identity token"
|
header1 := "Generate identity token"
|
||||||
section1Header := "An identity token will serve as the password for uploading and downloading artifact."
|
section1Header := "An identity token will serve as the password for uploading and downloading artifact."
|
||||||
@ -267,14 +314,23 @@ func (c *APIController) generateGenericClientSetupDetail(
|
|||||||
Steps: §ion3steps,
|
Steps: §ion3steps,
|
||||||
})
|
})
|
||||||
|
|
||||||
clientSetupDetails := artifact.ClientSetupDetails{
|
sections := []artifact.ClientSetupSection{
|
||||||
MainHeader: "Generic Client Setup",
|
|
||||||
SecHeader: "Follow these instructions to install/use Generic artifacts or compatible packages.",
|
|
||||||
Sections: []artifact.ClientSetupSection{
|
|
||||||
section1,
|
section1,
|
||||||
section2,
|
section2,
|
||||||
section3,
|
section3,
|
||||||
},
|
}
|
||||||
|
|
||||||
|
if registryType == artifact.RegistryTypeUPSTREAM {
|
||||||
|
sections = []artifact.ClientSetupSection{
|
||||||
|
section1,
|
||||||
|
section3,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
clientSetupDetails := artifact.ClientSetupDetails{
|
||||||
|
MainHeader: "Generic Client Setup",
|
||||||
|
SecHeader: "Follow these instructions to install/use Generic artifacts or compatible packages.",
|
||||||
|
Sections: sections,
|
||||||
}
|
}
|
||||||
//nolint:lll
|
//nolint:lll
|
||||||
c.replacePlaceholders(ctx, &clientSetupDetails.Sections, "", registryRef, image, tag, "", "",
|
c.replacePlaceholders(ctx, &clientSetupDetails.Sections, "", registryRef, image, tag, "", "",
|
||||||
@ -296,6 +352,7 @@ func (c *APIController) generateHelmClientSetupDetail(
|
|||||||
registryRef string,
|
registryRef string,
|
||||||
image *artifact.ArtifactParam,
|
image *artifact.ArtifactParam,
|
||||||
tag *artifact.VersionParam,
|
tag *artifact.VersionParam,
|
||||||
|
registryType artifact.RegistryType,
|
||||||
) *artifact.ClientSetupDetailsResponseJSONResponse {
|
) *artifact.ClientSetupDetailsResponseJSONResponse {
|
||||||
header1 := "Login to Helm"
|
header1 := "Login to Helm"
|
||||||
section1step1Header := "Run this Helm command in your terminal to authenticate the client."
|
section1step1Header := "Run this Helm command in your terminal to authenticate the client."
|
||||||
@ -368,14 +425,23 @@ func (c *APIController) generateHelmClientSetupDetail(
|
|||||||
_ = section3.FromClientSetupStepConfig(artifact.ClientSetupStepConfig{
|
_ = section3.FromClientSetupStepConfig(artifact.ClientSetupStepConfig{
|
||||||
Steps: §ion3Steps,
|
Steps: §ion3Steps,
|
||||||
})
|
})
|
||||||
clientSetupDetails := artifact.ClientSetupDetails{
|
|
||||||
MainHeader: "Helm Client Setup",
|
sections := []artifact.ClientSetupSection{
|
||||||
SecHeader: "Follow these instructions to install/use Helm artifacts or compatible packages.",
|
|
||||||
Sections: []artifact.ClientSetupSection{
|
|
||||||
section1,
|
section1,
|
||||||
section2,
|
section2,
|
||||||
section3,
|
section3,
|
||||||
},
|
}
|
||||||
|
if registryType == artifact.RegistryTypeUPSTREAM {
|
||||||
|
sections = []artifact.ClientSetupSection{
|
||||||
|
section1,
|
||||||
|
section3,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
clientSetupDetails := artifact.ClientSetupDetails{
|
||||||
|
MainHeader: "Helm Client Setup",
|
||||||
|
SecHeader: "Follow these instructions to install/use Helm artifacts or compatible packages.",
|
||||||
|
Sections: sections,
|
||||||
}
|
}
|
||||||
|
|
||||||
c.replacePlaceholders(ctx, &clientSetupDetails.Sections, username, registryRef, image, tag, "", "", "")
|
c.replacePlaceholders(ctx, &clientSetupDetails.Sections, username, registryRef, image, tag, "", "", "")
|
||||||
@ -392,6 +458,7 @@ func (c *APIController) generateMavenClientSetupDetail(
|
|||||||
version *artifact.VersionParam,
|
version *artifact.VersionParam,
|
||||||
registryRef string,
|
registryRef string,
|
||||||
username string,
|
username string,
|
||||||
|
registryType artifact.RegistryType,
|
||||||
) *artifact.ClientSetupDetailsResponseJSONResponse {
|
) *artifact.ClientSetupDetailsResponseJSONResponse {
|
||||||
staticStepType := artifact.ClientSetupStepTypeStatic
|
staticStepType := artifact.ClientSetupStepTypeStatic
|
||||||
generateTokenStepType := artifact.ClientSetupStepTypeGenerateToken
|
generateTokenStepType := artifact.ClientSetupStepTypeGenerateToken
|
||||||
@ -652,31 +719,35 @@ func (c *APIController) generateMavenClientSetupDetail(
|
|||||||
})
|
})
|
||||||
|
|
||||||
section2 := artifact.ClientSetupSection{}
|
section2 := artifact.ClientSetupSection{}
|
||||||
_ = section2.FromTabSetupStepConfig(artifact.TabSetupStepConfig{
|
config := artifact.TabSetupStepConfig{
|
||||||
Tabs: &[]artifact.TabSetupStep{
|
Tabs: &[]artifact.TabSetupStep{
|
||||||
{
|
{
|
||||||
Header: stringPtr("Maven"),
|
Header: stringPtr("Maven"),
|
||||||
Sections: &[]artifact.ClientSetupSection{
|
Sections: &[]artifact.ClientSetupSection{
|
||||||
mavenSection1,
|
mavenSection1,
|
||||||
mavenSection2,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Header: stringPtr("Gradle"),
|
Header: stringPtr("Gradle"),
|
||||||
Sections: &[]artifact.ClientSetupSection{
|
Sections: &[]artifact.ClientSetupSection{
|
||||||
gradleSection1,
|
gradleSection1,
|
||||||
gradleSection2,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Header: stringPtr("Sbt/Scala"),
|
Header: stringPtr("Sbt/Scala"),
|
||||||
Sections: &[]artifact.ClientSetupSection{
|
Sections: &[]artifact.ClientSetupSection{
|
||||||
sbtSection1,
|
sbtSection1,
|
||||||
sbtSection2,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
}
|
||||||
|
if registryType == artifact.RegistryTypeVIRTUAL {
|
||||||
|
for i, remoteSection := range []artifact.ClientSetupSection{mavenSection2, gradleSection2, sbtSection2} {
|
||||||
|
*(*config.Tabs)[i].Sections = append(*(*config.Tabs)[i].Sections, remoteSection)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = section2.FromTabSetupStepConfig(config)
|
||||||
|
|
||||||
clientSetupDetails := artifact.ClientSetupDetails{
|
clientSetupDetails := artifact.ClientSetupDetails{
|
||||||
MainHeader: "Maven Client Setup",
|
MainHeader: "Maven Client Setup",
|
||||||
@ -714,6 +785,7 @@ func (c *APIController) generatePythonClientSetupDetail(
|
|||||||
username string,
|
username string,
|
||||||
image *artifact.ArtifactParam,
|
image *artifact.ArtifactParam,
|
||||||
tag *artifact.VersionParam,
|
tag *artifact.VersionParam,
|
||||||
|
registryType artifact.RegistryType,
|
||||||
) *artifact.ClientSetupDetailsResponseJSONResponse {
|
) *artifact.ClientSetupDetailsResponseJSONResponse {
|
||||||
staticStepType := artifact.ClientSetupStepTypeStatic
|
staticStepType := artifact.ClientSetupStepTypeStatic
|
||||||
generateTokenType := artifact.ClientSetupStepTypeGenerateToken
|
generateTokenType := artifact.ClientSetupStepTypeGenerateToken
|
||||||
@ -784,14 +856,23 @@ func (c *APIController) generatePythonClientSetupDetail(
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
clientSetupDetails := artifact.ClientSetupDetails{
|
sections := []artifact.ClientSetupSection{
|
||||||
MainHeader: "Python Client Setup",
|
|
||||||
SecHeader: "Follow these instructions to install/use Python packages from this registry.",
|
|
||||||
Sections: []artifact.ClientSetupSection{
|
|
||||||
section1,
|
section1,
|
||||||
section2,
|
section2,
|
||||||
section3,
|
section3,
|
||||||
},
|
}
|
||||||
|
|
||||||
|
if registryType == artifact.RegistryTypeUPSTREAM {
|
||||||
|
sections = []artifact.ClientSetupSection{
|
||||||
|
section1,
|
||||||
|
section3,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
clientSetupDetails := artifact.ClientSetupDetails{
|
||||||
|
MainHeader: "Python Client Setup",
|
||||||
|
SecHeader: "Follow these instructions to install/use Python packages from this registry.",
|
||||||
|
Sections: sections,
|
||||||
}
|
}
|
||||||
|
|
||||||
registryURL := c.URLProvider.PackageURL(ctx, registryRef, "python")
|
registryURL := c.URLProvider.PackageURL(ctx, registryRef, "python")
|
||||||
|
Loading…
Reference in New Issue
Block a user