Beispiel #1
0
func main() {
	if len(os.Args) < 2 {
		log.Println("Usage: client http://server:port/v1/")
		os.Exit(2)
	}
	serverURL := os.Args[1]

	svc, err := util.GetHTTPClientService(serverURL)
	if err != nil {
		log.Printf("call to util.GetHTTPClientService failed: %s\n", err.Error())
		return
	}

	crtSvc := api.NewCertService(svc)
	// TODO allow user to specify multiple keys instead of enforcing id_rsa.pub
	publicKeyPath := os.ExpandEnv("$HOME/.ssh/id_rsa.pub")
	privateKeyPath := strings.Split(publicKeyPath, ".pub")[0]
	pk := util.LoadPublicKey(publicKeyPath)

	certsWithKey, err := crtSvc.GetCerts(pk).Do()
	if err != nil {
		log.Printf("Get request to API failed: %s\n", err.Error())
		return
	}
	err = updateSSHAgent(certsWithKey.List, privateKeyPath)
	if err != nil {
		log.Printf("Failed to updateSSHAgent: %s\n", err.Error())
	}
}
Beispiel #2
0
// addServerToDirectory takes in the key value pair provided by the user and adds it to the server directory on the Certifying authority server.
func addServerToDirectory(c *cobra.Command, args []string) {
	if len(args) != 2 {
		fmt.Fprintf(os.Stderr, "command must have two arguments: The server name and the server url.\nType shortbreadctl help server-add for more information")
		return
	}

	key := args[0]
	address := args[1]

	svc, err := util.GetHTTPClientService(serverURL)
	if err != nil {
		log.Println(err)
	}

	directoryPair := &api.DirectoryPair{
		Key:          key,
		Value:        address,
		GitSignature: gitSignature,
	}
	err = svc.Directory.UpdateServerDirectory(directoryPair).Do()
	if err != nil {
		log.Println(err)
	}
}