@@ -3,9 +3,11 @@ package environments
3
3
import (
4
4
"encoding/json"
5
5
"fmt"
6
+ "strings"
6
7
7
8
"github.com/Azure/InnovationEngine/internal/az"
8
9
"github.com/Azure/InnovationEngine/internal/logging"
10
+ "github.com/Azure/InnovationEngine/internal/patterns"
9
11
"github.com/Azure/InnovationEngine/internal/ui"
10
12
)
11
13
@@ -23,12 +25,13 @@ type AzureStep struct {
23
25
24
26
// The status of a one-click deployment or learn mode deployment.
25
27
type AzureDeploymentStatus struct {
26
- Steps []AzureStep `json:"steps"`
27
- CurrentStep int `json:"currentStep"`
28
- Status string `json:"status"`
29
- ResourceURIs []string `json:"resourceURIs"`
30
- Error string `json:"error"`
31
- Output string `json:"output"`
28
+ Steps []AzureStep `json:"steps"`
29
+ CurrentStep int `json:"currentStep"`
30
+ Status string `json:"status"`
31
+ ResourceURIs []string `json:"resourceURIs"`
32
+ Error string `json:"error"`
33
+ Output string `json:"output"`
34
+ ConfiguredMarkdown string `json:"configuredMarkdown"`
32
35
}
33
36
34
37
func NewAzureDeploymentStatus () AzureDeploymentStatus {
@@ -72,6 +75,52 @@ func (status *AzureDeploymentStatus) SetOutput(output string) {
72
75
status .Output = output
73
76
}
74
77
78
+ // Given a markdown string, replace the environment variables with the values
79
+ // provided in the environmentVariables map. Currently this is only used
80
+ // by the portal.
81
+ func (status * AzureDeploymentStatus ) ConfigureMarkdownForDownload (
82
+ markdown string ,
83
+ environmentVariables map [string ]string ,
84
+ environment string ,
85
+ ) {
86
+ if ! IsAzureEnvironment (environment ) {
87
+ return
88
+ }
89
+
90
+ for key , value := range environmentVariables {
91
+ exportRegex := patterns .ExportVariableRegex (key )
92
+
93
+ matches := exportRegex .FindAllStringSubmatch (markdown , - 1 )
94
+
95
+ if len (matches ) != 0 {
96
+ logging .GlobalLogger .Debugf (
97
+ "Found %d matches for the environment variable %s, Replacing them in markdown source." ,
98
+ len (matches ),
99
+ key ,
100
+ )
101
+ }
102
+
103
+ for _ , match := range matches {
104
+ oldLine := match [0 ]
105
+ oldValue := match [1 ]
106
+
107
+ // Replace the old export with the new export statement
108
+ newLine := strings .Replace (oldLine , oldValue , value + " " , 1 )
109
+ logging .GlobalLogger .Debugf ("Replacing '%s' with '%s'" , oldLine , newLine )
110
+
111
+ // Update the code block with the new export statement
112
+ markdown = strings .Replace (
113
+ markdown ,
114
+ oldLine ,
115
+ newLine ,
116
+ 1 ,
117
+ )
118
+ }
119
+ }
120
+
121
+ status .ConfiguredMarkdown = markdown
122
+ }
123
+
75
124
// Print out the status JSON for azure/cloudshell if in the correct environment.
76
125
func ReportAzureStatus (status AzureDeploymentStatus , environment string ) {
77
126
if ! IsAzureEnvironment (environment ) {
0 commit comments