Exemplo n.º 1
0
func main() {
	flag.Parse()
	auth := aws.Auth{os.Getenv("AWS_ACCESS_KEY_ID"), os.Getenv("AWS_SECRET_ACCESS_KEY")}
	bucket = s3.New(auth, aws.USEast).Bucket(flag.Arg(0))

	go logLines()
	for i := 0; i < *workers; i++ {
		go deleteBatches()
	}
	done.Add(*workers)

	var count int
	var marker string
	for {
		var prefix string
		if len(os.Args) > 2 {
			prefix = flag.Arg(1)
		}
		list, err := bucket.List(prefix, "", marker, 1000)
		if err != nil {
			log.Fatalln("list:", err)
		}
		if len(list.Contents) == 0 {
			break
		}

		keys := make([]string, len(list.Contents))
		for i, k := range list.Contents {
			keys[i] = k.Key
		}

		batches <- keys
		count += len(keys)

		if !list.IsTruncated {
			break
		}
		marker = keys[len(keys)-1]
	}
	close(batches)
	done.Wait()
	log.Printf("Delete %d objects", count)
}
Exemplo n.º 2
0
func main() {
	http.HandleFunc("/", protect(indexHandler))
	http.HandleFunc("/push", protect(pushHandler))
	http.HandleFunc("/upload", uploadHandler)
	http.HandleFunc("/auth", authSetupHandler)
	http.HandleFunc("/auth/return", authFinalizeHandler)
	port := os.Getenv("PORT")
	if port == "" {
		port = "8080"
	}
	log.Fatal(http.ListenAndServe(":"+port, nil))
}

var (
	appName    = os.Getenv("APP_NAME")
	s3Bucket   = s3.New(aws.Auth{os.Getenv("AWS_ACCESS_KEY_ID"), os.Getenv("AWS_SECRET_ACCESS_KEY")}, aws.USEast).Bucket(os.Getenv("S3_BUCKET"))
	authUsers  = strings.Split(os.Getenv("AUTHORIZED_USERS"), ",")
	apiKey     = []byte(os.Getenv("API_KEY"))
	requireSig = os.Getenv("REQUIRE_SIGNATURE") != ""
	githubAuth *oauth2.OAuth2Service
	baseURL    *url.URL
)

func init() {
	e := []string{"AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", "APP_NAME", "S3_BUCKET", "COOKIE_SECRET", "AUTHORIZED_USERS", "GITHUB_CLIENT_ID", "GITHUB_CLIENT_SECRET", "BASE_URL", "API_KEY"}
	for _, env := range e {
		if os.Getenv(env) == "" {
			log.Fatalf("Missing %s environment variable", env)
		}
	}