github.com/jfrog/jfrog-cli-core@v1.12.1/artifactory/commands/golang/gonative.go (about)

     1  package golang
     2  
     3  import (
     4  	"github.com/jfrog/jfrog-cli-core/artifactory/utils"
     5  	"github.com/jfrog/jfrog-cli-core/utils/config"
     6  	"github.com/jfrog/jfrog-client-go/utils/log"
     7  )
     8  
     9  type GoNativeCommand struct {
    10  	configFilePath string
    11  	GoCommand
    12  }
    13  
    14  func NewGoNativeCommand() *GoNativeCommand {
    15  	return &GoNativeCommand{GoCommand: *new(GoCommand)}
    16  }
    17  
    18  func (gnc *GoNativeCommand) SetConfigFilePath(configFilePath string) *GoNativeCommand {
    19  	gnc.configFilePath = configFilePath
    20  	return gnc
    21  }
    22  
    23  func (gnc *GoNativeCommand) SetArgs(args []string) *GoNativeCommand {
    24  	gnc.goArg = args
    25  	return gnc
    26  }
    27  
    28  func (gnc *GoNativeCommand) Run() error {
    29  	// Read config file.
    30  	log.Debug("Preparing to read the config file", gnc.configFilePath)
    31  	vConfig, err := utils.ReadConfigFile(gnc.configFilePath, utils.YAML)
    32  	if err != nil {
    33  		return err
    34  	}
    35  
    36  	// Extract resolution params.
    37  	gnc.resolverParams, err = utils.GetRepoConfigByPrefix(gnc.configFilePath, utils.ProjectConfigResolverPrefix, vConfig)
    38  	if err != nil {
    39  		return err
    40  	}
    41  
    42  	if vConfig.IsSet(utils.ProjectConfigDeployerPrefix) {
    43  		// Extract deployer params.
    44  		gnc.deployerParams, err = utils.GetRepoConfigByPrefix(gnc.configFilePath, utils.ProjectConfigDeployerPrefix, vConfig)
    45  		if err != nil {
    46  			return err
    47  		}
    48  		// Set to true for publishing dependencies.
    49  		gnc.SetPublishDeps(true)
    50  	}
    51  
    52  	// Extract build info information from the args.
    53  	gnc.goArg, gnc.buildConfiguration, err = utils.ExtractBuildDetailsFromArgs(gnc.goArg)
    54  	if err != nil {
    55  		return err
    56  	}
    57  	return gnc.GoCommand.Run()
    58  }
    59  
    60  func (gnc *GoNativeCommand) ServerDetails() (*config.ServerDetails, error) {
    61  	// If deployer Artifactory details exists, returs it.
    62  	if gnc.deployerParams != nil && !gnc.deployerParams.IsServerDetailsEmpty() {
    63  		return gnc.deployerParams.ServerDetails()
    64  	}
    65  
    66  	// If resolver Artifactory details exists, returs it.
    67  	if gnc.resolverParams != nil && !gnc.resolverParams.IsServerDetailsEmpty() {
    68  		return gnc.resolverParams.ServerDetails()
    69  	}
    70  
    71  	// If conf file exists, return the server configured in the conf file.
    72  	if gnc.configFilePath != "" {
    73  		vConfig, err := utils.ReadConfigFile(gnc.configFilePath, utils.YAML)
    74  		if err != nil {
    75  			return nil, err
    76  		}
    77  		return utils.GetServerDetails(vConfig)
    78  	}
    79  	return nil, nil
    80  }