Showing posts with label Google Cloud Platform. Show all posts
Showing posts with label Google Cloud Platform. Show all posts

Tuesday, May 29, 2018

dispatch.yaml

Override routing rules, to specific service.
  1. Create a dispatch.yaml
  2. Write Code
dispatch:
  - url: '*/favicon.ico'
    service: default
  - url: 'myurl.com/*'
    service: myservice
  1. cd dispatchfilepath
  2. gcloud config list (check is it in project ?)
  3. gcloud config set project [myproject] (if u not in project)
  4. gcloud app deploy dispatch.yaml

Wednesday, May 2, 2018

Connect Cloud SQL through local

1) make sure you are connecting to project
2) cd to cloud_sql_proxy.exe folder path
3)cloud_sql_proxy -instances=[isntancename]=tcp:3308

make sure port not resuse.

https://cloud.google.com/sql/docs/mysql/quickstart-proxy-test

Tuesday, May 1, 2018

GCP .NET Core Connect MYSQL

1) Authorization set 0.0.0.0/0  (this will allow everyone to connect, to secure it, use SSL (number 2).
2) SSL Connections (Allow SSL connections only)
3) Create Client Certificate (3 File - Client, Key, Server) pem
4) This 3 Files can put in MYSQL workbrench
5) Infra create pfx, this file will put in VS code and password.
6) Appsetting.json

"Connectionstrings": {
  "ConnectionApp":"Uid=[id];Pwd=[password];Server=[ip];port=3306;Database=[dbName]",
  "SSLCertFile": "[mysql.pfx]",
  "SSLCertPassword": "[sslPassword]"

},

7) Code

public MySqlConnection AppConnection()
{
    var connectionString = new MySqlConnectionStringBuilder(ConnectionApp)
    {
       SslMode = MySqlSslMode.Required,
       CertificateFile = System.IO.Path.Combine(Directory.GetCurrentDirectory(), "SSL", SSLCertFile),
        CertificatePassword = SSLCertPassword,
        AllowUserVariables = true,
    };

    return new MySqlConnection(connectionString.ConnectionString);

}

8)Every Method

using (MySqlConnection conn = CargoTrackConnection())


Monday, April 16, 2018

GCP .Net Core Error Reporting

If use Log, it will log duplicate, so just throw exception, code below is throw exception with response 500 and exception class.

//Startup.cs After this

app.UseGoogleTrace();

app.UseExceptionHandler(
 options =>
 {
     options.Run(
     async context =>
     {

         context.Response.Headers.Add("Access-Control-Allow-Origin", "*"); //Allow Origin
         context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
         context.Response.ContentType = "application/json";
         var ex = context.Features.Get<IExceptionHandlerFeature>();
         if (ex != null)
         {
             var err = JsonConvert.SerializeObject(ex.Error);
             await context.Response.WriteAsync(err).ConfigureAwait(false);
         }
     });
 }
);

//Before this 
app.UseMvc();

----------------

try
{
    return Ok(result);
}
catch (Exception ex)
{
    throw ex;
}

Thursday, October 12, 2017

Cron Job

  1. Create a cron.yaml
  2. Write Code
cron:
- description: Update Today Flight job
  url: /api/Flight/UpdateTodayFlights/KUL

  schedule: every day 02:00
  1. cd yamlfilepath
  2. gcloud app deploy cron.yaml

Monday, September 11, 2017

Firebase Cloud Function

  • Function for Fire base features (trigger event by firebase)
    • in GCP, not your mobile (light for your mobile app)
    • Logic Centralized , safe, server less
  • Example
    • Write Realtime Database trigger function
    • Upload your storage bucket
    • New user authentication
    • Incoming HTTPS requests
    • Send Message
  1. Install Node.JS
  2. Install Firebase CLI
    • npm install -g firebase-tools
  3. cd to folder (firebase cloud function project)
  4. firebase login
  5. firebase init (Deselect Database and Hosting)

https://www.youtube.com/watch?v=EvV9Vk9iOCQ#t=314.64541


Thursday, August 24, 2017

Google Cloud Web API c#

1. Create Project  > Google Cloud ASP.NET Core Web API C#
2. Choose Google Project ID (can link with FireBase)

If you want run locally you need to add credential


3. Create  json file,
4. Copy this .json file to locally (outside cannot browse)


public Startup(IHostingEnvironment env)
{
      //Here is the Code for Credential
    string credential_path = "CargoTracking-2e89f93ec38b.json";
    Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", credential_path);

------------------------

[GCP Command]
gcloud config list
gcloud auth login
gcloud config set project [myproject]