github.com/jfrog/jfrog-cli-core/v2@v2.51.0/artifactory/commands/container/containermanagercommand.go (about)

     1  package container
     2  
     3  import (
     4  	"github.com/jfrog/jfrog-cli-core/v2/artifactory/utils/container"
     5  	"github.com/jfrog/jfrog-cli-core/v2/utils/config"
     6  )
     7  
     8  // General utils for docker/podman commands
     9  type ContainerCommand struct {
    10  	ContainerCommandBase
    11  	skipLogin            bool
    12  	cmdParams            []string
    13  	containerManagerType container.ContainerManagerType
    14  }
    15  
    16  func NewContainerManagerCommand(containerManagerType container.ContainerManagerType) *ContainerCommand {
    17  	return &ContainerCommand{
    18  		containerManagerType: containerManagerType,
    19  	}
    20  }
    21  
    22  func (cm *ContainerCommand) SetSkipLogin(skipLogin bool) *ContainerCommand {
    23  	cm.skipLogin = skipLogin
    24  	return cm
    25  }
    26  
    27  func (cm *ContainerCommand) SetCmdParams(cmdParams []string) *ContainerCommand {
    28  	cm.cmdParams = cmdParams
    29  	return cm
    30  }
    31  
    32  func (cm *ContainerCommand) PerformLogin(serverDetails *config.ServerDetails, containerManagerType container.ContainerManagerType) error {
    33  	if !cm.skipLogin {
    34  		// Exclude refreshable tokens when working with external tools (build tools, curl, etc)
    35  		// Otherwise refresh Token may be expireted and docker login will fail.
    36  		if serverDetails.ServerId != "" {
    37  			var err error
    38  			serverDetails, err = config.GetSpecificConfig(serverDetails.ServerId, true, true)
    39  			if err != nil {
    40  				return err
    41  			}
    42  		}
    43  		loginConfig := &container.ContainerManagerLoginConfig{ServerDetails: serverDetails}
    44  		return container.ContainerManagerLogin(cm.image, loginConfig, containerManagerType)
    45  	}
    46  	return nil
    47  }