I've created a spring boot application that is deployed on heroku.
Everything works fine.. Now, I am trying to use the Text to Speech api from google cloud. This works fine locally but when I want to use it on heroku i get the warning.
Error reading credential file from environment variable
GOOGLE_APPLICATION_CREDENTIALS, value 'config/keyFile.json': File does
not exist.
I've set in heroku the following :
heroku config:set GOOGLE_APPLICATION_CREDENTIALS=‘config/keyFile.json’
No matter where i put the file.. I cannot get it to work.
Who can help?
I got this to work by setting a heroku config variable (say GOOGLE_APPLICATION_CREDENTIALS) with the contents of the GOOGLE_APPLICATION_CREDENTIALS json file and calling the process.env.GOOGLE_APPLICATION_CREDENTIALS where the client needs to be instantiated.
In any case, it is not a best practice to save key files to a remote server (such as heroku), and is safer to call the key using an environment variable.
// Where you need to instantiate the google project client,
var keyValue = JSON.parse(process.env.GOOGLE_APPLICATION_CREDENTIALS);
// set the 'credentials' parameter with keyValue
I had a similar issue with vercel where it was unable to find the serviceaccount.json. I finally got it to work by passing the credenitals to directly to the TextToSpeechClient constructor as an object. Just remember to use environment variables for the sensitive properties.
const client = new textToSpeech.TextToSpeechClient({
credentials: {
type: "service_account",
project_id: "",
private_key_id: "",
private_key:"",
client_email: "",
client_id: "",
auth_uri: "",
token_uri: "",
auth_provider_x509_cert_url: "",
client_x509_cert_url:"",
},
});
You can see the Google documentation here: https://cloud.google.com/nodejs/docs/reference/text-to-speech/latest/text-to-speech/v1.texttospeechclient
The documentation is not very clear as to how the ClientOptions object should look like. I just took a guess at the credentials {credentials:{}} part and it worked.
Hope this helps who what to deploy to the cloud and are struggling with getting the right path to the serviceaccount.json
Related
I want to move the appsettings.json file inside the app folder, but when I do that the object Configuration in the startup class cannot access to connection string.
If I leave the appsettings.json file in the root as it comes by default, everything works correctly. Does anyone know what it is due to and how to solve it?
You can try to set the app's configuration by calling ConfigureAppConfiguration when building the host, like below.
.ConfigureAppConfiguration((hostingContext, config) =>
{
config.AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), "app", "appsettings.json"),
optional: false, reloadOnChange: false);
})
For more information about configuring the JSON configuration provider to load the specific json settings file, please check this doc: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-5.0#json-configuration-provider
Hi Experts,
I am following https://open.sap.com/courses/s4h13/items/258qEhXx5kdG8b4SXMSJYp tutorial, after deploying the app I am getting 404 for my servlets in approuter application while same servets are giving me 'http 401' in 'address-manager' as expected.
has anyone done this successfully? if so then please guide me in the right direction.
I have gone through everything I could think of, but I can't get past this issue.
xs-app.json file content
{
"welcomeFile": "index.html",
"routes": [
{
"source": "^/api/(.*)",
"target": "/api/$1",
"destination": "app-destination"
},
{
"source": "^/address-manager/(.*)",
"target": "/address-manager/$1",
"destination": "app-destination"
}],
"logout" : {
"logoutEndpoint": "/logout",
"logoutPage": "/logout.html"
}
}
The destinations environment variable of the approuter on SAP Cloud Platform, Cloud Foundry needs to reference the URL(s) at which you reach the application(s) that you want to access via the route(s) defined in the approuter. (Not to be confused with the destinations environment variable that you may be using as a placeholder in athe backend application built with the SAP S/4HANA Cloud SDK.)
In your case, this should probably be some URL pointing to the address-manager, your target application. In the example value mentioned in your comment, you point to the mock server instead, which is probably not what you want.
Change the destinations environment variable to the following and push / restart the application again. (Insert the URL that points to your address manager application deployment.)
[{"name":"app-destination", "url" :"address-manager-<random text>.cfapps.eu10.hana.ondemand.com/", "forwardAuthToken": true}]
The fact that you can login and logout despite the misconfigured destination is expected, because those paths are actually served by the approuter itself.
I'm loosing my mind.
I'm using Shrine (https://github.com/janko-m/shrine) with Google Cloud Storage (https://github.com/renchap/shrine-google_cloud_storage), but when I start the PUT call I get this:
<Error>
<Code>SignatureDoesNotMatch</Code>
<Message>
The request signature we calculated does not match the signature you provided. Check your Google secret key and signing method.
</Message>
<StringToSign>
PUT
image/jpeg
1518399402
/mybucket.appspot.com/7d5e4aad1e3a737fb8d2c59571fdb980.jpg
</StringToSign>
</Error>
I followed this info (http://shrinerb.com/rdoc/classes/Shrine/Plugins/PresignEndpoint.html) for presign_endpoint, but still nothing:
class FileUploader < Shrine
plugin :presign_endpoint, presign_options: -> (request) do
filename = request.params["filename"]
extension = File.extname(filename)
content_type = Rack::Mime.mime_type(extension)
{
content_type: content_type
}
end
end
I tried with and without this (restarting the Rails server everytime).
Where am I wrong?
I also tried with Postman with a PUT to that URL and withtout any content-type. But still nothing.
I read here: https://github.com/GoogleCloudPlatform/google-cloud-node/issues/1976 and here: https://github.com/GoogleCloudPlatform/google-cloud-node/issues/1695
How can I try without Rails?
Is there a REPL (or similar) to try with my credentials and with a file?
You have several options for just uploading a file to Google Cloud Storage as you can see in the official docs here.
For example if you want to use Ruby Client Library, you can use this code:
# project_id = "Your Google Cloud project ID"
# your-bucket-name = "Your Google Cloud Storage bucket name"
# local_file_path = "Path to local file to upload"
# storage_file_path = "Path to store the file in Google Cloud Storage"
require "google/cloud/storage"
storage = Google::Cloud::Storage.new(project: "your-project_id")
bucket = storage.bucket "your-bucket-name"
file = bucket.create_file "local_file_path", "storage_file_path"
puts "Uploaded #{file.name}"
You will need to:
Set the environment variable GOOGLE_APPLICATION_CREDENTIALS to the file path of the JSON file that contains your service account key.
as you can see in the Cloud Storage Client Libraries docs here.
However, it looks like the github repo you are using makes use of signed URLs. If you need to create a signed URL you have the instructions here. It exists already the signed_urls method for Ruby in the official repo.
Anyway, the error you were getting is because there was something wrong being made with the signed urls. And precisely there was a commit to the repo you were referencing (https://github.com/renchap/shrine-google_cloud_storage) 7 days ago with the name Fix presigned uploads. It looks like this commit should fix the "PUT" upload (before a "GET" was being signed, therefore it wouldn't work). Still I didn't try it so I don't know if it is actually working.
I am using Ion Auth for registration, and everything is working fine on local, So when I wanted to move Live server I need email activation for new registrations [I am not using SMTP, there is no email config file in my config folder], So I made changes in ion_auth.php in config file as follows::
$config['email_activation'] = TRUE;
$config['manual_activation'] = FALSE;
$config['use_ci_email'] = TRUE;
as far as I know about this library (I am new to CodeIgniter), that's it. But unfortunately these configurations are not taking effect. When I var dump the following items inside constructor of ion_auth.php library file returns null
$this->config->item('use_ci_email','ion_auth') or
$this->config->item('email_activation','ion_auth')
And other config items like 'admin_email' has no issues, I can fetch the value. So, what is wrong with my config file, I am using very basic file provided by the library repo.
When I set the values, inside the constructor of library file as below, it works.
$this->config->set_item('use_ci_email', TRUE);
$this->config->set_item('email_activation', TRUE);
Is there anything wrong I am doing to get this weird behavior.
Ok, so I opened an issue on Ion Auth Git repo, and the Author, Ben Edmunds responded with the solution, If anybody facing this issue, with latest CodeIgniter, please pull the latest commit of IonAuth library and test, It will work.
For more on the issue, please refer the isse,
Codeigniter Ion Auth configuration and Email Activation
I am trying to use Slack to post my debug messages to. i have followed some exmaple code and have this in my app.php file
$app->configureMonologUsing(function ($monolog) {
$monolog->pushHandler($chromeHandler = new \Monolog\Handler\ChromePHPHandler());
$chromeHandler->setFormatter(new \Monolog\Formatter\ChromePHPFormatter());
$slackHandler = new \Monolog\Handler\SlackHandler('xoxp-dasdasdzxczxcasdasdasdas', '#general');
$slackHandler->setLevel(\Monolog\Logger::INFO);
$slackHandler->setFormatter(new \Monolog\Formatter\LineFormatter());
$monolog->pushHandler($slackHandler);
});
which works and send mesages to slack using the following command
Log::info('thing to log');
I want to only send debug messages to slack if I am on a local machine.
I have tried reading in the the APP_ENV variable using env() but it is not returning anything.
I can access it using the same code in the controller. THerefore I assume it has not been loaded in the app.php file when I am trying to get it.
is there a better place to add the slack code, or anther way to detect the env variable?