@@ -139,20 +139,31 @@ func runCreate(cmd *cobra.Command, args []string) error {
139139 return fmt .Errorf ("failed to create docker directory: %w" , err )
140140 }
141141
142+ // Handle enterprise authentication if needed
143+ var enterpriseToken string
144+ if flagEnterprise {
145+ var err error
146+ enterpriseToken , err = promptEnterpriseAuth ()
147+ if err != nil {
148+ return fmt .Errorf ("enterprise authentication failed: %w" , err )
149+ }
150+ }
151+
142152 // Build state
143153 state := & config.State {
144- ProjectName : ctx .Name ,
145- OdooVersion : ctx .OdooVersion ,
146- Branch : ctx .Branch ,
147- IsGitRepo : ctx .IsGitRepo ,
148- ProjectRoot : ctx .Root ,
149- Modules : modules ,
150- Enterprise : flagEnterprise ,
151- WithoutDemo : flagWithoutDemo ,
152- PipPackages : pipPkgs ,
153- AddonsPaths : addonsPaths ,
154- Ports : config .CalculatePorts (ctx .OdooVersion ),
155- CreatedAt : time .Now (),
154+ ProjectName : ctx .Name ,
155+ OdooVersion : ctx .OdooVersion ,
156+ Branch : ctx .Branch ,
157+ IsGitRepo : ctx .IsGitRepo ,
158+ ProjectRoot : ctx .Root ,
159+ Modules : modules ,
160+ Enterprise : flagEnterprise ,
161+ EnterpriseGitHubToken : enterpriseToken ,
162+ WithoutDemo : flagWithoutDemo ,
163+ PipPackages : pipPkgs ,
164+ AddonsPaths : addonsPaths ,
165+ Ports : config .CalculatePorts (ctx .OdooVersion ),
166+ CreatedAt : time .Now (),
156167 }
157168
158169 // Render templates
@@ -171,6 +182,92 @@ func runCreate(cmd *cobra.Command, args []string) error {
171182 return nil
172183}
173184
185+ func promptEnterpriseAuth () (string , error ) {
186+ green := color .New (color .FgGreen ).SprintFunc ()
187+ cyan := color .New (color .FgCyan ).SprintFunc ()
188+ yellow := color .New (color .FgYellow ).SprintFunc ()
189+
190+ fmt .Println ()
191+ fmt .Printf ("%s Enterprise access requires authentication\n \n " , green ("🔐" ))
192+
193+ // Check for SSH keys
194+ home , err := os .UserHomeDir ()
195+ if err != nil {
196+ home = ""
197+ }
198+
199+ hasSSH := false
200+ if home != "" {
201+ sshPaths := []string {
202+ filepath .Join (home , ".ssh" , "id_rsa" ),
203+ filepath .Join (home , ".ssh" , "id_ed25519" ),
204+ }
205+ for _ , path := range sshPaths {
206+ if _ , err := os .Stat (path ); err == nil {
207+ hasSSH = true
208+ break
209+ }
210+ }
211+ }
212+
213+ // Present authentication options
214+ fmt .Println ("Choose authentication method:" )
215+ if hasSSH {
216+ fmt .Printf (" [1] SSH Keys %s\n " , cyan ("(detected)" ))
217+ }
218+ fmt .Printf (" [2] Personal Access Token %s\n " , cyan ("(recommended)" ))
219+ fmt .Println ()
220+
221+ // Default to token (option 2)
222+ useSSH := false
223+ if hasSSH {
224+ choice , err := prompt .InputString ("Select option [1-2]:" , "2" )
225+ if err != nil {
226+ return "" , err
227+ }
228+ useSSH = choice == "1"
229+ }
230+
231+ if useSSH {
232+ fmt .Printf ("\n %s Using SSH keys for enterprise repository access\n " , green ("✓" ))
233+ fmt .Printf ("%s Make sure your SSH key is added to GitHub: https://github.com/settings/keys\n \n " , yellow ("ℹ" ))
234+ return "" , nil // Empty token means use SSH
235+ }
236+
237+ // Prompt for token
238+ fmt .Println ()
239+ fmt .Printf ("%s To create a Personal Access Token:\n " , cyan ("ℹ" ))
240+ fmt .Printf (" 1. Visit: %s\n " , cyan ("https://github.com/settings/tokens/new" ))
241+ fmt .Printf (" 2. Set description: %s\n " , cyan ("Odoo Enterprise Access" ))
242+ fmt .Printf (" 3. Select scope: %s\n " , cyan ("repo (Full control of private repositories)" ))
243+ fmt .Printf (" 4. Click %s and copy the token\n \n " , cyan ("'Generate token'" ))
244+
245+ token , err := prompt .InputPassword ("Enter GitHub Personal Access Token:" )
246+ if err != nil {
247+ return "" , err
248+ }
249+
250+ token = strings .TrimSpace (token )
251+ if token == "" {
252+ return "" , fmt .Errorf ("token cannot be empty" )
253+ }
254+
255+ // Basic validation - modern GitHub tokens start with specific prefixes
256+ if ! strings .HasPrefix (token , "ghp_" ) && ! strings .HasPrefix (token , "github_pat_" ) {
257+ fmt .Printf ("\n %s Token doesn't match expected format (should start with 'ghp_' or 'github_pat_')\n " , yellow ("⚠" ))
258+ confirm , err := prompt .Confirm ("Continue anyway?" , false )
259+ if err != nil {
260+ return "" , err
261+ }
262+ if ! confirm {
263+ return "" , fmt .Errorf ("authentication cancelled" )
264+ }
265+ }
266+
267+ fmt .Printf ("\n %s Token saved securely in environment configuration\n " , green ("✓" ))
268+ return token , nil
269+ }
270+
174271func printCreateSummary (state * config.State ) {
175272 green := color .New (color .FgGreen ).SprintFunc ()
176273 cyan := color .New (color .FgCyan ).SprintFunc ()
@@ -186,12 +283,20 @@ func printCreateSummary(state *config.State) {
186283 dir , _ := config .EnvironmentDir (state .ProjectName , state .Branch )
187284 fmt .Printf (" Files: %s\n " , cyan (dir ))
188285
286+ if state .Enterprise {
287+ authMethod := "SSH Keys"
288+ if state .EnterpriseGitHubToken != "" {
289+ authMethod = "GitHub Token"
290+ }
291+ fmt .Printf (" Enterprise: %s (%s)\n " , green ("✓" ), authMethod )
292+ }
293+
189294 if len (state .AddonsPaths ) > 0 {
190295 fmt .Printf (" Addons: %d custom path(s)\n " , len (state .AddonsPaths ))
191296 }
192297
193298 fmt .Println ()
194299 fmt .Println ("Next steps:" )
195- fmt .Printf (" 1. %s # Initialize database and start containers \n " , cyan ("odooctl docker run" ))
300+ fmt .Printf (" 1. %s # Build image and initialize database \n " , cyan ("odooctl docker run -i " ))
196301 fmt .Printf (" 2. %s # View container status\n " , cyan ("odooctl docker status" ))
197302}
0 commit comments