@@ -21,12 +21,49 @@ import (
2121 "github.com/utmstack/UTMStack/plugins/azure/config"
2222)
2323
24+ type AzureCloud string
25+
2426const (
25- defaultTenant string = "ce66672c-e36d-4761-a8c8-90058fee1a24"
26- urlCheckConnection = "https://login.microsoftonline.com/"
27- wait = 1 * time .Second
27+ defaultTenant string = "ce66672c-e36d-4761-a8c8-90058fee1a24"
28+ wait = 1 * time .Second
29+
30+ AzurePublic AzureCloud = "AzurePublic"
31+ AzureGovernment AzureCloud = "AzureGovernment"
32+ AzureChina AzureCloud = "AzureChina"
2833)
2934
35+ type CloudEndpoints struct {
36+ Name AzureCloud
37+ EventHubSuffix string
38+ StorageSuffix string
39+ LoginAuthority string
40+ Description string
41+ }
42+
43+ var SupportedClouds = []CloudEndpoints {
44+ {
45+ Name : AzureGovernment ,
46+ EventHubSuffix : ".servicebus.usgovcloudapi.net" ,
47+ StorageSuffix : ".core.usgovcloudapi.net" ,
48+ LoginAuthority : "https://login.microsoftonline.us/" ,
49+ Description : "Azure Government (US)" ,
50+ },
51+ {
52+ Name : AzureChina ,
53+ EventHubSuffix : ".servicebus.chinacloudapi.cn" ,
54+ StorageSuffix : ".core.chinacloudapi.cn" ,
55+ LoginAuthority : "https://login.chinacloudapi.cn/" ,
56+ Description : "Azure China (21Vianet)" ,
57+ },
58+ {
59+ Name : AzurePublic ,
60+ EventHubSuffix : ".servicebus.windows.net" ,
61+ StorageSuffix : ".core.windows.net" ,
62+ LoginAuthority : "https://login.microsoftonline.com/" ,
63+ Description : "Azure Public Cloud" ,
64+ },
65+ }
66+
3067func main () {
3168 mode := plugins .GetCfg ().Env .Mode
3269 if mode != "manager" {
@@ -46,12 +83,18 @@ func main() {
4683 defer ticker .Stop ()
4784
4885 for range ticker .C {
49- if err := connectionChecker (urlCheckConnection ); err != nil {
50- _ = catcher .Error ("External connection failure detected: %v" , err , nil )
51- }
52-
5386 moduleConfig := config .GetConfig ()
5487 if moduleConfig != nil && moduleConfig .ModuleActive {
88+ cloudsInUse := detectCloudsInUse (moduleConfig )
89+ for cloudName , loginAuthority := range cloudsInUse {
90+ if err := connectionChecker (loginAuthority ); err != nil {
91+ catcher .Info ("Airgap or limited connectivity detected" , map [string ]any {
92+ "cloud" : cloudName ,
93+ "loginAuthority" : loginAuthority ,
94+ })
95+ }
96+ }
97+
5598 var wg sync.WaitGroup
5699 wg .Add (len (moduleConfig .ModuleGroups ))
57100 for _ , grp := range moduleConfig .ModuleGroups {
@@ -76,6 +119,47 @@ func main() {
76119 }
77120}
78121
122+ func detectCloudsInUse (moduleConfig * config.ConfigurationSection ) map [string ]string {
123+ cloudsMap := make (map [string ]string )
124+
125+ for _ , group := range moduleConfig .ModuleGroups {
126+ for _ , cnf := range group .ModuleGroupConfigurations {
127+ if cnf .ConfKey == "eventHubConnection" || cnf .ConfKey == "storageConnection" {
128+ if cloud , err := detectCloudFromConnectionString (cnf .ConfValue ); err == nil {
129+ cloudsMap [string (cloud .Name )] = cloud .LoginAuthority
130+ }
131+ }
132+ }
133+ }
134+
135+ return cloudsMap
136+ }
137+
138+ func detectCloudFromConnectionString (connectionString string ) (CloudEndpoints , error ) {
139+ if connectionString == "" {
140+ return CloudEndpoints {}, fmt .Errorf ("connection string is empty" )
141+ }
142+
143+ connStrLower := strings .ToLower (connectionString )
144+
145+ for _ , cloud := range SupportedClouds {
146+ if strings .Contains (connStrLower , strings .ToLower (cloud .EventHubSuffix )) {
147+ return cloud , nil
148+ }
149+ if strings .Contains (connStrLower , strings .ToLower (cloud .StorageSuffix )) {
150+ return cloud , nil
151+ }
152+ }
153+
154+ for _ , cloud := range SupportedClouds {
155+ if cloud .Name == AzurePublic {
156+ return cloud , nil
157+ }
158+ }
159+
160+ return CloudEndpoints {}, fmt .Errorf ("unable to detect Azure cloud from connection string" )
161+ }
162+
79163func pull (group * config.ModuleGroup ) {
80164 agent := getAzureProcessor (group )
81165
0 commit comments