Added interactive password prompt when no password is given
This commit is contained in:
		
							parent
							
								
									10a3cc9637
								
							
						
					
					
						commit
						02e4443ab8
					
				
							
								
								
									
										3
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @ -1 +1,4 @@ | ||||
| /.idea | ||||
| vendor/ | ||||
| /pkg | ||||
| /bin | ||||
							
								
								
									
										24
									
								
								src/calanonsync/Gopkg.lock
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								src/calanonsync/Gopkg.lock
									
									
									
										generated
									
									
									
										Normal file
									
								
							| @ -0,0 +1,24 @@ | ||||
| # This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. | ||||
| 
 | ||||
| 
 | ||||
| [[projects]] | ||||
|   branch = "master" | ||||
|   name = "golang.org/x/crypto" | ||||
|   packages = ["ssh/terminal"] | ||||
|   revision = "12892e8c234f4fe6f6803f052061de9057903bb2" | ||||
| 
 | ||||
| [[projects]] | ||||
|   branch = "master" | ||||
|   name = "golang.org/x/sys" | ||||
|   packages = [ | ||||
|     "unix", | ||||
|     "windows" | ||||
|   ] | ||||
|   revision = "378d26f46672a356c46195c28f61bdb4c0a781dd" | ||||
| 
 | ||||
| [solve-meta] | ||||
|   analyzer-name = "dep" | ||||
|   analyzer-version = 1 | ||||
|   inputs-digest = "724028051592219199897d15df4916e95f132caea6497383bbfabbcdb0672123" | ||||
|   solver-name = "gps-cdcl" | ||||
|   solver-version = 1 | ||||
							
								
								
									
										34
									
								
								src/calanonsync/Gopkg.toml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								src/calanonsync/Gopkg.toml
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,34 @@ | ||||
| # Gopkg.toml example | ||||
| # | ||||
| # Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md | ||||
| # for detailed Gopkg.toml documentation. | ||||
| # | ||||
| # required = ["github.com/user/thing/cmd/thing"] | ||||
| # ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] | ||||
| # | ||||
| # [[constraint]] | ||||
| #   name = "github.com/user/project" | ||||
| #   version = "1.0.0" | ||||
| # | ||||
| # [[constraint]] | ||||
| #   name = "github.com/user/project2" | ||||
| #   branch = "dev" | ||||
| #   source = "github.com/myfork/project2" | ||||
| # | ||||
| # [[override]] | ||||
| #   name = "github.com/x/y" | ||||
| #   version = "2.4.0" | ||||
| # | ||||
| # [prune] | ||||
| #   non-go = false | ||||
| #   go-tests = true | ||||
| #   unused-packages = true | ||||
| 
 | ||||
| 
 | ||||
| [prune] | ||||
|   go-tests = true | ||||
|   unused-packages = true | ||||
| 
 | ||||
| [[constraint]] | ||||
|   branch = "master" | ||||
|   name = "golang.org/x/crypto" | ||||
| @ -18,7 +18,7 @@ func main() { | ||||
| 		time.Now().AddDate(0, -1, 0), // One month past | ||||
| 		time.Now().AddDate(0, 2, 0))  // Two months ahead | ||||
| 	if err != nil { | ||||
| 		log.Fatalln(err) | ||||
| 		log.Fatalf("Could not get EWS items: %s\n", err) | ||||
| 	} | ||||
| 
 | ||||
| 	relevantEWSItems := make(map[string]CalendarItem) | ||||
| @ -35,7 +35,7 @@ func main() { | ||||
| 	c := NewCalDAV(s.CalDAV) | ||||
| 	calDavItems, err := c.GetEvents() | ||||
| 	if err != nil { | ||||
| 		log.Fatalln(err) | ||||
| 		log.Fatalf("Could not get CalDAV items: %s\n", err) | ||||
| 	} | ||||
| 	// Build a map for easier lookup by UID | ||||
| 	calDavItemMap := make(map[string]CalDAVItem) | ||||
|  | ||||
| @ -274,6 +274,10 @@ func (c *CalDAV) GetEvents() ([]CalDAVItem, error) { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 
 | ||||
| 	if resp.StatusCode != http.StatusMultiStatus { | ||||
| 		return nil, fmt.Errorf("Unexpected status code: %d", resp.StatusCode) | ||||
| 	} | ||||
| 
 | ||||
| 	defer resp.Body.Close() | ||||
| 	ms := &MultiStatus{} | ||||
| 	err = xml.NewDecoder(resp.Body).Decode(ms) | ||||
|  | ||||
| @ -2,8 +2,10 @@ package main | ||||
| 
 | ||||
| import ( | ||||
| 	"encoding/json" | ||||
| 	"golang.org/x/crypto/ssh/terminal" | ||||
| 	"os" | ||||
| 	"strings" | ||||
| 	"syscall" | ||||
| ) | ||||
| 
 | ||||
| type ServerSettings struct { | ||||
| @ -20,6 +22,22 @@ type Settings struct { | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func ensurePassword(password *string, name string) { | ||||
| 	if *password != "" { | ||||
| 		// Nothing to do. Password already set. | ||||
| 		return | ||||
| 	} | ||||
| 
 | ||||
| 	print(name + " password: ") | ||||
| 	b, err := terminal.ReadPassword(syscall.Stdin) | ||||
| 	println() | ||||
| 	if err != nil { | ||||
| 		panic(err) | ||||
| 	} | ||||
| 
 | ||||
| 	*password = string(b) | ||||
| } | ||||
| 
 | ||||
| func LoadSettings() Settings { | ||||
| 	f, err := os.Open("calanonsync.json") | ||||
| 	if err != nil { | ||||
| @ -35,5 +53,8 @@ func LoadSettings() Settings { | ||||
| 		settings.CalDAV.URL += "/" | ||||
| 	} | ||||
| 
 | ||||
| 	ensurePassword(&settings.EWS.Password, "EWS") | ||||
| 	ensurePassword(&settings.CalDAV.Password, "CalDAV") | ||||
| 
 | ||||
| 	return settings | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user