mirror of https://github.com/harness/drone.git
feat: [CDE-573]: refactor to reduce number of utils. (#3208)
* feat: [CDE-573]: refactor to reduce number of utils. * feat: [CDE-573]: refactor to reduce number of utils.BT-10437
parent
5d17af97d3
commit
de86d126a5
|
@ -419,8 +419,8 @@ func (e *EmbeddedDockerOrchestrator) runGitspaceSetupSteps(
|
|||
gitspaceLogger.Info(fmt.Sprintf("Setting Environment : %v", environment))
|
||||
}
|
||||
|
||||
containerUser := getContainerUser(runArgsMap, devcontainerConfig, metadataFromImage, imageUser)
|
||||
remoteUser := getRemoteUser(devcontainerConfig, metadataFromImage, containerUser)
|
||||
containerUser := GetContainerUser(runArgsMap, devcontainerConfig, metadataFromImage, imageUser)
|
||||
remoteUser := GetRemoteUser(devcontainerConfig, metadataFromImage, containerUser)
|
||||
|
||||
homeDir := GetUserHomeDir(remoteUser)
|
||||
|
||||
|
@ -722,38 +722,6 @@ func (e *EmbeddedDockerOrchestrator) flushLogStream(logStreamInstance *logutil.L
|
|||
}
|
||||
}
|
||||
|
||||
func getRemoteUser(
|
||||
devcontainerConfig types.DevcontainerConfig,
|
||||
metadataFromImage map[string]any,
|
||||
containerUser string,
|
||||
) string {
|
||||
if devcontainerConfig.RemoteUser != "" {
|
||||
return devcontainerConfig.RemoteUser
|
||||
}
|
||||
if remoteUser, ok := metadataFromImage["remoteUser"].(string); ok {
|
||||
return remoteUser
|
||||
}
|
||||
return containerUser
|
||||
}
|
||||
|
||||
func getContainerUser(
|
||||
runArgsMap map[types.RunArg]*types.RunArgValue,
|
||||
devcontainerConfig types.DevcontainerConfig,
|
||||
metadataFromImage map[string]any,
|
||||
imageUser string,
|
||||
) string {
|
||||
if containerUser := getUser(runArgsMap); containerUser != "" {
|
||||
return containerUser
|
||||
}
|
||||
if devcontainerConfig.ContainerUser != "" {
|
||||
return devcontainerConfig.ContainerUser
|
||||
}
|
||||
if containerUser, ok := metadataFromImage["containerUser"].(string); ok {
|
||||
return containerUser
|
||||
}
|
||||
return imageUser
|
||||
}
|
||||
|
||||
func getImage(devcontainerConfig types.DevcontainerConfig, defaultBaseImage string) string {
|
||||
imageName := devcontainerConfig.Image
|
||||
if imageName == "" {
|
||||
|
|
|
@ -44,6 +44,38 @@ func GetUserHomeDir(userIdentifier string) string {
|
|||
return filepath.Join(linuxHome, userIdentifier)
|
||||
}
|
||||
|
||||
func GetContainerUser(
|
||||
runArgsMap map[types.RunArg]*types.RunArgValue,
|
||||
devcontainerConfig types.DevcontainerConfig,
|
||||
metadataFromImage map[string]any,
|
||||
imageUser string,
|
||||
) string {
|
||||
if containerUser := getUser(runArgsMap); containerUser != "" {
|
||||
return containerUser
|
||||
}
|
||||
if devcontainerConfig.ContainerUser != "" {
|
||||
return devcontainerConfig.ContainerUser
|
||||
}
|
||||
if containerUser, ok := metadataFromImage["containerUser"].(string); ok {
|
||||
return containerUser
|
||||
}
|
||||
return imageUser
|
||||
}
|
||||
|
||||
func GetRemoteUser(
|
||||
devcontainerConfig types.DevcontainerConfig,
|
||||
metadataFromImage map[string]any,
|
||||
containerUser string,
|
||||
) string {
|
||||
if devcontainerConfig.RemoteUser != "" {
|
||||
return devcontainerConfig.RemoteUser
|
||||
}
|
||||
if remoteUser, ok := metadataFromImage["remoteUser"].(string); ok {
|
||||
return remoteUser
|
||||
}
|
||||
return containerUser
|
||||
}
|
||||
|
||||
func ExtractRemoteUserFromLabels(inspectResp dockerTypes.ContainerJSON) string {
|
||||
remoteUser := deprecatedRemoteUser
|
||||
|
||||
|
|
Loading…
Reference in New Issue