Skip to content
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
9 changes: 7 additions & 2 deletions pkg/app/AppListingViewBuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package app

import (
"errors"
"github.com/devtron-labs/devtron/api/bean"
"github.com/devtron-labs/devtron/internal/sql/repository/helper"
"go.uber.org/zap"
Expand Down Expand Up @@ -60,12 +61,16 @@ func (impl *AppListingViewBuilderImpl) BuildView(fetchAppListingRequest FetchApp

var appContainersResponses []*bean.AppContainer
for k, v := range filteredAppEnvMap {
appId, err := strconv.Atoi(strings.Split(k, "_")[0])
appIdAndName := strings.Split(k, "_")
if len(appIdAndName) != 2 {
return []*bean.AppContainer{}, errors.New("invalid format for app id and name. It should be in format <appId>_<appName>")
}
appId, err := strconv.Atoi(appIdAndName[0])
if err != nil {
impl.Logger.Error("err", err)
return []*bean.AppContainer{}, nil
}
appName := strings.Split(k, "_")[1]
appName := appIdAndName[1]
defaultEnv := bean.AppEnvironmentContainer{}
projectId := 0
for _, env := range v {
Expand Down
6 changes: 5 additions & 1 deletion pkg/auth/user/UserService.go
Original file line number Diff line number Diff line change
Expand Up @@ -1244,7 +1244,11 @@ func (impl *UserServiceImpl) GetUserByToken(context context.Context, token strin
}

func (impl *UserServiceImpl) CheckIfTokenIsValid(email string, version string) error {
tokenName := userHelper.ExtractTokenNameFromEmail(email)
tokenName, err := userHelper.ExtractTokenNameFromEmail(email)
if err != nil {
impl.logger.Errorw("error in extracting token name from email", "email", email, "error", err)
return err
}
embeddedTokenVersion, _ := strconv.Atoi(version)
isProvidedTokenValid, err := impl.userRepository.CheckIfTokenExistsByTokenNameAndVersion(tokenName, embeddedTokenVersion)
if err != nil || !isProvidedTokenValid {
Expand Down
9 changes: 7 additions & 2 deletions pkg/auth/user/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package helper

import (
"errors"
"fmt"
bean2 "github.com/devtron-labs/devtron/api/bean"
"github.com/devtron-labs/devtron/internal/util"
Expand Down Expand Up @@ -65,8 +66,12 @@ func CheckIfUserIdsExists(userIds []int32) error {
return nil
}

func ExtractTokenNameFromEmail(email string) string {
return strings.Split(email, ":")[1]
func ExtractTokenNameFromEmail(email string) (string, error) {
splitData := strings.Split(email, ":")
if splitData == nil || len(splitData) != 2 {
return "", errors.New("invalid apitoken format")
}
return splitData[1], nil
}

func CreateErrorMessageForUserRoleGroups(restrictedGroups []bean2.RestrictedGroup) (string, string) {
Expand Down
16 changes: 13 additions & 3 deletions pkg/pipeline/pipelineStageVariableParser.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,14 @@ func (impl *PluginInputVariableParserImpl) HandleCopyContainerImagePluginInputVa
dockerImageTag = pluginTriggerImageSplit[len(pluginTriggerImageSplit)-1]
}

registryRepoMapping := impl.getRegistryRepoMapping(DestinationInfo)
registryRepoMapping, err := impl.getRegistryRepoMapping(DestinationInfo)
if err != nil {
impl.logger.Errorw("error in getting registry repo mapping", "DestinationInfo", DestinationInfo, "err", err)
return nil, nil, err
}
registryCredentials, err = impl.getRegistryDetails(registryRepoMapping, sourceImageDockerRegistry)
if err != nil {
impl.logger.Errorw("error in getting registry details", "err", err)
return nil, nil, err
}
registryDestinationImageMap = impl.getRegistryDestinationImageMapping(registryRepoMapping, dockerImageTag, registryCredentials)
Expand All @@ -108,7 +113,7 @@ func (impl *PluginInputVariableParserImpl) HandleCopyContainerImagePluginInputVa
return registryDestinationImageMap, registryCredentials, nil
}

func (impl *PluginInputVariableParserImpl) getRegistryRepoMapping(destinationInfo string) map[string][]string {
func (impl *PluginInputVariableParserImpl) getRegistryRepoMapping(destinationInfo string) (map[string][]string, error) {
/*
creating map with registry as key and list of repositories in that registry where we need to copy image
destinationInfo format (each registry detail is separated by new line) :
Expand All @@ -119,6 +124,11 @@ func (impl *PluginInputVariableParserImpl) getRegistryRepoMapping(destinationInf
destinationRegistryRepoDetails := strings.Split(destinationInfo, "\n")
for _, detail := range destinationRegistryRepoDetails {
registryRepoSplit := strings.Split(detail, "|")
if len(registryRepoSplit) != 2 {
impl.logger.Errorw("invalid destination info format", "destinationInfo", destinationInfo)
// skipping for invalid format
return destinationRegistryRepositoryMap, errors.New("invalid destination info format. Please provide it in <registry-1> | <repo1>,<repo2>")
}
registryName := strings.Trim(registryRepoSplit[0], EMPTY_STRING)
repositoryValuesSplit := strings.Split(registryRepoSplit[1], ",")
var repositories []string
Expand All @@ -128,7 +138,7 @@ func (impl *PluginInputVariableParserImpl) getRegistryRepoMapping(destinationInf
}
destinationRegistryRepositoryMap[registryName] = repositories
}
return destinationRegistryRepositoryMap
return destinationRegistryRepositoryMap, nil
}

func (impl *PluginInputVariableParserImpl) getRegistryDetails(destinationRegistryRepositoryMap map[string][]string, sourceRegistry string) (map[string]bean2.RegistryCredentials, error) {
Expand Down
Loading