Use config.Enviornment() to find MySQL AAD resource ID
@@ -31,6 +31,23 @@ const DriverName = "mysql"
// assume will exist).
const SystemDatabase = "mysql"
+func GetMySQLAADResourceID() string {
+ // TODO: Switch this to use config.Environment().ResourceIdentifiers.OSSRDBMS
+ // TODO: when that change is in azure-go-sdk
+ // TODO: See: https://github.com/Azure/go-autorest/pull/635
+ envName := config.Environment().Name
+
+ if envName == "AzureUSGovernmentCloud" {
+ return "https://ossrdbms-aad.database.usgovcloudapi.net"
+ } else if envName == "AzureChinaCloud" {
+ return "https://ossrdbms-aad.database.chinacloudapi.cn"
+ } else if envName == "AzureGermanCloud" {
+ return "https://ossrdbms-aad.database.cloudapi.de"
+ }
+
+ return "https://ossrdbms-aad.database.windows.net"
+}
+
func GetMySQLDatabaseDNSSuffix() string {
// TODO: We need an environment specific way of getting the DNS suffix
// TODO: which the Go SDK doesn't seem to have.
@@ -84,7 +101,7 @@ func ConnectToSQLDBAsCurrentUser(
user string,
clientID string) (*sql.DB, error) {
- tokenProvider, err := iam.GetMSITokenProviderForResourceByClientID("https://ossrdbms-aad.database.windows.net", clientID)
+ tokenProvider, err := iam.GetMSITokenProviderForResourceByClientID(GetMySQLAADResourceID(), clientID)
if err != nil {
return nil, err
}
