Posts Tagged GAE

How to use https on Google App Engine for all requests for custom domain

Before use the settings below, make sure that you uploaded and assigned appropriate SSL certificate to your app project.

Forcing GAE to use https is very easy, just need to mention the option “secure” with value “always” in “app.yaml” file (other options are “optional” for using both http & https (default behavior) and “never” for using http only), the example below in for golang app, the same approach is used for other languages.

application: your-app-here
version: 1
runtime: go
api_version: go1

- url: /.*
  script: _go_app
  secure: always

, , , ,

Leave a comment

Setting SSL certificate for Google App Engine

Help on the topic can be found here: https://cloud.google.com/appengine/docs/python/console/using-custom-domains-and-ssl

Telling long story shortly:

1. Generate key & signing request with the command

openssl req -nodes -newkey rsa:2048 -keyout myserver.key -out server.csr

2. Send “server.csr” file to your favorite certificate issuer and receive .crt files

3. Convert your private key into the format google requires:

openssl rsa -in myserver.key -out private.key.pem

4. Concatenate all .crt file into one

cat www_example_com.crt ASecureServerCA.crt ATrustCA.crt ATrustExternal.crt > public.crt

5. Upload public.crt & private.key.pem in google cloud console

6. Map your certificate with the website and enjoy.

, , ,

1 Comment

Setup Sublime Text to work with golang and Google App Engine (mac)

If you want to create applications with GO, deploy them to google app engine and use Sublime Text as your IDE then this step-by-step tutorial is for you (tutorial is  for Mac but it can be used for other platforms)

Step 0:

Download and install golang SDK from Google:
https://cloud.google.com/appengine/downloads#Google_App_Engine_SDK_for_Go

Unpack it somewhere (I usually use the folder “$HOME/SDKs”)

Step 1:

Install Sublime Text 3, you can find it here:
https://www.sublimetext.com

Step 2:

Install package control for Sublime Text, find all relevant information about installation process here: https://packagecontrol.io/installation

Step 3:

Install GoSublime package: https://github.com/DisposaBoy/GoSublime

Press cmd+shift+p, type ‘Package Control: Install Package’ or select it from the list, then type GoSublime and install the package

Step 4:

Setup  variables GOROOT & GOPATH in your environment (put the information below into .bash_profile on Mac/Linux)

Type in command line

cd ~
open .bash_profile -a "Sublime Text"

And add following lines to the end of the file

# Change the variables below to the path where you installed go_appengine
export GOSDK=/Users/user/SDKs/go_appengine
export GOROOT=$GOSDK/goroot
export GOPATH=$GOSDK/gopath
export PATH=$GOSDK:$GOROOT/bin:$PATH

Step 5:

Go to $GOROOT/bin & $GOROOT/pkg folders and execute the a commands below to create appropriate symlinks (GoSublime does not know anything about ‘goapp’, it knows only about ‘go’, we should simulate it)

cd $GOROOT/bin
ln -s goapp go
cd $GOROOT/pkg
ln -s darwin_amd64_appengine darwin_amd64

Step 6:

Create your first go app for GAE: create folder somewhere and create there 2 files, hello.go with the following content

package hello

import (
    "fmt"
    "net/http"
)

func init() {
    http.HandleFunc("/", handler)
}

func handler(w http.ResponseWriter, r *http.Request) {
    fmt.Fprint(w, "Hello, world!")
}

and app.yaml with the following content (change gae-app-name-hello to real gae ID before deploying!)

application: gae-app-name
version: 1
runtime: go
api_version: go1

handlers:
- url: /.*
  script: _go_app

If you did everything correctly then your Sublime Text should have code completion and console to run go commands. Press in Sublime Text cmd+9 and type ‘build’ in the console, it should compile and build your app. If build is successful then go to terminal and type in the app folder ‘goapp serve’, the app will run locally, you can check it with your web browser on the link http://localhost:8080

Step 7:

Deploy your app using command ‘goapp deploy’ in your app folder (do not forget to perform all the prerequisites to setup app engine, check this link for more info: https://cloud.google.com/appengine/docs/go/gettingstarted/uploading)

Enjoy!

, , , , , , ,

Leave a comment

Allow google app engine project to access storage bucket of the other project

  1. Go to Google Developer console and open the project where you want to have an access to storage bucket of another project
  2. Open menu “Permissions” and go to the tab “Service accounts”
  3. Copy the account ID marked as “App Engine default service account” (should be something like your_app_id@appspot.gserviceaccount.com)
  4. Switch in the console to the project with storage bucket
  5. Go to the menu “Storage” and call the menu on the bucket you want to share (3 dots on the right side) and select “Edit bucket permissions”
  6. Add new item with “User” as entity putting there the copied above account ID, select appropriate permission (read, write, owner)

That’s it.

, , , , ,

Leave a comment

How to create simple webservice using GO (golang) on GAE

This tutorial will show how to create simple webservice application using GO on Google Application Engine (GAE), I’m going to cover the following topics:

  1. Creating project in GAE
  2. Creating and testing application locally
  3. Using martini package to simplify service development
  4. Deployment of the services to GAE

First of all, go to Google Developer Console and create new project:

https://console.developers.google.com/project

Screenshot 2015-09-09 09.22.54

Select project name and open advanced options, make sure that you are selecting the proper region you want to use, it is important as if we are going to add SQL Cloud later to our project and the region of the project & SQL Cloud should be the same to work together.

Screenshot 2015-09-09 09.29.28

Give some minutes to Google and you should see the picture as shown below with your project ready to be developed. Copy Project ID (in my case it is tutorial-golang, you will defenitely have different name) to you favourite text editor on your computer, we will need it later when we prepare our first deploy of the application

Screenshot 2015-09-09 09.35.42

Read the rest of this entry »

, , , , , , , , , ,

Leave a comment

Using GO + Sublime Text + GoSublime + GAE

Sometimes easy things are not so obvious as they really are. If you are using GO language together with Sublime Text and want to have in place such features as code completion, you obviously will start using GoSublime plugin. If you are using GO in GAE (Google Application Engine) for your developments than you need small tuning to make it work.

  1. First of all, make sure  GOROOT and GOPATH are set in your environment (or in Sublime Text settings) and pointing to the GAE version of GO
  2. Go to GOROOT/bin folder and make a symlink for “goapp” naming it “go”
  3. Go to GOROOT/pkg folder and make a symlink for “darwin_amd64_appengine” naming it “darwin_amd64”

Enjoy.

, , , , , , , , , , ,

1 Comment

How to use basic authentication on GAE with PHP

As you probably noticed PHP in Google Application Engine does not provide the variables $_SERVER[‘PHP_AUTH_USER’] and $_SERVER[‘PHP_AUTH_PW’]. You can perform basic authentication anyway using the variable $_SERVER[‘HTTP_AUTHORIZATION’]

PHP code to parse HTTP authorization header looks the following way:

if (isset($_SERVER['HTTP_AUTHORIZATION'])) {
 $nobasic = substr($_SERVER['HTTP_AUTHORIZATION'],6); // removing 'Basic ' from the string
 $decoded = base64_decode($nobasic); // decoding string with user:password
 list($client_user, $client_pass) = explode(':',$decoded);
 if ($client_user == "username" && $client_pass == "password") {
   // Successfully authenticated
 } else {
   // Authentication failed, username or password are wrong
 }
} else {
 // Not authenticated as there is no appropriate header in HTTP request
}

You can check if your authentication is working sending appropriate header in HTTP request, check here to get the information how to form the header

, , , , , , , ,

Leave a comment