Browse Source

Merge pull request #206 from CatalystCode/bugfix/azure-database-url

Bugfix/Encode username in Azure DATABASE_URL
pull/202/head
Hiroki Nakayama 5 years ago
committed by GitHub
parent
commit
3f630d66d9
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 3 deletions
  1. 10
      app/server/tests/test_config.py
  2. 18
      azuredeploy.json

10
app/server/tests/test_config.py

@ -24,15 +24,23 @@ class TestDatabaseUrl(TestCase):
with setenv('DATABASE_URL', 'pgsql://u:p@h/d?sslmode=require'): with setenv('DATABASE_URL', 'pgsql://u:p@h/d?sslmode=require'):
self._assert_sslmode_is('require') self._assert_sslmode_is('require')
def test_database_url_with_complex_user(self):
with setenv('DATABASE_URL', 'pgsql://user%40host:p@h/d'):
self._assert_user_is('user@host')
def _assert_sslmode_is(self, expected): def _assert_sslmode_is(self, expected):
reload(settings)
actual = settings.DATABASES['default'].get('OPTIONS', {}).get('sslmode') actual = settings.DATABASES['default'].get('OPTIONS', {}).get('sslmode')
self.assertEqual(actual, expected) self.assertEqual(actual, expected)
def _assert_user_is(self, expected):
actual = settings.DATABASES['default'].get('USER', '')
self.assertEqual(actual, expected)
@contextmanager @contextmanager
def setenv(key, value): def setenv(key, value):
environ[key] = value environ[key] = value
reload(settings)
yield yield
del environ[key] del environ[key]

18
azuredeploy.json

@ -97,11 +97,15 @@
"databaseSkuTier": "GeneralPurpose", "databaseSkuTier": "GeneralPurpose",
"databaseSkuFamily": "Gen5", "databaseSkuFamily": "Gen5",
"databaseSkuName": "[concat('GP_', variables('databaseSkuFamily'), '_', parameters('databaseCores'))]", "databaseSkuName": "[concat('GP_', variables('databaseSkuFamily'), '_', parameters('databaseCores'))]",
"databaseConnectionString": "[concat('pgsql://', parameters('adminUserName'), '@', variables('databaseServerName'), ':', parameters('adminPassword'), '@', variables('databaseServerName'), '.postgres.database.azure.com:5432/', parameters('databaseName'))]",
"databaseVersion": "9.6", "databaseVersion": "9.6",
"databaseServerPort": 5432,
"databaseServerName": "[concat(parameters('appName'),'-state')]", "databaseServerName": "[concat(parameters('appName'),'-state')]",
"databaseUserCredentials" : "[concat(uriComponent(concat(parameters('adminUserName'), '@', variables('databaseServerName'))), ':', parameters('adminPassword'))]",
"databaseFqdn" : "[concat( variables('databaseServerName'), '.postgres.database.azure.com:', variables('databaseServerPort'))]",
"databaseConnectionString": "[concat('pgsql://', variables('databaseUserCredentials'), '@', variables('databaseFqdn'), '/', parameters('databaseName'))]",
"setupScriptName": "[concat(parameters('appName'),'-setup')]", "setupScriptName": "[concat(parameters('appName'),'-setup')]",
"appServicePlanName": "[concat(parameters('appName'),'-hosting')]", "appServicePlanName": "[concat(parameters('appName'),'-hosting')]",
"appFqdn": "[concat(parameters('appName'),'.azurewebsites.net')]",
"analyticsName": "[concat(parameters('appName'),'-analytics')]" "analyticsName": "[concat(parameters('appName'),'-analytics')]"
}, },
"resources": [ "resources": [
@ -269,5 +273,15 @@
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanName'))]" "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanName'))]"
} }
} }
]
],
"outputs": {
"appServer": {
"type": "string",
"value": "[concat(variables('appFqdn'))]"
},
"databaseServer": {
"type": "string",
"value": "[variables('databaseFqdn')]"
}
}
} }
Loading…
Cancel
Save