Exemple #1
0
func main() {
	flag.Parse()
	log.SetHandler(text.New(os.Stderr))
	log.SetLevel(log.DebugLevel)

	// set up producer
	svc := kinesis.New(session.New())
	p := producer.New(producer.Config{
		StreamName:  *stream,
		BacklogSize: 500,
		Client:      svc,
	})
	p.Start()

	// open data file
	f, err := os.Open("/tmp/users.txt")
	if err != nil {
		log.Fatal("Cannot open users.txt file")
	}
	defer f.Close()

	// loop over file data
	b := bufio.NewScanner(f)
	for b.Scan() {
		err := p.Put(b.Bytes(), "site")

		if err != nil {
			log.WithError(err).Fatal("error producing")
		}
	}

	p.Stop()
}
Exemple #2
0
func invokeCmdPreRun(c *cobra.Command, args []string) {
	lv := &invokeCmdLocalValues

	if len(args) < 1 {
		log.Fatal("Missing name argument")
	}
	lv.name = args[0]
}
Exemple #3
0
func rollbackCmdPreRun(c *cobra.Command, args []string) {
	lv := &rollbackCmdLocalValues

	if len(args) < 1 {
		log.Fatal("Missing name argument")
	}
	lv.name = args[0]

	if len(args) >= 2 {
		lv.version = args[1]
	}
}
Exemple #4
0
func logsCmdPreRun(c *cobra.Command, args []string) {
	lv := &logsCmdLocalValues

	if len(args) < 1 {
		log.Fatal("Missing name argument")
	}
	lv.name = args[0]

	if len(args) >= 2 {
		lv.Duration = args[1]
	}
}
Exemple #5
0
func metricsCmdPreRun(c *cobra.Command, args []string) {
	lv := &metricsCmdLocalValues

	if len(args) < 1 {
		log.Fatal("Missing name argument")
	}

	lv.name = args[0]

	if len(args) > 1 {
		lv.duration = args[1]
	} else {
		lv.duration = "24h"
	}
}
Exemple #6
0
func hookBefore(c *cli.Context) error {
	level := log.InfoLevel
	syslogLevel := syslog.LOG_INFO
	if c.Bool("verbose") {
		level = log.DebugLevel
		syslogLevel = syslog.LOG_DEBUG
	}
	log.SetLevel(level)
	log.SetHandler(text.New(os.Stderr))

	if c.String("syslog-server") != "" {
		server := strings.Split(c.String("syslog-server"), "://")

		if server[0] == "unix" {
			log.SetHandler(multi.New(text.New(os.Stderr), sysloghandler.New("", "", syslogLevel, "")))
		} else {
			if len(server) != 2 {
				log.Fatal("invalid syslog parameter")
			}
			log.SetHandler(multi.New(text.New(os.Stderr), sysloghandler.New(server[0], server[1], syslogLevel, "")))
		}
	}
	return nil
}
Exemple #7
0
func main() {
	renameFlag := flag.String("r", "", "-r [newname]")
	pathFlag := flag.String("p", "", "-p [/some/path/]")
	dryRunFlag := flag.Bool("d", false, "-d")
	flag.Usage = func() {
		println(USAGE)
	}

	flag.Parse()
	args := flag.Args()

	log.Infof("Flags: rename(%s), path(%s), dry(%t)", *renameFlag, *pathFlag, *dryRunFlag)
	log.Infof("Args : %s", strings.Join(args, ", "))

	if len(args) < 1 {
		log.Fatal(USAGE)
	}

	project := strings.TrimSpace(args[0])
	if project == "" {
		log.Fatal(USAGE)
	}

	parts := strings.Split(project, "/")
	if len(parts) != 2 {
		log.Fatal(USAGE)
	}

	owner := strings.TrimSpace(parts[0])
	repo := strings.TrimSpace(parts[1])
	if owner == "" || repo == "" {
		log.Fatal(USAGE)
	}

	projectUrl := fmt.Sprintf("github.com/%s/%s", owner, repo)

	client := github.NewClient(nil)

	log.Infof("Grabbing from %s...", project)

	_, resp, err := client.Repositories.Get(owner, repo)
	if err != nil {
		if resp == nil {
			log.Fatalf("Error: Cannot reach %s", projectUrl)
		}

		if resp.StatusCode == 404 {
			log.Fatalf("Error: Project does not exist: %s", projectUrl)
		} else {
			log.Fatalf("Error: Unknown error (%d) reaching: %s", resp.StatusCode, projectUrl)
		}
	}

	release, resp, err := client.Repositories.GetLatestRelease(owner, repo)
	if err != nil {
		if resp.StatusCode == 404 {
			log.Infof("No official releases yet. Checking pre-release tags...")
			tags, _, err := client.Repositories.ListTags(owner, repo, nil)
			if err != nil || len(tags) < 1 {
				log.Fatalf(ERR_NO_RELEASES, err)
			}

			tag := tags[0]
			log.Infof("Latest tag: %s (%s)", *tag.Name, *tag.Commit.SHA)

			release, resp, err = client.Repositories.GetReleaseByTag(owner, repo, *tag.Name)
			if err != nil || len(tags) < 1 {
				log.Fatalf(ERR_NO_RELEASES, err)
			}
		}
	}

	assets := release.Assets
	var asset github.ReleaseAsset

	switch len(assets) {
	case 0:
		log.Fatal("Error: No assets to download")
		break
	case 1:
		asset = assets[0]
		break
	default:
		log.Info("Release Assets:")
		for i, a := range assets {
			log.Infof(" (%d) %s (%s)", i+1, *a.Name, *a.BrowserDownloadURL)
		}

		reader := bufio.NewReader(os.Stdin)
		fmt.Print("Which asset would you like to download? ")
		choice, _ := reader.ReadString('\n')
		choice = strings.TrimSpace(choice)
		choiceInt, err := strconv.Atoi(choice)
		if err != nil {
			log.Fatalf("Error: You must select an asset to download")
		}
		println("")
		asset = assets[choiceInt-1]

		break
	}

	if *dryRunFlag {
		log.Info("Dry-run completed")
	} else {
		downloadReleaseAsset(&asset, renameFlag, pathFlag)
	}
}
Exemple #8
0
// Fatal level message, followed by an exit.
func Fatal(msg string) {
	apexlog.Fatal(msg)
}