Skip to content

austincunningham/mobile-security-service

Β 
Β 

Repository files navigation

Mobile Security Service

Overview

This is the server component of the AeroGear Mobile Security Service. It is a RESTful API that allows developers to view, enable and disable specific versions of applications on demand, with the information stored in a PostgreSQL database.

Getting Started

If you’d like to simply run the entire application in docker-compose, follow these instructions.

Golang projects are kept in a workspace that follows a very specific architecture. Before cloning this repo, be sure you have a $GOPATH environment variable set up.

.1. Clone the Repository

git clone [email protected]:aerogear/mobile-security-service.git $GOPATH/src/github.com/aerogear/mobile-security-service

.2. Install Dependencies

make setup
πŸ“Ž
This is using the dep package manager under the hood. You will see the dependencies installed in the vendor folder.

.3. Start the Server

go run cmd/mobile-security-service/main.go

.4. Run Entire Application with Docker Compose

This section shows how to start the entire application with docker-compose. This is useful for doing some quick tests (using the SDKs) for example.

First, compile a Linux compatible binary:

go build -o mobile-security-service cmd/mobile-security-service/main.go

This binary will be used to build the Docker image. Now start the entire application.

docker-compose up

Setup and configurations

Environment Variables

The mobile-security-service is configured using environment variables.

  • By default, the application will look for system environment variables to use.

  • If a system environment variable cannot be found, the application will then check the .env file in the application root.

  • If the .env file does not exist, or if the variable is not defined in the file, the application will use the default value defined in config.go.

Add your own .env file

Make a copy of the example file .env.example.

cp .env.example .env

Now the application will use the values defined in .env.

Server Configuration

Server Configuration

Variable

Default

Description

PORT

3000

The port the server will listen on

LOG_LEVEL

info

Can be one of [debug, info, warning, error, fatal, panic]

LOG_FORMAT

text

Can be one of [text, json]

ACCESS_CONTROL_ALLOW_ORIGIN

*

Can be multiple URL values separated with commas. Example: ACCESS_CONTROL_ALLOW_ORIGIN=http://www.example.com,http://example.com

ACCESS_CONTROL_ALLOW_CREDENTIALS

false

Can be one of [true, false]

DBMAX_CONNECTIONS

100

The maximum number of concurrent database connections the server will open

Database

The database connection is configured using the table of environment variables below. These environment variables correspond to the PostgreSQL libpq environment variables. The table below shows all of the environment variables supported by the pq driver used in this server.

Database Configuration

Variable

Default

Description

PGDATABASE

mobile_security_service

The database to connect to

PGUSER

postgresql

The database user

PGPASSWORD

postgres

The database password

PGHOST

localhost

The database hostname to connect to

PGPORT

5432

The database port to connect to

PGSSLMODE

disable

The SSL mode

PGCONNECT_TIMEOUT

5

The default connection timeout (seconds)

PGAPPNAME

The application_name connection parameter

PGSSLCERT

The sslcert connection parameter.

PGSSLKEY

The sslkey connection parameter.

PGSSLROOTCERT

The sslrootcert connection parameter

Database Entity Relationship Diagram

Diagram

Using Swagger UI

Method 1

A Swagger UI can be used for testing the mobile-security-service service.

docker run -p 8080:8080 -e API_URL=https://raw.githubusercontent.com/aerogear/mobile-security-service/master/api/swagger.yaml swaggerapi/swagger-ui

Or you can run the container with docker-compose up -d swagger.

The Swagger UI is available at localhost:8080.

Method 2

There is also a Chrome extension you can use instead of running a Docker container.

Building & Testing

The Makefile provides commands for building and testing the code. Some dependencies are required to run these commands.

Dependencies

Dependencies may be required to run some of the Make commands. Below are instructions on how to install them.

Creating mock for Interfaces

This project is using teh dependency moq. Follow the steps below to use it.

Install the required dependencies

Run the following command.

$ go get -u github.com/matryer/moq

Creating mocks

Execute the following command to generate the mock file.

$ moq -out <name_of_mock_file> . <name of interface>

Following an example.

moq -out app_service_mock.go . Service
❗
This command need to be executed from the same directory where the interface is or it need to be called as, for example, $ moq -out ./pkg/web/apps/app_service_mock.go ./pkg/web/apps Service
πŸ“Ž
See more over it in the Readme of moq

Developing Helpers

Errcheck

The errcheck is required to run the make errcheck command.

Install:

go get -u github.com/kisielk/errcheck

Commands

Commands

Command

Description

make setup

Downloads dependencies into vendor

make setup_githooks

Symlink all Git hooks from .githooks into .git/hooks

make build

Compile a binary compatible with your current system into ./mobile-security-service

make build_linux

Compile a Linux binary into ./dist/linux_amd64/mobile-security-service

make build_swagger_api

Generate swagger API documentation from the source code

make docker_build

Compile a binary and create a Docker image from it.

make docker_build_release

Compile a binary and create a Docker image with a release tag

make docker_build_master

Compile a binary and create a Docker image tagged master

make test

Runs unit tests

make test-all

Runs all tests

make test-integration

Runs integration tests

make test-integration-cover

Runs integration tests and outputs results to a log file

make errcheck

Checks for unchecked errors using errcheck

make vet

Examines source code and reports suspicious constructs using vet

make fmt

Formats code using gofmt

make clean

Removes binary compiled using make build

make docker_push_release

Pushes release image to Docker image hosting repository

make docker_push_master

Pushes master image to Docker image hosting repository

Built With

  • Golang - Programming language used

  • Echo - Web framework used

Contributing

All contributions are hugely appreciated. Please see our Contributing Guide for guidelines on how to open issues and pull requests. Please check out our Code of Conduct too.

Questions

There are a number of ways you can get in in touch with us, please see the AeroGear community.

About

No description, website, or topics provided.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 84.3%
  • Shell 6.1%
  • Makefile 4.1%
  • JavaScript 2.5%
  • HTML 2.0%
  • CSS 0.5%
  • Dockerfile 0.5%