| 
						 
							
							
							
						 
					 | 
				
			
			 | 
			 | 
			
				@@ -1,74 +1,40 @@
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				package actions
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				import (
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					"bytes"
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					"bufio"
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					"context"
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					"encoding/json"
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					"fmt"
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					"io"
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					"mime/multipart"
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					"net/http"
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					"os"
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					"strings"
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					"syscall"
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					"time"
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					"git.t-juice.club/torjus/gpaste/api"
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					"github.com/google/uuid"
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					"git.t-juice.club/torjus/gpaste/client"
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					"git.t-juice.club/torjus/gpaste/files"
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					"github.com/urfave/cli/v2"
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					"golang.org/x/term"
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				func ActionUpload(c *cli.Context) error {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					url := fmt.Sprintf("%s/api/file", c.String("url"))
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					client := &http.Client{}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					// TODO: Change timeout
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					ctx, cancel := context.WithTimeout(c.Context, 10*time.Minute)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					defer cancel()
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					buf := &bytes.Buffer{}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					mw := multipart.NewWriter(buf)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					clnt := client.Client{
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						BaseURL: c.String("url"),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					for _, arg := range c.Args().Slice() {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						f, err := os.Open(arg)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						if err != nil {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
							return err
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						defer f.Close()
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						fw, err := mw.CreateFormFile(uuid.Must(uuid.NewRandom()).String(), arg)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						file := &files.File{
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
							OriginalFilename: arg,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
							Body:             f,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						resp, err := clnt.Upload(c.Context, file)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						if err != nil {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
							return err
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
							errmsg := fmt.Sprintf("Error uploading file: %s", err)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
							return cli.Exit(errmsg, 1)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						if _, err := io.Copy(fw, f); err != nil {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
							return err
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					mw.Close()
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, buf)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					if err != nil {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						return err
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					req.Header.Add("Content-Type", mw.FormDataContentType())
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					resp, err := client.Do(req)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					if err != nil {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						return err
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					defer resp.Body.Close()
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					var expectedResp []struct {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						Message string `json:"message"`
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						ID      string `json:"id"`
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						URL     string `json:"url"`
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					decoder := json.NewDecoder(resp.Body)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					if err := decoder.Decode(&expectedResp); err != nil {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						return fmt.Errorf("error decoding response: %w", err)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					for _, r := range expectedResp {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						fmt.Printf("Uploaded file %s\n", r.ID)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						fmt.Printf("Uploaded file %s - %s", file.OriginalFilename, resp[0].URL)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					return nil
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				}
 | 
			
		
		
	
	
		
			
				
					
					| 
						
					 | 
				
			
			 | 
			 | 
			
				@@ -83,92 +49,49 @@ func ActionLogin(c *cli.Context) error {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						return fmt.Errorf("error reading password: %w", err)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					url := fmt.Sprintf("%s/api/login", c.String("url"))
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					client := &http.Client{}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					// TODO: Change timeout
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					ctx, cancel := context.WithTimeout(c.Context, 10*time.Second)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					defer cancel()
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					body := new(bytes.Buffer)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					requestData := struct {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						Username string `json:"username"`
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						Password string `json:"password"`
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					}{
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						Username: username,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						Password: password,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					clnt := client.Client{
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						BaseURL: c.String("url"),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					encoder := json.NewEncoder(body)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					if err := encoder.Encode(&requestData); err != nil {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						return fmt.Errorf("error encoding response: %w", err)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					if err := clnt.Login(c.Context, username, password); err != nil {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						errmsg := fmt.Sprintf("Error logging in: %s", err)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						return cli.Exit(errmsg, 1)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, body)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					if err != nil {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						return fmt.Errorf("error creating request: %w", err)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					resp, err := client.Do(req)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					if err != nil {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						return fmt.Errorf("unable to perform request: %s", err)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					defer resp.Body.Close()
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					if resp.StatusCode != http.StatusOK {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						return cli.Exit("got non-ok response from server", 0)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					responseData := struct {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						Token string `json:"token"`
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					}{}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					decoder := json.NewDecoder(resp.Body)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					if err := decoder.Decode(&responseData); err != nil {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						return fmt.Errorf("unable to parse response: %s", err)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					fmt.Printf("Token: %s", responseData.Token)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					// TODO: Store this somewhere, so we don't need to log in each time
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					fmt.Println("Successfully logged in.")
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					return nil
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				func ActionUserCreate(c *cli.Context) error {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					// TODO: Needs to supply auth token to actually work
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					username := c.Args().First()
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					if username == "" {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						return cli.Exit("USERNAME not supplied.", 1)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					fmt.Println("Need to be logged in to create user")
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					username := readString("Enter username: ")
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					password, err := readPassword()
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					if err != nil {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						return fmt.Errorf("error reading password: %w", err)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					url := fmt.Sprintf("%s/api/user", c.String("url"))
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					client := &http.Client{}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					// TODO: Change timeout
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					clnt := client.Client{
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						BaseURL: c.String("url"),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					ctx, cancel := context.WithTimeout(c.Context, 10*time.Second)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					defer cancel()
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					body := new(bytes.Buffer)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					requestData := &api.RequestAPIUserCreate{
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						Username: username,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						Password: password,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					encoder := json.NewEncoder(body)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					if err := encoder.Encode(requestData); err != nil {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						return fmt.Errorf("error encoding response: %w", err)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, body)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					if err != nil {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						return fmt.Errorf("error creating request: %w", err)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					if err := clnt.Login(ctx, username, password); err != nil {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						errmsg := fmt.Sprintf("Error logging in: %s", err)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						return cli.Exit(errmsg, 1)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					resp, err := client.Do(req)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					fmt.Println("User to create:")
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					username = readString("Enter username: ")
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					password, err = readPassword()
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					if err != nil {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						return fmt.Errorf("unable to perform request: %s", err)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						return fmt.Errorf("error reading password: %w", err)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					defer resp.Body.Close()
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					if resp.StatusCode != http.StatusAccepted {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						return cli.Exit("got non-ok response from server", 0)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					if err := clnt.UserCreate(ctx, username, password); err != nil {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						errmsg := fmt.Sprintf("Error creating user: %s", err)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						return cli.Exit(errmsg, 1)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					fmt.Printf("Created user %s\n", username)
 | 
			
		
		
	
	
		
			
				
					
					| 
						
					 | 
				
			
			 | 
			 | 
			
				@@ -186,3 +109,12 @@ func readPassword() (string, error) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					password := string(bytePassword)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					return strings.TrimSpace(password), nil
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				func readString(prompt string) string {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					fmt.Print(prompt)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					scanner := bufio.NewScanner(os.Stdin)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					for scanner.Scan() {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						return scanner.Text()
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					return ""
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				}
 | 
			
		
		
	
	
		
			
				
					
					| 
						 
							
							
							
						 
					 | 
				
			
			 | 
			 | 
			
				 
 |