Beispiel #1
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
			}
			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")
	}
}
Beispiel #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")
	}
}
Beispiel #3
0
func main() {
	flag.Usage = usage
	flag.Parse()
	args := flag.Args()

	if len(args) < 3 {
		usage()
		return
	}

	if flagInsecure == nil {
		fmt.Fprintln(os.Stderr, "Insecure flag unset?")
		os.Exit(1)
	}
	if flagDebug == nil {
		fmt.Fprintln(os.Stderr, "Debug flag unset?")
		os.Exit(1)
	}
	if flagSystemConfigDir == nil {
		fmt.Fprintln(os.Stderr, "System config dir unset?")
		os.Exit(1)
	}
	if flagLocalConfigDir == nil {
		fmt.Fprintln(os.Stderr, "Local config dir unset?")
		os.Exit(1)
	}

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

	err = libacpush.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")
	}
}