How can we modify the hostingstart.html of kudu in the azure app service? - html

I'm doing all the work based on the code. I want to work on a simple task of edit and save hostingstart.html in kudu ui, but I don't know how to do it.
Currently, we have checked the connection through Azure app service distribution and dns authentication with terraform, and even checked whether the change is good through hostingstart.html in kuduui.
If possible, I wanted to work with the terraform code, so I wrote it as below and put the html file inside, but it didn't work.
(If it's not terraform, yaml or sh direction is also good.)
resource "azurerm_app_service" "service" {
provider = azurerm.generic
name = "${local.service_name}-service"
app_service_plan_id = azurerm_app_service_plan.service_plan.id
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
https_only = true
source_control {
repo_url = "https://git.a.git"
branch = "master"
}
}
Or can we specify the default path in the internal folder in this way?
tree : web
+page
- hostingstart.html
+terraform
- main.tf
- app_service.tf
site_config {
always_on = true
default_documents = "../page/hostingstart.html"
}
For the moment. It seems best to deploy and apply through blob storage.
(https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/storage_blob)

for Terraform you can’t easily edit that file from management plane APIs, which Terraform would use. Instead, you can deploy a minimal application with whatever you want to show. Here’s an example of deploying code with an ARM template: https://github.com/JasonFreeberg/zip-deploy-arm-template.

Related

Using Google Secret Manager with Firebase Functions and Stripe (top level)

Gday,
Quite new to TS and only got a little bit of experience with backend in general, so apologies if I am completely missing the idea.
So I really like the idea of using Google Secret Manager instead of custom env config for Firebase Functions.
Below is all done within a config.ts within my functions dir.
I need to initialize stripe. Traditional tutorials say to do something like the below example:
import Stripe from 'stripe';
export const stripeSecret = functions.config().stripe.secret;
const stripe = new Stripe(stripeSecret, {apiVersion: '2020-08-27'});
I think it would be ideal to change it to this:
import Stripe from 'stripe'
import {SecretManagerServiceClient} from '#google-cloud/secret-manager';
export async function getSecret(name:string){
const [version] = await secrets.accessSecretVersion({
name: `projects/example/secrets/${name}/versions/latest`,
});
return version.payload?.data?.toString();
}
export const stripeSecret = await getSecret("Stripe-API")
const stripe = new Stripe(stripeSecret, {apiVersion: '2020-08-27'});
But this causes an issue with it being async/await on the top level.
What are my options here and what is best practice?
The Google Secret manager is a useful utility and below are a few best practices when using Secret Manager.
You may try and use following to create and use a secret:
From the root of your local project directory, run the following command:
firebase functions:secrets:set SECRET_NAME
Enter a value for SECRET_NAME.
The CLI echoes a success message and warns that you must deploy functions
for the change to take effect.
Before deploying, make sure your functions code allows the function to access the secret using the runWith parameter:
exports.processPayment = functions
// Make the secret available to this function
.runWith({ secrets: ["SECRET_NAME"] })
.onCall((data, context) => {
const myBillingService = initializeBillingService(
// reference the secret value
process.env.SECRET_NAME);
// Process the payment});
Deploy Cloud Functions:
firebase deploy --only functions
You can also access it like any other environment variable. Conversely, if another function that does not specify the secret in runWith tries to access the secret, it receives an undefined value:
To see the complete best practices list, please visit the next link [1] and to know more about managing secret versions, please take a look at the next link [2].
[1] https://cloud.google.com/secret-manager/docs/best-practices
[2] https://cloud.google.com/secret-manager/docs/managing-secret-versions

Is it possible to add service redirect in development mode in Angular 6

I'm working on an App in Angular 6. When the app is deployed, it exchanges data with an online database. When I'm working on the app, however, I would like it to exchange data with a local database. I have a single service setup to do all of the communication, so when I am working on the app I can simply change the base URL, but I was wondering if there was a way I could just redirect that service in development, and then have it go to the database as normal in the production environment.
I am aware I can add a proxy.conf.json file, which I'm already doing to access a separate online API, so I dont know if it is as simple as just adding another element to that json file.
I haven't posted any sample code as this is more of a general question as to methodology in angular versus a specific line of code question, but I'm happy to post whatever people would like to see for clarification.
You can do one thing,
you can configure your url in both environment.ts and environment.prod.ts like
environment = {
...
url: 'something.com/api',
...
}
and use it like
import { environment } from 'environment/environment';
const url = environment.url;
this will give you different url for normal build (Development env.) and prod build (Deploy env.)
Also, don't worry about using just environmet.ts in import statement, as when you create prod build your environment.ts gets content from environment.prod.ts. so you will be using url from environment.prod.ts
In Angular you have access to a function isDevMode() which determines if the app is currently in devmode.
Based on that, you should be able to adjust your base url as needed.
import { isDevMode } from '#angular/core';
private baseUrl: string = '';
const devUrl: string = '...';
const prodUrl: string = '...';
if (isDevMode()) {
this.baseUrl = devUrl
}
else {
this.baseUrl = prodUrl
};

Use google api client in cakephp 3

I have been trying to use the google api client in cakekphp 3, but not successful on adding the service account json file to my project.
The below line is mentioned in:
https://github.com/googleapis/google-api-php-client
putenv('GOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account.json');
But that doesn't work on cakephp 3. I know I can add it to the .env.default file, but it is not recommended for production.
How to use it then?
This function defines a default credentials setting path to be used, but note that you have not called it yet.
You must "tell" your application to use its default credentials settings.
// app.php
putenv('GOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account.json');
// In the file you want to use Google Client
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
CakePHP also can read an specific file for env variables:
// config/.env
export GOOGLE_APPLICATION_CREDENTIALS="/path/to/service-account.json"
// Uncomment this part of your bootstrap.php
if (!env('APP_NAME') && file_exists(CONFIG . '.env')) {
$dotenv = new \josegonzalez\Dotenv\Loader([CONFIG . '.env']);
$dotenv->parse()
->putenv()
->toEnv()
->toServer();
}
Keeping your setup on .env files make it easier maintaining all your settings up to date.

JSON environnement variable is seen as a string

I'm trying to help a friend about his nodejs application.
He use NodeMailer to send emails automatically. We both use ubuntu.
To avoid any leaks, the credential for NodeMailer are set as an environnement variable called EMAIL_CREDENTIALS.
In the app, EMAIL_CREDENTIAL is called as follow:
var emailCredentials = process.env.EMAIL_CREDENTIALS;
if (emailCredentials === 'undefined') {
throw Error('Email credentials are not present');
}
// create reusable transporter object using the default SMTP transport
var transporter = nodemailer.createTransport(emailCredentials);
To set email credential I added a line in src/environnement :
EMAIL_CREDENTIALS={host:"smtp.gmail.com", port: 587, secure: false, auth: {user: "**user**", pass: "**pass**"}}
When I run some test, NodeMailer return the following error
Error: Unsupported configuration, downgrade Nodemailer to v0.7.1 to use it
at Nodemailer.sendMail (/home/**path**/node_modules/nodemailer/lib/nodemailer.js:274:18)
This error happen because type of param === 'string' in nodemailer.createTransport(param) .
My friend has been using this code for a pretty long time with no problem.
Somehow, I understand where the error come from but I would like to know how is it possible that the environnement variable of my friends setup isn't a string and mine is ? And how should I set my variable to be able to run his code without modifying it ?
EDIT: To use JSON.parse() would be a solution but I would prefer not to modifie the app code and as I said this configuration seems to work for my friend so I would like to understand where's the difference.
It is better not to use environment variables for other than simple values. I would suggest you to use a plain JS or JSON file with those variables, that you can simple require(). You can ignore this file via .gitignore, if you do not want it to be included in a git repository.
You can take a look at my configuration module here: https://www.npmjs.com/package/mikro-config
It is designed to be used this way.
Using it, your general configuration will be stored in /config/default.js file, and your environment specific configuration will be stored in /config/env/$NODE_ENV.js file (or in /config/env/$NODE_ENV.local.js, which should be ignored by git, as I described above).

How to get custom-resource file after packaging Metro App?

I have a Metro application in which am using different service URLs for receiving the data.For this scenario I want to change service URLs after building my application into a package.I have followed adding resource files into my app as mentioned in MSDN sites and tested by using following code.
var resourceLoader = new Windows.ApplicationModel.Resources.ResourceLoader();
var resourceString = resourceLoader.getString("greeting");
Here am getting greeting resource value string in my app before packaging.After packaging am not able to see my resource files but am able to see default resource files like en-US,fr-FR etc but.
Can anyone suggest some solution to get custom-resource file after packaging?
The way I see it you need to add the resource files before packaging the app... after that's done, you can not additional resources... what you could do is getting the new service url from a service and save it locally as a setting or in your DB
edit: also, resourceLoader.getString("greeting").value; will give you the actual string, or "greeting" in case no resources were found