@@ -86,15 +86,26 @@ def install_plugin(self) -> bool:
8686
8787 def setup_credentials (self ) -> bool :
8888 """Setup credentials file for certbot using provider implementation."""
89- return self .provider .setup_certbot_credentials ()
89+ print (f"Setting up credentials for { self .provider_type } provider" )
90+ result = self .provider .setup_certbot_credentials ()
91+ if result :
92+ print (f"Credentials setup successful for { self .provider_type } " )
93+ else :
94+ print (f"Credentials setup failed for { self .provider_type } " )
95+ return result
9096
9197 def _build_certbot_command (self , action : str , domain : str , email : str ) -> List [str ]:
9298 """Build certbot command using provider configuration."""
99+ print (f"Building certbot command for action: { action } , domain: { domain } " )
100+
93101 plugin = self .provider .CERTBOT_PLUGIN
102+ print (f"Using plugin: { plugin } " )
103+
94104 if not plugin :
95105 raise ValueError (f"No certbot plugin configured for { self .provider_type } " )
96106
97107 propagation_seconds = self .provider .CERTBOT_PROPAGATION_SECONDS
108+ print (f"Propagation seconds configured: { propagation_seconds } " )
98109
99110 base_cmd = ["certbot" , action ]
100111
@@ -105,37 +116,77 @@ def _build_certbot_command(self, action: str, domain: str, email: str) -> List[s
105116 "--non-interactive" ,
106117 ]
107118 )
119+ print (f"Added plugin and non-interactive flags" )
108120
109121 # Add credentials file if provider has one configured
110122 if self .provider .CERTBOT_CREDENTIALS_FILE :
111123 credentials_file = os .path .expanduser (
112124 self .provider .CERTBOT_CREDENTIALS_FILE
113125 )
126+ print (f"Credentials file path (expanded): { credentials_file } " )
127+
114128 if os .path .exists (credentials_file ):
115- base_cmd .extend ([f"--{ plugin } -credentials={ credentials_file } " ])
129+ credentials_arg = f"--{ plugin } -credentials={ credentials_file } "
130+ base_cmd .extend ([credentials_arg ])
131+ print (f"Added credentials argument: { credentials_arg } " )
132+ else :
133+ print (f"Warning: Credentials file does not exist: { credentials_file } " )
134+ else :
135+ print (f"No credentials file configured for provider" )
116136
117137 if action == "certonly" :
118138 base_cmd .extend (
119139 ["--agree-tos" , "--no-eff-email" , "--email" , email , "-d" , domain ]
120140 )
141+ print (f"Added certonly-specific arguments" )
121142
143+ # Print the final command with masked email
144+ masked_cmd = []
145+ for i , arg in enumerate (base_cmd ):
146+ if i > 0 and base_cmd [i - 1 ] == "--email" :
147+ masked_cmd .append ("<email>" )
148+ else :
149+ masked_cmd .append (arg )
150+ print (f"Final certbot command: { ' ' .join (masked_cmd )} " )
151+
122152 return base_cmd
123153
124154 def obtain_certificate (self , domain : str , email : str ) -> bool :
125155 """Obtain a new certificate for the domain."""
126- print (f"Obtaining new certificate for { domain } using { self .provider_type } " )
156+ print (f"Starting certificate obtaining process for { domain } using { self .provider_type } " )
157+
158+ # Check if credentials are set up
159+ print (f"Checking credentials setup..." )
160+ if not self .setup_credentials ():
161+ print (f"Failed to setup credentials for { self .provider_type } " , file = sys .stderr )
162+ return False
163+ print (f"Credentials setup completed" )
127164
128165 cmd = self ._build_certbot_command ("certonly" , domain , email )
166+ print (f"Executing certbot command..." )
129167
130168 try :
131- result = subprocess .run (cmd , capture_output = True , text = True )
169+ result = subprocess .run (cmd , capture_output = True , text = True , timeout = 300 )
170+
171+ print (f"Certbot command completed with return code: { result .returncode } " )
172+
173+ if result .stdout :
174+ print (f"Certbot stdout: { result .stdout } " )
175+
132176 if result .returncode != 0 :
133- print (f"Certificate obtaining failed: { result .stderr } " , file = sys .stderr )
177+ print (f"Certificate obtaining failed with return code { result .returncode } " )
178+ if result .stderr :
179+ print (f"Certificate obtaining failed: { result .stderr } " , file = sys .stderr )
180+ if result .stdout :
181+ print (f"Certificate stdout on failure: { result .stdout } " , file = sys .stderr )
134182 return False
135183
136184 print (f"Certificate obtained successfully for { domain } " )
137185 return True
138186
187+ except subprocess .TimeoutExpired :
188+ print (f"Certbot command timed out after 300 seconds" , file = sys .stderr )
189+ return False
139190 except Exception as e :
140191 print (f"Error running certbot: { e } " , file = sys .stderr )
141192 return False
0 commit comments