Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding documentation, and serverless-domain-manager plugin #1

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
.serverless
data/*.mmdb
node_modules
package-lock.json
package-lock.json
yarn-error.log
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

Use AWS Lambda and [MaxMind GeoLite](http://dev.maxmind.com/geoip/geoip2/geolite2/) to query for locations of IP addresses. You can invoke the function or use API Gateway to send an HTTP request with the IP address to lookup.

## Why
Since FreeGeoIP has deprecated their [free api](https://github.com/apilayer/freegeoip#readme), we decided to implement this in lambda.

```bash
curl \
-H "Content-Type: application/json" \
https://geoip.scw.video/ip/172.217.8.206
```

Feel free to utilize our api endpoint hosted by [security-camera-warehouse.com](https://www.security-camera-warehouse.com/)
## Install

```bash
Expand All @@ -22,6 +32,18 @@ Download the [GeoLite2 City](http://dev.maxmind.com/geoip/geoip2/geolite2/) data

## Deploy

### Dependencies
[serverless-domain-manager](https://securitycw.atlassian.net/wiki/spaces/DEV/pages/32571396/Serverless#Serverless-Serverless-domain-manager)
[serverless-aws-documentation](https://securitycw.atlassian.net/wiki/spaces/DEV/pages/32571396/Serverless#Serverless-Serverless-aws-documentation)

Run
```bash
serverless create-domain
```
Wait 40 minutes for domain to create if it's new

### yarn deploy

```bash
$ > yarn deploy

Expand All @@ -33,6 +55,7 @@ endpoints:

## Usage


### Invoke

```bash
Expand All @@ -57,4 +80,9 @@ $ > sls invoke -f lookup --data '{ "ip": "8.8.8.8" }'
$ > curl https://randomid.execute-api.us-east-1.amazonaws.com/dev/ip/8.8.8.8

{"continent":{"code":"NA","geoname_id":6255149,"names":{"de":"Nordamerika","en":"North America", …
```

### Remove Domain with
```bash
serverless delete_domain
```
10 changes: 10 additions & 0 deletions models/awsError.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: "awsError"
description: "an aws internal server error, usually with status code 502 (bad gateway)"
contentType: "application/json"
schema:
type: object
properties:
message:
type: string
required:
- message
13 changes: 13 additions & 0 deletions models/city.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: "city"
description: "a city object returned from api"
##contentType: "application/json"
schema:
type: object
properties:
confidence:
type: integer
format: int32
geoname_id:
type: integer
format: int32
names: ${file(models/names.yml):schema}
12 changes: 12 additions & 0 deletions models/continent.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: "continent"
description: "a continent object returned from api"
#contentType: "application/json"
schema:
type: object
properties:
code:
type: string
geoname_id:
type: integer
format: int32
names: ${file(models/names.yml):schema}
15 changes: 15 additions & 0 deletions models/country.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: "country"
description: "a country object returned from api"
#contentType: "application/json"
schema:
type: object
properties:
confidence:
type: integer
format: int32
geoname_id:
type: integer
format: int32
iso_code:
type: string
names: ${file(models/names.yml):schema}
29 changes: 29 additions & 0 deletions models/ip.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: "ip"
description: "a ip object returned from api at /ip/{ip}"
contentType: "application/json"
schema:
type: object
properties:
city: ${file(models/city.yml):schema}
continent: ${file(models/continent.yml):schema}
country: ${file(models/country.yml):schema}
location: ${file(models/location.yml):schema}
postal: ${file(models/postal.yml):schema}
registered_country: ${file(models/registered_country.yml):schema}
represented_country: ${file(models/represented_country.yml):schema}
subdivisions:
type: array
items: ${file(models/subdivisions.yml):schema}
traits: ${file(models/traits.yml):schema}
maxmind: ${file(models/maxmind.yml):schema}
required:
- city
- continent
- country
- location
- postal
- registered_country
- represented_country
- subdivisions
- traits
- maxmind
6 changes: 6 additions & 0 deletions models/ipResponse.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: ipResponse
description: "default ip response"
contentType: "application/json"
schema:
type: object
properties: ${file(models/ip.yml):schema.properties}
26 changes: 26 additions & 0 deletions models/location.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: "location"
description: "a location object returned from api"
#contentType: "application/json"
schema:
type: object
properties:
accuracy_radius:
type: integer
format: int32
average_income:
type: integer
format: int64
latitude:
type: integer
format: int64
longitude:
type: integer
format: int64
metro_code:
type: integer
format: int32
population_density:
type: integer
format: int32
time_zone:
type: string
9 changes: 9 additions & 0 deletions models/maxmind.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: "maxmind"
description: "a maxmind object returned from api"
#contentType: "application/json"
schema:
type: object
properties:
queries_remaining:
type: integer
format: int64
22 changes: 22 additions & 0 deletions models/names.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: "names"
description: "a names object with localized names"
#contentType: "application/json"
schema:
type: object
properties:
de:
type: string
en:
type: string
es:
type: string
fr:
type: string
ja:
type: string
pt-BR:
type: string
ru:
type: string
zh-CN:
type: string
11 changes: 11 additions & 0 deletions models/postal.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: "postal"
description: "a postal object returned from api"
#contentType: "application/json"
schema:
type: object
properties:
code:
type: string
confidence:
type: integer
format: int64
12 changes: 12 additions & 0 deletions models/registered_country.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: "registered_country"
description: "a registered_country object returned from api"
#contentType: "application/json"
schema:
type: object
properties:
geoname_id:
type: integer
format: int64
iso_code:
type: string
names: ${file(models/names.yml):schema}
11 changes: 11 additions & 0 deletions models/represented_country.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: "represented_country"
description: "a represented_country object returned from api"
#contentType: "application/json"
schema:
type: object
properties:
iso_code:
type: string
names: ${file(models/names.yml):schema}
type:
type: string
15 changes: 15 additions & 0 deletions models/subdivisions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: "subdivisions"
description: "a subdivisions object returned from api"
#contentType: "application/json"
schema:
type: object
properties:
confidence:
type: integer
format: int32
geoname_id:
type: integer
format: int64
iso_code:
type: string
names: ${file(models/names.yml):schema}
25 changes: 25 additions & 0 deletions models/traits.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: "traits"
description: "a traits object returned from api"
#contentType: "application/json"
schema:
type: object
properties:
autonomous_system_number:
type: integer
format: int64
autonomous_system_organization:
type: string
domain:
type: string
is_anonymous_proxy:
type: boolean
is_satellite_provider:
type: boolean
isp:
type: string
ip_address:
type: string
organization:
type: string
user_type:
type: string
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
"mmdb-reader": "^1.1.0"
},
"devDependencies": {
"serverless": "^1.24.0"
"serverless": "^1.24.0",
"serverless-aws-documentation": "^1.0.1",
"serverless-domain-manager": "^2.3.6"
}
}
Loading