@@ -7,26 +7,18 @@ use std::process::{Command, Stdio};
77
88#[ derive( Debug , Clone , Serialize , Deserialize ) ]
99pub struct LastPassConfig {
10- /// Whether to sync before each operation
11- #[ serde( default = "default_sync_on_access" ) ]
12- pub sync_on_access : bool ,
1310 /// Default folder prefix
1411 pub folder_prefix : Option < String > ,
1512}
1613
1714impl Default for LastPassConfig {
1815 fn default ( ) -> Self {
1916 Self {
20- sync_on_access : true ,
2117 folder_prefix : None ,
2218 }
2319 }
2420}
2521
26- fn default_sync_on_access ( ) -> bool {
27- true
28- }
29-
3022impl LastPassConfig {
3123 pub fn from_uri ( uri : & Uri ) -> Result < Self > {
3224 let scheme = uri. scheme_str ( ) . ok_or_else ( || {
@@ -117,18 +109,14 @@ impl LastPassProvider {
117109 format ! ( "{}/{}/{}" , folder, project, key)
118110 }
119111
120- fn sync_if_needed ( & self ) -> Result < ( ) > {
112+ fn check_if_logged_in ( & self ) -> Result < ( ) > {
121113 // Check if we're logged in first
122114 if !self . check_login_status ( ) ? {
123115 return Err ( SecretSpecError :: ProviderOperationFailed (
124116 "LastPass authentication required. Please run 'lpass login <your-email>' first."
125117 . to_string ( ) ,
126118 ) ) ;
127119 }
128-
129- if self . config . sync_on_access {
130- self . execute_lpass_command ( & [ "sync" ] ) ?;
131- }
132120 Ok ( ( ) )
133121 }
134122
@@ -148,11 +136,11 @@ impl LastPassProvider {
148136
149137impl Provider for LastPassProvider {
150138 fn get ( & self , project : & str , key : & str , profile : Option < & str > ) -> Result < Option < String > > {
151- self . sync_if_needed ( ) ?;
139+ self . check_if_logged_in ( ) ?;
152140
153141 let item_name = self . format_item_name ( project, key, profile) ;
154142
155- match self . execute_lpass_command ( & [ "show" , "--password" , & item_name] ) {
143+ match self . execute_lpass_command ( & [ "show" , "--sync=now" , "-- password", & item_name] ) {
156144 Ok ( output) => {
157145 let password = output. trim ( ) ;
158146 if password. is_empty ( ) {
@@ -171,14 +159,20 @@ impl Provider for LastPassProvider {
171159 }
172160
173161 fn set ( & self , project : & str , key : & str , value : & str , profile : Option < & str > ) -> Result < ( ) > {
174- self . sync_if_needed ( ) ?;
162+ self . check_if_logged_in ( ) ?;
175163
176164 let item_name = self . format_item_name ( project, key, profile) ;
177165
178166 // Check if item exists
179167 if self . get ( project, key, profile) ?. is_some ( ) {
180168 // Update existing item
181- let args = vec ! [ "edit" , & item_name, "--password" , "--non-interactive" ] ;
169+ let args = vec ! [
170+ "edit" ,
171+ "--sync=now" ,
172+ & item_name,
173+ "--password" ,
174+ "--non-interactive" ,
175+ ] ;
182176
183177 let mut cmd = Command :: new ( "lpass" ) ;
184178 cmd. args ( & args) ;
@@ -202,22 +196,14 @@ impl Provider for LastPassProvider {
202196 ) ) ;
203197 }
204198 } else {
205- // Create new item
206- let folder = self . get_folder_name ( profile) ;
207-
208- // Create folder if it doesn't exist
209- let _ = self . execute_lpass_command ( & [ "mkdir" , & folder] ) ;
210-
211- let url = format ! ( "project://{}/{}" , project, key) ;
212- let username = format ! ( "{}:{}" , project, key) ;
213-
214- let note_content = format ! (
215- "URL: {}\n Username: {}\n Password: {}\n Notes: Managed by secrets provider\n Project: {}\n Key: {}" ,
216- url, username, value, project, key
217- ) ;
218-
219- // Use lpass add with piped input
220- let args = vec ! [ "add" , & item_name, "--non-interactive" , "--note" ] ;
199+ // Create new item using lpass set
200+ let args = vec ! [
201+ "set" ,
202+ "--sync=now" ,
203+ & item_name,
204+ "--password" ,
205+ "--non-interactive" ,
206+ ] ;
221207
222208 let mut cmd = Command :: new ( "lpass" ) ;
223209 cmd. args ( & args) ;
@@ -230,7 +216,7 @@ impl Provider for LastPassProvider {
230216 . spawn ( ) ?;
231217
232218 if let Some ( stdin) = child. stdin . as_mut ( ) {
233- stdin. write_all ( note_content . as_bytes ( ) ) ?;
219+ stdin. write_all ( value . as_bytes ( ) ) ?;
234220 }
235221
236222 let output = child. wait_with_output ( ) ?;
0 commit comments