Beispiel #1
0
func (c *initCmd) clientConfigFromServer() (*clientconfig.Config, error) {
	if c.noconfig {
		log.Print("--userpass and --noconfig are mutually exclusive")
		return nil, cmdmain.ErrUsage
	}
	server := client.ExplicitServer()
	if server == "" {
		log.Print("--userpass requires --server")
		return nil, cmdmain.ErrUsage
	}
	fields := strings.Split(c.userPass, ":")
	if len(fields) != 2 {
		log.Printf("wrong userpass; wanted username:password, got %q", c.userPass)
		return nil, cmdmain.ErrUsage
	}

	cl := client.NewFromParams(server,
		auth.NewBasicAuth(fields[0], fields[1]),
		client.OptionInsecure(c.insecureTLS))

	helpRoot, err := cl.HelpRoot()
	if err != nil {
		return nil, err
	}

	var cc clientconfig.Config
	if err := cl.GetJSON(helpRoot+"?clientConfig=true", &cc); err != nil {
		return nil, err
	}
	return &cc, nil
}
Beispiel #2
0
// Client returns a Camlistore client as defined by environment variables
// automatically supplied by the Camlistore server host.
func Client() (*client.Client, error) {
	server := os.Getenv("CAMLI_API_HOST")
	if server == "" {
		return nil, errors.New("CAMLI_API_HOST var not set")
	}
	am, err := basicAuth()
	if err != nil {
		return nil, err
	}
	return client.NewFromParams(server, am), nil
}
Beispiel #3
0
// Client returns a client from pkg/client, configured by environment variables
// for applications, and ready to be used to connect to the Camlistore server.
func Client() (*client.Client, error) {
	server := os.Getenv("CAMLI_API_HOST")
	if server == "" {
		return nil, errors.New("CAMLI_API_HOST var not set")
	}
	authString := os.Getenv("CAMLI_AUTH")
	if authString == "" {
		return nil, errors.New("CAMLI_AUTH var not set")
	}
	userpass := strings.Split(authString, ":")
	if len(userpass) != 2 {
		return nil, fmt.Errorf("invalid auth string syntax. got %q, want \"username:password\"", authString)
	}
	cl := client.NewFromParams(server, auth.NewBasicAuth(userpass[0], userpass[1]))
	return cl, nil
}
Beispiel #4
0
func main() {
	fmt.Printf("oi\n")

	camliAuth := auth.NewBasicAuth("nictuku", "SOMETHING")

	client := camli.NewFromParams("http://<IP>:3179", camliAuth)
	client.InsecureTLS = true
	recent, err := client.GetRecentPermanodes(&search.RecentRequest{})
	if err != nil {
		log.Printf("error getting recent permanodes:", err)
		os.Exit(1)
	}
	for _, desc := range recent.Meta {
		fmt.Printf("title: %v\ndescription: %v\n--\n", desc.Title(), desc.Description())
	}
	fmt.Println("printed %d items", len(recent.Meta))
}