예제 #1
1
func upload(c *cli.Context) {
	if c.NArg() < 2 || c.NArg() > 3 {
		cliutils.Exit(cliutils.ExitCodeError, "Wrong number of arguments. "+cliutils.GetDocumentationMessage())
	}
	localPath := c.Args().Get(0)
	versionDetails, err := utils.CreateVersionDetails(c.Args().Get(1))
	if err != nil {
		cliutils.Exit(cliutils.ExitCodeError, err.Error())
	}
	uploadPath := c.Args().Get(2)
	if strings.HasPrefix(uploadPath, "/") {
		uploadPath = uploadPath[1:]
	}

	uploadFlags, err := createUploadFlags(c)
	if err != nil {
		cliutils.Exit(cliutils.ExitCodeError, err.Error())
	}
	uploaded, failed, err := commands.Upload(versionDetails, localPath, uploadPath, uploadFlags)
	cliutils.ExitOnErr(err)
	if failed > 0 {
		if uploaded > 0 {
			cliutils.Exit(cliutils.ExitCodeWarning, "")
		}
		cliutils.Exit(cliutils.ExitCodeError, "")
	}
}
예제 #2
0
func searchCmd(c *cli.Context) {
	if c.NArg() > 0 && c.IsSet("spec") {
		cliutils.Exit(cliutils.ExitCodeError, "No arguments should be sent when the spec option is used. "+cliutils.GetDocumentationMessage())
	}
	if !(c.NArg() == 1 || (c.NArg() == 0 && c.IsSet("spec"))) {
		cliutils.Exit(cliutils.ExitCodeError, "Wrong number of arguments. "+cliutils.GetDocumentationMessage())
	}

	var searchSpec *utils.SpecFiles
	if c.IsSet("spec") {
		var err error
		searchSpec, err = getSearchSpec(c)
		cliutils.ExitOnErr(err)
	} else {
		searchSpec = createDefaultSearchSpec(c)
	}

	flags, err := createSearchFlags(c)
	cliutils.ExitOnErr(err)
	SearchResult, err := commands.Search(searchSpec, flags)
	cliutils.ExitOnErr(err)
	result, err := json.Marshal(SearchResult)
	cliutils.ExitOnErr(err)

	fmt.Println(string(cliutils.IndentJson(result)))
}
예제 #3
0
func logs(c *cli.Context) {
	bintrayDetails, err := createBintrayDetails(c, true)
	if err != nil {
		cliutils.Exit(cliutils.ExitCodeError, err.Error())
	}
	if c.NArg() == 1 {
		packageDetails, err := utils.CreatePackageDetails(c.Args().Get(0))
		cliutils.ExitOnErr(err)
		err = commands.LogsList(packageDetails, bintrayDetails)
		cliutils.ExitOnErr(err)
	} else if c.NArg() == 3 {
		if c.Args().Get(0) == "download" {
			packageDetails, err := utils.CreatePackageDetails(c.Args().Get(1))
			if err != nil {
				cliutils.Exit(cliutils.ExitCodeError, err.Error())
			}
			err = commands.DownloadLog(packageDetails, c.Args().Get(2), bintrayDetails)
			cliutils.ExitOnErr(err)
		} else {
			cliutils.Exit(cliutils.ExitCodeError, "Unkown argument "+c.Args().Get(0)+". "+cliutils.GetDocumentationMessage())
		}
	} else {
		cliutils.Exit(cliutils.ExitCodeError, "Wrong number of arguments. "+cliutils.GetDocumentationMessage())
	}
}
예제 #4
0
func uploadCmd(c *cli.Context) {
	if c.NArg() > 0 && c.IsSet("spec") {
		cliutils.Exit(cliutils.ExitCodeError, "No arguments should be sent when the spec option is used. "+cliutils.GetDocumentationMessage())
	}
	if !(c.NArg() == 2 || (c.NArg() == 0 && c.IsSet("spec"))) {
		cliutils.Exit(cliutils.ExitCodeError, "Wrong number of arguments. "+cliutils.GetDocumentationMessage())
	}

	var uploadSpec *utils.SpecFiles
	if c.IsSet("spec") {
		var err error
		uploadSpec, err = getUploadSpec(c)
		cliutils.ExitOnErr(err)
	} else {
		uploadSpec = createDefaultUploadSpec(c)
	}

	flags, err := createUploadFlags(c)
	cliutils.ExitOnErr(err)
	uploaded, failed, err := commands.Upload(uploadSpec, flags)
	cliutils.ExitOnErr(err)
	if failed > 0 {
		if uploaded > 0 {
			cliutils.Exit(cliutils.ExitCodeWarning, "")
		}
		cliutils.Exit(cliutils.ExitCodeError, "")
	}
}
예제 #5
0
func buildDistributeCmd(c *cli.Context) {
	if c.NArg() != 3 {
		cliutils.Exit(cliutils.ExitCodeError, "Wrong number of arguments. "+cliutils.GetDocumentationMessage())
	}
	buildDistributeFlags, err := createBuildDistributionFlags(c)
	if err != nil {
		cliutils.ExitOnErr(err)
	}
	err = commands.BuildDistribute(c.Args().Get(0), c.Args().Get(1), c.Args().Get(2), buildDistributeFlags)
	cliutils.ExitOnErr(err)
}
예제 #6
0
func deleteVersion(c *cli.Context) {
	if c.NArg() != 1 {
		cliutils.Exit(cliutils.ExitCodeError, "Wrong number of arguments. "+cliutils.GetDocumentationMessage())
	}
	versionDetails, err := utils.CreateVersionDetails(c.Args().Get(0))
	if err != nil {
		cliutils.Exit(cliutils.ExitCodeError, err.Error())
	}
	bintrayDetails, err := createBintrayDetails(c, true)
	if err != nil {
		cliutils.Exit(cliutils.ExitCodeError, err.Error())
	}

	if !c.Bool("quiet") {
		var confirm string
		fmt.Print("Delete version " + versionDetails.Version +
			" of package " + versionDetails.Package + "? (y/n): ")
		fmt.Scanln(&confirm)
		if !cliutils.ConfirmAnswer(confirm) {
			return
		}
	}
	err = commands.DeleteVersion(versionDetails, bintrayDetails)
	cliutils.ExitOnErr(err)
}
예제 #7
0
func buildPublishCmd(c *cli.Context) {
	vlidateBuildInfoArgument(c)
	buildInfoFlags, err := createBuildInfoFlags(c)
	cliutils.ExitOnErrWithMsg(err)
	err = commands.BuildPublish(c.Args().Get(0), c.Args().Get(1), buildInfoFlags)
	cliutils.ExitOnErr(err)
}
예제 #8
0
func configCmd(c *cli.Context) {
	if len(c.Args()) > 1 {
		cliutils.Exit(cliutils.ExitCodeError, "Wrong number of arguments. "+cliutils.GetDocumentationMessage())
	} else if len(c.Args()) == 1 {
		if c.Args()[0] == "show" {
			commands.ShowConfig()
		} else if c.Args()[0] == "clear" {
			commands.ClearConfig()
		} else {
			cliutils.Exit(cliutils.ExitCodeError, "Unknown argument '"+c.Args()[0]+"'. Available arguments are 'show' and 'clear'.")
		}
	} else {
		configFlags, err := createConfigFlags(c)
		cliutils.ExitOnErr(err)
		_, err = commands.Config(configFlags.ArtDetails, nil, configFlags.Interactive, configFlags.EncPassword)
		cliutils.ExitOnErr(err)
	}
}
예제 #9
0
func deleteCmd(c *cli.Context) {
	if c.NArg() > 0 && c.IsSet("spec") {
		cliutils.Exit(cliutils.ExitCodeError, "No arguments should be sent when the spec option is used. "+cliutils.GetDocumentationMessage())
	}
	if !(c.NArg() == 1 || (c.NArg() == 0 && c.IsSet("spec"))) {
		cliutils.Exit(cliutils.ExitCodeError, "Wrong number of arguments. "+cliutils.GetDocumentationMessage())
	}

	var deleteSpec *utils.SpecFiles
	if c.IsSet("spec") {
		var err error
		deleteSpec, err = getDeleteSpec(c)
		cliutils.ExitOnErr(err)
	} else {
		deleteSpec = createDefaultDeleteSpec(c)
	}

	flags, err := createDeleteFlags(c)
	cliutils.ExitOnErr(err)
	if !c.Bool("quiet") {
		pathsToDelete, err := commands.GetPathsToDelete(deleteSpec, flags)
		cliutils.ExitOnErr(err)
		if len(pathsToDelete) < 1 {
			return
		}
		for _, v := range pathsToDelete {
			fmt.Println("  " + v.GetFullUrl())
		}
		var confirm string
		fmt.Print("Are you sure you want to delete the above paths? (y/n): ")
		fmt.Scanln(&confirm)
		if !cliutils.ConfirmAnswer(confirm) {
			return
		}
		err = commands.DeleteFiles(pathsToDelete, flags)
		cliutils.ExitOnErr(err)
	} else {
		err = commands.Delete(deleteSpec, flags)
		cliutils.ExitOnErr(err)
	}
}
예제 #10
0
func copyCmd(c *cli.Context) {
	if c.NArg() > 0 && c.IsSet("spec") {
		cliutils.Exit(cliutils.ExitCodeError, "No arguments should be sent when the spec option is used. "+cliutils.GetDocumentationMessage())
	}
	if !(c.NArg() == 2 || (c.NArg() == 0 && c.IsSet("spec"))) {
		cliutils.Exit(cliutils.ExitCodeError, "Wrong number of arguments. "+cliutils.GetDocumentationMessage())
	}

	var copySpec *utils.SpecFiles
	if c.IsSet("spec") {
		var err error
		copySpec, err = getMoveSpec(c)
		cliutils.ExitOnErr(err)
	} else {
		copySpec = createDefaultMoveSpec(c)
	}

	flags, err := createMoveFlags(c)
	cliutils.ExitOnErr(err)
	err = commands.Copy(copySpec, flags)
	cliutils.ExitOnErr(err)
}
예제 #11
0
func downloadVersion(c *cli.Context) {
	if c.NArg() < 1 || c.NArg() > 2 {
		cliutils.Exit(cliutils.ExitCodeError, "Wrong number of arguments. "+cliutils.GetDocumentationMessage())
	}
	versionDetails, err := commands.CreateVersionDetailsForDownloadVersion(c.Args().Get(0))
	cliutils.ExitOnErr(err)
	targetPath := c.Args().Get(1)
	if strings.HasPrefix(targetPath, "/") {
		targetPath = targetPath[1:]
	}
	flags, err := createDownloadFlags(c)
	if err != nil {
		cliutils.Exit(cliutils.ExitCodeError, err.Error())
	}
	downloaded, failed, err := commands.DownloadVersion(versionDetails, targetPath, flags)
	cliutils.ExitOnErr(err)
	if failed > 0 {
		if downloaded > 0 {
			cliutils.Exit(cliutils.ExitCodeWarning, "")
		}
		cliutils.Exit(cliutils.ExitCodeError, "")
	}
}
예제 #12
0
func handleEntitlements(c *cli.Context) {
	if c.NArg() == 0 {
		cliutils.Exit(cliutils.ExitCodeError, "Wrong number of arguments. "+cliutils.GetDocumentationMessage())
	}
	if c.NArg() == 1 {
		bintrayDetails, err := createBintrayDetails(c, true)
		cliutils.ExitOnErr(err)
		details, err := entitlements.CreateVersionDetails(c.Args().Get(0))
		cliutils.ExitOnErr(err)
		err = entitlements.ShowEntitlements(bintrayDetails, details)
		cliutils.ExitOnErr(err)
		return
	}
	if c.NArg() != 2 {
		cliutils.Exit(cliutils.ExitCodeError, "Wrong number of arguments. "+cliutils.GetDocumentationMessage())
	}
	details, err := entitlements.CreateVersionDetails(c.Args().Get(1))
	cliutils.ExitOnErr(err)

	var flags *entitlements.EntitlementFlags
	switch c.Args().Get(0) {
	case "show":
		flags, err = createEntitlementFlagsForShowAndDelete(c)
		cliutils.ExitOnErr(err)
		err = entitlements.ShowEntitlement(flags, details)
	case "create":
		flags, err = createEntitlementFlagsForCreate(c)
		cliutils.ExitOnErr(err)
		err = entitlements.CreateEntitlement(flags, details)
	case "update":
		flags, err = createEntitlementFlagsForUpdate(c)
		cliutils.ExitOnErr(err)
		err = entitlements.UpdateEntitlement(flags, details)
	case "delete":
		flags, err = createEntitlementFlagsForShowAndDelete(c)
		cliutils.ExitOnErr(err)
		err = entitlements.DeleteEntitlement(flags, details)
	default:
		cliutils.Exit(cliutils.ExitCodeError, "Expecting show, create, update or delete before "+c.Args().Get(1)+". Got "+c.Args().Get(0))
	}
	cliutils.ExitOnErr(err)
}
예제 #13
0
func updatePackage(c *cli.Context) {
	if c.NArg() != 1 {
		cliutils.Exit(cliutils.ExitCodeError, "Wrong number of arguments. "+cliutils.GetDocumentationMessage())
	}
	packageDetails, err := utils.CreatePackageDetails(c.Args().Get(0))
	if err != nil {
		cliutils.Exit(cliutils.ExitCodeError, err.Error())
	}
	packageFlags, err := createPackageFlags(c)
	if err != nil {
		cliutils.Exit(cliutils.ExitCodeError, err.Error())
	}
	err = commands.UpdatePackage(packageDetails, packageFlags)
	cliutils.ExitOnErr(err)
}
예제 #14
0
func gpgSignVersion(c *cli.Context) {
	if c.NArg() != 1 {
		cliutils.Exit(cliutils.ExitCodeError, "Wrong number of arguments. "+cliutils.GetDocumentationMessage())
	}
	versionDetails, err := utils.CreateVersionDetails(c.Args().Get(0))
	if err != nil {
		cliutils.Exit(cliutils.ExitCodeError, err.Error())
	}
	flags, err := createBintrayDetails(c, true)
	if err != nil {
		cliutils.Exit(cliutils.ExitCodeError, err.Error())
	}
	err = commands.GpgSignVersion(versionDetails, c.String("passphrase"), flags)
	cliutils.ExitOnErr(err)
}
예제 #15
0
func signUrl(c *cli.Context) {
	if c.NArg() != 1 {
		cliutils.Exit(cliutils.ExitCodeError, "Wrong number of arguments. "+cliutils.GetDocumentationMessage())
	}
	urlSigningDetails, err := utils.CreatePathDetails(c.Args().Get(0))
	if err != nil {
		cliutils.Exit(cliutils.ExitCodeError, err.Error())
	}
	urlSigningFlags, err := createUrlSigningFlags(c)
	if err != nil {
		cliutils.Exit(cliutils.ExitCodeError, err.Error())
	}
	err = commands.SignVersion(urlSigningDetails, urlSigningFlags)
	cliutils.ExitOnErr(err)
}
예제 #16
0
func publishVersion(c *cli.Context) {
	if c.NArg() != 1 {
		cliutils.Exit(cliutils.ExitCodeError, "Wrong number of arguments. "+cliutils.GetDocumentationMessage())
	}
	versionDetails, err := utils.CreateVersionDetails(c.Args().Get(0))
	if err != nil {
		cliutils.Exit(cliutils.ExitCodeError, err.Error())
	}
	bintrayDetails, err := createBintrayDetails(c, true)
	if err != nil {
		cliutils.Exit(cliutils.ExitCodeError, err.Error())
	}
	err = commands.PublishVersion(versionDetails, bintrayDetails)
	cliutils.ExitOnErr(err)
}
예제 #17
0
func createVersion(c *cli.Context) {
	if c.NArg() != 1 {
		cliutils.Exit(cliutils.ExitCodeError, "Wrong number of arguments "+cliutils.GetDocumentationMessage())
	}
	versionDetails, err := utils.CreateVersionDetails(c.Args().Get(0))
	if err != nil {
		cliutils.Exit(cliutils.ExitCodeError, err.Error())
	}
	versionFlags, err := createVersionFlags(c, "")
	if err != nil {
		cliutils.Exit(cliutils.ExitCodeError, err.Error())
	}
	err = commands.CreateVersion(versionDetails, versionFlags)
	cliutils.ExitOnErr(err)
}
예제 #18
0
func downloadFile(c *cli.Context) {
	if c.NArg() < 1 || c.NArg() > 2 {
		cliutils.Exit(cliutils.ExitCodeError, "Wrong number of arguments. "+cliutils.GetDocumentationMessage())
	}
	pathDetails, err := utils.CreatePathDetails(c.Args().Get(0))
	if err != nil {
		cliutils.Exit(cliutils.ExitCodeError, err.Error())
	}
	targetPath := c.Args().Get(1)
	if strings.HasPrefix(targetPath, "/") {
		targetPath = targetPath[1:]
	}

	flags, err := createDownloadFlags(c)
	if err != nil {
		cliutils.Exit(cliutils.ExitCodeError, err.Error())
	}
	err = commands.DownloadFile(pathDetails, targetPath, flags)
	cliutils.ExitOnErr(err)
}
예제 #19
0
func offerConfig(c *cli.Context) (*config.BintrayDetails, error) {
	exists, err := config.IsBintrayConfExists()
	if err != nil {
		return nil, err
	}
	if exists {
		return nil, nil
	}
	val, err := cliutils.GetBoolEnvValue("JFROG_CLI_OFFER_CONFIG", true)
	if err != nil {
		return nil, err
	}
	if !val {
		config.SaveBintrayConf(new(config.BintrayDetails))
		return nil, nil
	}
	msg := "Some CLI commands require the following common options:\n" +
		"- User\n" +
		"- API Key\n" +
		"- Default Package Licenses\n" +
		"Configuring JFrog CLI with these parameters now will save you having to include them as command options.\n" +
		"You can also configure these parameters later using the 'config' command.\n" +
		"Configure now? (y/n): "
	fmt.Print(msg)
	var confirm string
	fmt.Scanln(&confirm)
	if !cliutils.ConfirmAnswer(confirm) {
		config.SaveBintrayConf(new(config.BintrayDetails))
		return nil, nil
	}
	bintrayDetails, err := createBintrayDetails(c, false)
	if err != nil {
		return nil, err
	}
	details, err := commands.Config(nil, bintrayDetails, true)
	cliutils.ExitOnErr(err)
	details.ApiUrl = bintrayDetails.ApiUrl
	details.DownloadServerUrl = bintrayDetails.DownloadServerUrl
	return details, nil
}
예제 #20
0
func configure(c *cli.Context) {
	if c.NArg() > 1 {
		cliutils.Exit(cliutils.ExitCodeError, "Wrong number of arguments. "+cliutils.GetDocumentationMessage())
	} else if c.NArg() == 1 {
		if c.Args().Get(0) == "show" {
			commands.ShowConfig()
		} else if c.Args().Get(0) == "clear" {
			commands.ClearConfig()
		} else {
			cliutils.Exit(cliutils.ExitCodeError, "Unknown argument '"+c.Args().Get(0)+"'. Available arguments are 'show' and 'clear'.")
		}
	} else {
		interactive := cliutils.GetBoolFlagValue(c, "interactive", true)
		if !interactive {
			if c.String("user") == "" || c.String("key") == "" {
				cliutils.Exit(cliutils.ExitCodeError, "The --user and --key options are mandatory when the --interactive option is set to false")
			}
		}
		bintrayDetails, err := createBintrayDetails(c, false)
		cliutils.ExitOnErr(err)
		commands.Config(bintrayDetails, nil, interactive)
	}
}
예제 #21
0
func accessKeys(c *cli.Context) {
	org := c.String("org")
	if c.NArg() == 0 {
		bintrayDetails, err := createBintrayDetails(c, true)
		cliutils.ExitOnErr(err)
		err = commands.ShowAccessKeys(bintrayDetails, org)
		cliutils.ExitOnErr(err)
		return
	}
	if c.NArg() != 2 {
		cliutils.Exit(cliutils.ExitCodeError, "Wrong number of arguments. "+cliutils.GetDocumentationMessage())
	}
	keyId := c.Args().Get(1)
	var flags *commands.AccessKeyFlags
	var err error
	switch c.Args().Get(0) {
	case "show":
		flags, err = createAccessKeyFlagsForShowAndDelete(keyId, c)
		cliutils.ExitOnErr(err)
		err = commands.ShowAccessKey(flags, org)
	case "create":
		flags, err = createAccessKeyFlagsForCreateAndUpdate(keyId, c)
		cliutils.ExitOnErr(err)
		err = commands.CreateAccessKey(flags, org)
	case "update":
		flags, err = createAccessKeyFlagsForCreateAndUpdate(keyId, c)
		cliutils.ExitOnErr(err)
		err = commands.UpdateAccessKey(flags, org)
	case "delete":
		flags, err = createAccessKeyFlagsForShowAndDelete(keyId, c)
		cliutils.ExitOnErr(err)
		err = commands.DeleteAccessKey(flags, org)
	default:
		cliutils.Exit(cliutils.ExitCodeError, "Expecting show, create, update or delete before the key argument. Got "+c.Args().Get(0))
	}
	cliutils.ExitOnErr(err)
}
예제 #22
0
func buildCleanCmd(c *cli.Context) {
	vlidateBuildInfoArgument(c)
	err := commands.BuildClean(c.Args().Get(0), c.Args().Get(1))
	cliutils.ExitOnErr(err)
}