@@ -19,6 +19,9 @@ var cookCmd = &cobra.Command{
1919 Short : "Execute OpenTofu" ,
2020 Args : cobra .MinimumNArgs (1 ),
2121 Long : `Execute OpenTofu with generated config from inventory and parameters after --` ,
22+ PreRun : func (cmd * cobra.Command , args []string ) {
23+ initConfig ()
24+ },
2225 Run : func (cmd * cobra.Command , args []string ) {
2326 //Creating signal to be handled and send to the child tofu/terraform
2427 sigs := make (chan os.Signal , 2 )
@@ -28,10 +31,35 @@ var cookCmd = &cobra.Command{
2831 // Creating Tofug shared structure and filling with values
2932 tofuguStruct := & utils.Tofugu {}
3033
34+ toasterUrl := os .Getenv ("toasterurl" )
35+ if toasterUrl != "" {
36+ // validate URL format and remove trailing slash if present
37+ if strings .HasSuffix (toasterUrl , "/" ) {
38+ toasterUrl = strings .TrimRight (toasterUrl , "/" )
39+ }
40+
41+ // Basic validation for toasterUrl format
42+ if ! strings .HasPrefix (toasterUrl , "https://" ) {
43+ log .Fatalf ("Error: toasterUrl must start with https://" )
44+ }
45+
46+ // Check if URL contains credentials and correct domain
47+ urlParts := strings .Split (strings .TrimPrefix (toasterUrl , "https://" ), "@" )
48+ if len (urlParts ) != 2 || urlParts [1 ] != "toaster.altuhov.su" {
49+ log .Fatalf ("Error: toasterUrl must be in format https://ACCOUNTID:PASSWORD@toaster.altuhov.su" )
50+ }
51+
52+ // Validate credential part has both account ID and password
53+ credParts := strings .Split (urlParts [0 ], ":" )
54+ if len (credParts ) != 2 || credParts [0 ] == "" || credParts [1 ] == "" {
55+ log .Fatalf ("Error: toasterUrl credentials must include both ACCOUNTID and PASSWORD" )
56+ }
57+ }
58+
3159 tofuguStruct .TofiName , _ = cmd .Flags ().GetString ("tofi" )
3260 tofuguStruct .OrgName , _ = cmd .Flags ().GetString ("org" )
3361 tofuguStruct .Workspace , _ = cmd .Flags ().GetString ("workspace" )
34- tofuguStruct .ToasterUrl = os . Getenv ( "toasterurl" )
62+ tofuguStruct .ToasterUrl = toasterUrl
3563 tofuguStruct .DimensionsFlags , _ = cmd .Flags ().GetStringSlice ("dimension" )
3664 tofuguStruct .TofiPath , _ = filepath .Abs (tofuguStruct .GetStringFromViperByOrgOrDefault ("tofies_path" ) + "/" + tofuguStruct .OrgName + "/" + tofuguStruct .TofiName )
3765 if tofuguStruct .GetStringFromViperByOrgOrDefault ("shared_modules_path" ) != "" {
0 commit comments