Ejemplo n.º 1
0
Archivo: main.go Proyecto: appc/acpush
func runACPush(cmd *cobra.Command, args []string) {
	if len(args) != 3 {
		cmd.Usage()
		os.Exit(1)
	}

	conf, err := config.GetConfigFrom(flagSystemConfigDir, flagLocalConfigDir)
	if err != nil {
		fmt.Fprintf(os.Stderr, "error loading config: %v\n", err)
		os.Exit(2)
	}

	err = lib.Uploader{
		Acipath:  args[0],
		Ascpath:  args[1],
		Uri:      args[2],
		Insecure: flagInsecure,
		Debug:    flagDebug,
		SetHTTPHeaders: func(r *http.Request) {
			if r.URL == nil {
				return
			}
			if flagUser != "" && flagPassword != "" {
				creds := []byte(fmt.Sprintf("%s:%s", flagUser, flagPassword))
				encodedCreds := base64.StdEncoding.EncodeToString(creds)
				r.Header["Authorization"] = append(r.Header["Authorization"], "Basic "+encodedCreds)
			} else {
				headerer, ok := conf.AuthPerHost[r.URL.Host]
				if !ok {
					if flagDebug {
						fmt.Fprintf(os.Stderr, "No auth present in config for domain %s.\n", r.URL.Host)
					}
					return
				}
				header := headerer.Header()
				for k, v := range header {
					r.Header[k] = append(r.Header[k], v...)
				}
			}
		},
	}.Upload()

	if err != nil {
		fmt.Fprintf(os.Stderr, "err: %v\n", err)
		os.Exit(1)
	}
	if flagDebug {
		fmt.Fprintln(os.Stderr, "Upload successful")
	}
}
Ejemplo n.º 2
0
func runACPush(cmd *cobra.Command, args []string) {
	if len(args) != 3 {
		cmd.Usage()
		os.Exit(1)
	}

	conf, err := config.GetConfigFrom(flagSystemConfigDir, flagLocalConfigDir)
	if err != nil {
		fmt.Fprintf(os.Stderr, "error loading config: %v\n", err)
		os.Exit(2)
	}

	err = lib.Uploader{
		Acipath:  args[0],
		Ascpath:  args[1],
		Uri:      args[2],
		Insecure: flagInsecure,
		Debug:    flagDebug,
		SetHTTPHeaders: func(r *http.Request) {
			if r.URL == nil {
				return
			}
			headerer, ok := conf.AuthPerHost[r.URL.Host]
			if !ok {
				if flagDebug {
					fmt.Fprintf(os.Stderr, "No auth present in config for domain %s.\n", r.URL.Host)
				}
				return
			}
			header := headerer.Header()
			for k, v := range header {
				r.Header[k] = append(r.Header[k], v...)
			}
		},
	}.Upload()

	if err != nil {
		fmt.Fprintf(os.Stderr, "err: %v\n", err)
		os.Exit(1)
	}
	if flagDebug {
		fmt.Fprintln(os.Stderr, "Upload successful")
	}
}