I'm using JHipster 4 to build Microservices. I have created an application without H2. But now we need one for development.
How to enable H2? i added H2 in the application-dev.yml :
h2:
console:
enabled: false
jpa:
database-platform: io.github.jhipster.domain.util.FixedH2Dialect
database: H2
show-sql: true
properties:
hibernate.id.new_generator_mappings: true
hibernate.cache.use_second_level_cache: true
hibernate.cache.use_query_cache: false
hibernate.generate_statistics: true
But it doesnt work. I can't access it
You could simply modify your .yo-rc.json by modifying the 2 entries:
"devDatabaseType": "h2Disk",
"prodDatabaseType": "postgresql",
and then regenerate your app/service by calling the jhipster generator.
Related
How do I apply EF migrations to multiple databases, referencing either a Development or Production environment as required?
TL;DR
I'm developing an ASP.NET Core MVC application using Entity Framework that references different databases for Development and Production. Both databases are hosted Azure SQL databases.
The application at the moment is running on IIS Express on my Development machine, but I will deploy Production to an Azure App Service. I'm using Entity Framework and migrations to update the database design.
I've applied this answer to use a different database connection string for either the Development or Production launch configurations, and this seems to be working. The connection strings are then stored in appsettings.Development.json or appsettings.Production.json.
When I select the DEV launch configuration, I am able to use the EF cli command dotnet ef database update in order to apply my migrations to the development database. Works fine.
However, I cannot work out how to tell Visual Studio to apply each migration to the production database when I run under the PROD launch configuration.
Running the command dotnet ef database update after changing the launch configuration continues referencing the development database, and nothing changes. I'm not surprised by this - I haven't told Visual Studio where to find the other database. But I also can't work out how to do this.
Is there a way to change the referenced database, based on the launch configuration or environment variables? Or some other convenient way?
launchSettings.json
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:57961",
"sslPort": 44320
}
},
"profiles": {
"IIS Express (dev)": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express (prod)": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Production"
}
}
}
}
According to the documentation, you can specify the connection string as an extra parameter:
--connection: The connection string to the database. Defaults to the one specified in AddDbContext or OnConfiguring.
So this command will let you specify which database you are targeting:
dotnet ef database update --connection "<sql connection string>"
context: I'm adding a new resource foo to Terraform provider.
The interesting detail about foo is that the corresponding POST API request requires to pass 0 or more secret values (best represented as a TypeMap) and then these secrets are pretty much useless (both READ, UPDATE work without it) and I think it doesn't really makes sense to store these secrets in Terraform configuration / state which is why I'd like to set this secrets_map attribute to either null or empty map.
So I started with this definition for this resource:
"secrets_map": {
Type: schema.TypeMap,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Sensitive: true,
Optional: true,
Computed: true,
ForceNew: false,
},
I picked Optional + Computed over Required: true because d.Set("secrets_map", make(map[string]string)) was failing but I'm still running into some issues. Is there an example of such a setup?
My ideal workflow would be:
Import works doesn't require user to set secrets_map at all.
Initially a user sets secrets_map attribute to allow Terraform Provider to read secrets to set them in CREATE request and then terraform apply / plan to ensure everything is in sync and then a user deletes this block from their TF configuration file, runs terraform apply to update secrets_map in TF state and then there're no changes when someone runs terraform plan.
I also figured DiffSurpressFunc doesn't really work for TypeMap which is a bummer: Is it possible to use DiffSuppressFunc for a TypeMap in Terraform SDK v2?
My newest idea is to set secrets_map to null in fooRead().
I've deployed an Azure Function to Azure. I have not specified AZURE_FUNCTIONS_ENVIRONMENT to be "Development" anywhere in the Application Settings, or anywhere else in the environment.
However, when the following code executes
var configurationBuilder = new ConfigurationBuilder()
.SetBasePath(basePath)
.AddJsonFile("appsettings.json", true, true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", true, reloadOnChange: true);
$"appsettings.{env.EnvironmentName}.json"resolves to "appsettings.Development.json", and as such the Development configuration is loaded instead of the Production config.
When I view the Environment variables of that environment via Kudu, I don't see any references to Development at all, and in fact see WEBSITE_SLOT_NAME = Production configured (though that's not necessarily relevant to a Function.
My understanding is that if no Environment is specified then the runtime defaults to Production. As such, this implies to me that Development is specified somewhere. I have no idea where to look for that though.
Question:
Is it possible that Development could be specified somewhere that isn't in App Settings or Environment variables? If so, where? Is there anywhere I could look for it, or is there any other explanation for why the Development configuration is being loaded instead of Production? What should I do to explicitly ensure the Production configuration is loaded in the Production environment?
Unfortunately I couldn't get this to work until I manually specified that I wanted the data from Environment Variables:
var environment = Environment.GetEnvironmentVariable("AZURE_FUNCTIONS_ENVIRONMENT");
var configurationBuilder = new ConfigurationBuilder()
.SetBasePath(basePath)
.AddJsonFile("appsettings.json", true, true)
.AddJsonFile($"appsettings.{environment}.json", true, reloadOnChange: true);
Which required that I specify the value in Application Settings in the Azure environment:
And in the launchSettings.json file as
"environmentVariables": {
"AZURE_FUNCTIONS_ENVIRONMENT": "Development"
}
.NET Core uses the ASPNETCORE_ENVIRONMENT and Hosting:Environment environment variables for env.EnvironmentName. WEBSITE_SLOT_NAME is set by Azure and indicates the name of the Deployment Slot hosting the app.
You'd better set it in App settings or Environment variables if you want to have a better control.
Just for your case, you should remember that when you use the code:
.AddJsonFile("appsettings.json", true, true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", true, reloadOnChange: true);
the 2nd .AddJsonFile() method should always override the first .AddJsonFile() method, if both appsettings.json and appsettings.development.json exist.
So if you just want to make sure it uses production config without using App setting or environment variable, just specify your production config( it is appsettings.json file) in the 2nd .AddJsonFile() method.
I have configured an Azure application as type "Web app / API", but would like to switch it to "Native". According to https://blogs.msdn.microsoft.com/aaddevsup/2018/04/11/changing-an-existing-native-application-to-a-web-appapi-to-get-existing-keys/, the reverse seems possible. It says that I should edit the manifest's 'publicClient' field, which is, "the field that determines whether an application is a web app/api or native application. When it is true, it is a native application otherwise it is a web app." However, both editing the app manifest on the web UI and uploading a newly edited copy of the manifest will return the message, "Failed to update application xxx. Error details: GenericError".
Is there a way to do this at all, or should I start from scratch?
To fix the issue, before you set the publicClient to true, you need to set the "identifierUris": [xxxxxx] to "identifierUris": [] in the Manifest
, then it will work fine.
According to the link you provided, there are 2 important notes
The goal of the steps provided in the article is changing Native app to Web App, which does not necessarily mean it will work the other way around.
This is a work around and is not recommended
Note : This is not recommended practice, and this is solely meant for
customers who have keys on their native application but can't get to
them anymore; so they need a workaround to get access to the native
application Keys
So, my recommendation is to start from scratch because even if it worked, it will not be supported
However, below are the main differences between native app manifest and web app manifest. Check if this works for you.
Key/Value pairs in Native App Manifest
"availableToOtherTenants": true
"homepage": null,
"identifierUris": [],
"oauth2Permissions": [],
"publicClient": true,
In my sails application, I have created the Data model and controller (blueprint model).
I have set up the following policies to only authorize the creation of new data.
module.exports.policies = {
// Prevent all actions
'*': false,
// Data controller's policies
DataController:{
'*': false,
'create': true
}
};
This does not work and prevent all the actions. Does not 'create' rules have priority over the rules above it ?
UPDATE
My mistake, DataController should be replaced by data (thanks to the #sailsjs IRC).
I have updated the policies order but this is not working either:
module.exports.policies = {
// Data controller's policies
data:{
'create': true,
'find': false,
'findAll': false,
'update': false,
'destroy': false
}
};
With this code, even the 'create' action is forbidden when this is the only one I need open to anyone.
I assume you are using the built in blueprints that Sails.js provides
You will find that the following policies will allow you to access the '/data/create' route
data: {
'find': true,
'create': true,
'update': true,
'destroy': false,
'findAll': false
}
I am unsure why your policies have to be configured like this in order for you to access the 'create' route, but I suppose it has something to do with the way blueprints are implemented behind the scenes
A possible work around to your problem is to create your own routes that override the default blueprints provided by Sails. For example, mapping '/data/create' to a createData method within the Data controller and then specifying the policies that apply to this method.
My understanding is that these CRUD routes are only intended for use during development, you will find that this is also stated within the config/controllers.js file
// These CRUD shortcuts exist for your convenience during development,
// but you'll want to disable them in production.
// '/:controller/find/:id?'
// '/:controller/create'
// '/:controller/update/:id'
// '/:controller/destroy/:id'
As blueprints are not intended to be used in production, writing policies that target these default CRUD shortcuts serves no purpose. So, another option would be to disable blueprints altogether in config/controllers.js and instead apply policies to your own custom routes and methods.