Example #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, "")
	}
}
Example #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)))
}
Example #3
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, "")
	}
}
Example #4
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())
	}
}
Example #5
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)
}
Example #6
0
func getOfflineUpdatesFlag(c *cli.Context) (flags *commands.OfflineUpdatesFlags, err error) {
	flags = new(commands.OfflineUpdatesFlags)
	flags.License = c.String("license-id")
	if len(flags.License) < 1 {
		cliutils.Exit(cliutils.ExitCodeError, "The --license-id option is mandatory")
	}
	from := c.String("from")
	to := c.String("to")
	if len(to) > 0 && len(from) < 1 {
		cliutils.Exit(cliutils.ExitCodeError, "The --from option is mandatory, when the --to option is sent.")
	}
	if len(from) > 0 && len(to) < 1 {
		cliutils.Exit(cliutils.ExitCodeError, "The --to option is mandatory, when the --from option is sent.")
	}
	if len(from) > 0 && len(to) > 0 {
		flags.From, err = dateToMilliseconds(from)
		cliutils.CheckError(err)
		if err != nil {
			return
		}
		flags.To, err = dateToMilliseconds(to)
		cliutils.CheckError(err)
	}
	return
}
Example #7
0
func offlineUpdates(c *cli.Context) {
	offlineUpdateFlags, err := getOfflineUpdatesFlag(c)
	if err != nil {
		cliutils.Exit(cliutils.ExitCodeError, err.Error())
	}
	err = commands.OfflineUpdate(offlineUpdateFlags)
	if err != nil {
		cliutils.Exit(cliutils.ExitCodeError, err.Error())
	}
}
Example #8
0
func addInstance(c *cli.Context) {
	size := len(c.Args())
	if size != 1 {
		cliutils.Exit(cliutils.ExitCodeError, "Wrong number of arguments. "+cliutils.GetDocumentationMessage())
	}
	addInstanceFlags, err := createAddInstanceFlag(c)
	if err != nil {
		cliutils.Exit(cliutils.ExitCodeError, err.Error())
	}
	rtinstances.AddInstance(c.Args()[0], addInstanceFlags)
}
Example #9
0
func detachLicense(c *cli.Context) {
	size := len(c.Args())
	if size != 1 {
		cliutils.Exit(cliutils.ExitCodeError, "Wrong number of arguments. "+cliutils.GetDocumentationMessage())
	}
	flags, err := createDetachLicFlags(c)
	if err != nil {
		cliutils.Exit(cliutils.ExitCodeError, err.Error())
	}
	rtinstances.DetachLic(c.Args()[0], flags)
}
Example #10
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)
}
Example #11
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)
}
Example #12
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)
}
Example #13
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)
}
Example #14
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)
}
Example #15
0
func getSplitCountFlag(c *cli.Context) int {
	if c.String("split-count") == "" {
		return 3
	}
	splitCount, err := strconv.Atoi(c.String("split-count"))
	if err != nil {
		cliutils.Exit(cliutils.ExitCodeError, "The '--split-count' option should have a numeric value. Try 'art download --help'.")
	}
	if splitCount > 15 {
		cliutils.Exit(cliutils.ExitCodeError, "The '--split-count' option value is limitted to a maximum of 15.")
	}
	if splitCount < 0 {
		cliutils.Exit(cliutils.ExitCodeError, "The '--split-count' option cannot have a negative value.")
	}
	return splitCount
}
Example #16
0
func getDebFlag(c *cli.Context) (deb string) {
	deb = c.String("deb")
	if deb != "" && len(strings.Split(deb, "/")) != 3 {
		cliutils.Exit(cliutils.ExitCodeError, "The --deb option should be in the form of distribution/component/architecture")
	}
	return deb
}
Example #17
0
func getSplitCount(c *cli.Context) (splitCount int) {
	var err error
	splitCount = 3
	if c.String("split-count") != "" {
		splitCount, err = strconv.Atoi(c.String("split-count"))
		if err != nil {
			cliutils.Exit(cliutils.ExitCodeError, "The '--split-count' option should have a numeric value. "+cliutils.GetDocumentationMessage())
		}
		if splitCount > 15 {
			cliutils.Exit(cliutils.ExitCodeError, "The '--split-count' option value is limitted to a maximum of 15.")
		}
		if splitCount < 0 {
			cliutils.Exit(cliutils.ExitCodeError, "The '--split-count' option cannot have a negative value.")
		}
	}
	return
}
Example #18
0
func configure(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 {
		flags, err := createConfigFlags(c)
		cliutils.ExitOnErr(err)
		commands.Config(flags.MissionControlDetails, nil, flags.Interactive)
	}
}
Example #19
0
func createAttachLicFlags(c *cli.Context) (flags *rtinstances.AttachLicFlags, err error) {
	flags = new(rtinstances.AttachLicFlags)
	flags.MissionControlDetails, err = createMissionControlDetails(c, true)
	if err != nil {
		return
	}
	flags.LicensePath = c.String("license-path")
	if strings.HasSuffix(flags.LicensePath, ioutils.GetFileSeperator()) {
		cliutils.Exit(cliutils.ExitCodeError, "The --license-path option cannot be a directory")
	}
	if flags.BucketId = c.String("bucket-id"); flags.BucketId == "" {
		cliutils.Exit(cliutils.ExitCodeError, "The --bucket-id option is mandatory")
	}
	flags.Override = cliutils.GetBoolFlagValue(c, "override", false)
	flags.Deploy = cliutils.GetBoolFlagValue(c, "deploy", false)
	flags.NodeId = c.String("node-id")
	return
}
Example #20
0
func createEntitlementFlagsForUpdate(c *cli.Context) (*entitlements.EntitlementFlags, error) {
	if c.String("id") == "" {
		cliutils.Exit(cliutils.ExitCodeError, "Please add the --id option")
	}
	if c.String("access") == "" {
		cliutils.Exit(cliutils.ExitCodeError, "Please add the --access option")
	}
	details, err := createBintrayDetails(c, true)
	if err != nil {
		return nil, err
	}
	return &entitlements.EntitlementFlags{
		BintrayDetails: details,
		Id:             c.String("id"),
		Path:           c.String("path"),
		Access:         c.String("access"),
		Keys:           c.String("keys")}, nil
}
Example #21
0
func createPackageFlags(c *cli.Context) (*utils.PackageFlags, error) {
	var publicDownloadNumbers string
	var publicStats string
	if c.String("pub-dn") != "" {
		publicDownloadNumbers = c.String("pub-dn")
		publicDownloadNumbers = strings.ToLower(publicDownloadNumbers)
		if publicDownloadNumbers != "true" && publicDownloadNumbers != "false" {
			cliutils.Exit(cliutils.ExitCodeError, "The --pub-dn option should have a boolean value.")
		}
	}
	if c.String("pub-stats") != "" {
		publicStats = c.String("pub-stats")
		publicStats = strings.ToLower(publicStats)
		if publicStats != "true" && publicStats != "false" {
			cliutils.Exit(cliutils.ExitCodeError, "The --pub-stats option should have a boolean value.")
		}
	}
	licenses := c.String("licenses")
	if licenses == "" {
		confDetails, err := commands.GetConfig()
		if err != nil {
			return nil, err
		}
		licenses = confDetails.DefPackageLicenses
	}
	details, err := createBintrayDetails(c, true)
	if err != nil {
		return nil, err
	}
	return &utils.PackageFlags{
		BintrayDetails:         details,
		Desc:                   c.String("desc"),
		Labels:                 c.String("labels"),
		Licenses:               licenses,
		CustomLicenses:         c.String("cust-licenses"),
		VcsUrl:                 c.String("vcs-url"),
		WebsiteUrl:             c.String("website-url"),
		IssueTrackerUrl:        c.String("issuetracker-url"),
		GithubRepo:             c.String("github-repo"),
		GithubReleaseNotesFile: c.String("github-rel-notes"),
		PublicDownloadNumbers:  publicDownloadNumbers,
		PublicStats:            publicStats}, nil
}
Example #22
0
func createArtifactoryDetailsByFlags(c *cli.Context, includeConfig bool) (*config.ArtifactoryDetails, error) {
	artDetails, err := createArtifactoryDetails(c, includeConfig)
	if err != nil {
		return nil, err
	}
	if artDetails.Url == "" {
		cliutils.Exit(cliutils.ExitCodeError, "The --url option is mandatory")
	}
	return artDetails, nil
}
Example #23
0
func getMinSplitFlag(c *cli.Context) int64 {
	if c.String("min-split") == "" {
		return 5120
	}
	minSplit, err := strconv.ParseInt(c.String("min-split"), 10, 64)
	if err != nil {
		cliutils.Exit(cliutils.ExitCodeError, "The '--min-split' option should have a numeric value. "+cliutils.GetDocumentationMessage())
	}
	return minSplit
}
Example #24
0
func stream(c *cli.Context) {
	bintrayDetails, err := createBintrayDetails(c, true)
	if err != nil {
		cliutils.Exit(cliutils.ExitCodeError, err.Error())
	}
	if c.NArg() != 1 {
		cliutils.Exit(cliutils.ExitCodeError, "Wrong number of arguments. "+cliutils.GetDocumentationMessage())
	}

	streamDetails := &commands.StreamDetails{
		BintrayDetails: bintrayDetails,
		Subject:        c.Args().Get(0),
		Include:        c.String("include"),
	}
	err = commands.Stream(streamDetails, os.Stdout)
	if err != nil {
		cliutils.Exit(cliutils.ExitCodeError, "")
	}
}
Example #25
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)
}
Example #26
0
func getMinSplit(c *cli.Context) (minSplitSize int64) {
	minSplitSize = 5120
	var err error
	if c.String("min-split") != "" {
		minSplitSize, err = strconv.ParseInt(c.String("min-split"), 10, 64)
		if err != nil {
			cliutils.Exit(cliutils.ExitCodeError, "The '--min-split' option should have a numeric value. "+cliutils.GetDocumentationMessage())
		}
	}
	return
}
Example #27
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)
}
Example #28
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)
}
Example #29
0
func removeInstance(c *cli.Context) {
	size := len(c.Args())
	if size != 1 {
		cliutils.Exit(cliutils.ExitCodeError, "Wrong number of arguments. "+cliutils.GetDocumentationMessage())
	}
	instanceName := c.Args()[0]
	if !c.Bool("quiet") {
		var confirm string
		fmt.Print("Remove Instance,  " + instanceName + "? (y/n): ")
		fmt.Scanln(&confirm)
		if !cliutils.ConfirmAnswer(confirm) {
			return
		}
	}
	flags, err := createRemoveInstanceFlags(c)
	if err != nil {
		cliutils.Exit(cliutils.ExitCodeError, err.Error())
	}
	rtinstances.Remove(instanceName, flags)
}
Example #30
0
func createAddInstanceFlag(c *cli.Context) (flags *rtinstances.AddInstanceFlags, err error) {
	flags = new(rtinstances.AddInstanceFlags)
	flags.MissionControlDetails, err = createMissionControlDetails(c, true)
	if err != nil {
		return
	}
	flags.ArtifactoryInstanceDetails = new(utils.ArtifactoryInstanceDetails)
	if flags.ArtifactoryInstanceDetails.Url = c.String("rt-url"); flags.ArtifactoryInstanceDetails.Url == "" {
		cliutils.Exit(cliutils.ExitCodeError, "The --rt-url option is mandatory")
	}
	if flags.ArtifactoryInstanceDetails.User = c.String("rt-user"); flags.ArtifactoryInstanceDetails.User == "" {
		cliutils.Exit(cliutils.ExitCodeError, "The --rt-user option is mandatory")
	}
	if flags.ArtifactoryInstanceDetails.Password = c.String("rt-password"); flags.ArtifactoryInstanceDetails.Password == "" {
		cliutils.Exit(cliutils.ExitCodeError, "The --rt-password option is mandatory test")
	}
	flags.Description = c.String("desc")
	flags.Location = c.String("location")
	return
}