turn password flag into password file
This commit is contained in:
		
							parent
							
								
									c437d4388e
								
							
						
					
					
						commit
						d8e3da9d45
					
				
					 2 changed files with 15 additions and 8 deletions
				
			
		
							
								
								
									
										1
									
								
								.gitignore
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
										
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1 @@ | |||
| password.txt | ||||
							
								
								
									
										22
									
								
								fafomo.go
									
										
									
									
									
								
							
							
						
						
									
										22
									
								
								fafomo.go
									
										
									
									
									
								
							|  | @ -122,17 +122,17 @@ func update(ctx context.Context) (string, error) { | |||
| } | ||||
| 
 | ||||
| var ( | ||||
| 	flagMatrixHomeserver = "matrix.org" | ||||
| 	flagMatrixUsername   = "@fafomo:matrix.org" | ||||
| 	flagMatrixPassword   string | ||||
| 	flagMatrixRoom       string | ||||
| 	flagBackendURL       string | ||||
| 	flagMatrixHomeserver   = "matrix.org" | ||||
| 	flagMatrixUsername     = "@fafomo:matrix.org" | ||||
| 	flagMatrixPasswordFile = "password.txt" | ||||
| 	flagMatrixRoom         string | ||||
| 	flagBackendURL         string | ||||
| ) | ||||
| 
 | ||||
| func main() { | ||||
| 	flag.StringVar(&flagMatrixHomeserver, "matrix_homeserver", flagMatrixHomeserver, "Address of Matrix homeserver") | ||||
| 	flag.StringVar(&flagMatrixUsername, "matrix_username", flagMatrixUsername, "Matrix login username") | ||||
| 	flag.StringVar(&flagMatrixPassword, "matrix_password", flagMatrixPassword, "Matrix login password") | ||||
| 	flag.StringVar(&flagMatrixPasswordFile, "matrix_password_file", flagMatrixPasswordFile, "Path to file containing matrix login password") | ||||
| 	flag.StringVar(&flagMatrixRoom, "matrix_room", flagMatrixRoom, "Matrix room MXID") | ||||
| 	flag.StringVar(&flagBackendURL, "backend_url", flagBackendURL, "Checkinator (backend) addresss") | ||||
| 	flag.Parse() | ||||
|  | @ -143,7 +143,7 @@ func main() { | |||
| 	}{ | ||||
| 		{flagMatrixHomeserver, "matrix_homeserver"}, | ||||
| 		{flagMatrixUsername, "matrix_username"}, | ||||
| 		{flagMatrixPassword, "matrix_password"}, | ||||
| 		{flagMatrixPasswordFile, "matrix_password_file"}, | ||||
| 		{flagMatrixRoom, "matrix_room"}, | ||||
| 		{flagBackendURL, "backend_url"}, | ||||
| 	} { | ||||
|  | @ -164,12 +164,18 @@ func main() { | |||
| 		klog.Exitf("NewClient failed: %v", err) | ||||
| 	} | ||||
| 
 | ||||
| 	passwordBytes, err := os.ReadFile(flagMatrixPasswordFile) | ||||
| 	if err != nil { | ||||
| 		klog.Exitf("Could not read password file: %v", err) | ||||
| 	} | ||||
| 	password := strings.TrimSpace(string(passwordBytes)) | ||||
| 
 | ||||
| 	klog.Infof("Logging in...") | ||||
| 
 | ||||
| 	login, err := client.Login(startCtx, &mautrix.ReqLogin{ | ||||
| 		Type:       mautrix.AuthTypePassword, | ||||
| 		Identifier: mautrix.UserIdentifier{Type: mautrix.IdentifierTypeUser, User: flagMatrixUsername}, | ||||
| 		Password:   flagMatrixPassword, | ||||
| 		Password:   password, | ||||
| 	}) | ||||
| 	if err != nil { | ||||
| 		klog.Exitf("Failed to log in: %v", err) | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue