1
0
mirror of https://github.com/peeringdb/peeringdb.git synced 2024-05-11 05:55:09 +00:00

initial commit of code

This commit is contained in:
Stefan Pratter
2018-11-08 19:45:21 +00:00
parent 5d7c69de38
commit 0edf47bbfb
370 changed files with 47054 additions and 16 deletions

142
docs/deploy.md Normal file
View File

@@ -0,0 +1,142 @@
# PeeringDB Deploy
## Getting Started
This document uses the following variables
```sh
export FACS_REPO=git@github.com:20c/facsimile.git
export PDB_REPO=git@git.20c.com:pdb/peeringdb.git
```
### Install obfuscation tools (Only needed if you want to obfuscate js)
```sh
git clone src.20c.com:20c/sys-deploy
mkdir -p ~/.local/google
wget https://dl.google.com/closure-compiler/compiler-latest.zip
unzip compiler-latest.zip
mv compiler.jar ~/.local/google
```
### Install facsimile
```sh
git clone $FACS_REPO
cd facsimile
python setup.py install
```
### Clone peeringdb
```sh
git clone $PDB_REPO
```
# Developer instance deploymnet
Create ~/srv
```sh
mkdir ~/srv
```
```
facs $component $environment ($version|--src-dir=. for dev)
```
Use the `facs` command to deploy a virtualenv and server files for your dev instance
```sh
facs peeringdb dev --src-dir=.
facs venv dev --src-dir=.
```
Files will be deployed to `~/srv/dev.peeringdb.com`
## Setup passwords
Once you have run `facs` for the first time it will have created a .facsimile directory
You will want to open `.facimsile/state/{env}/state.yaml` and set the correct passwords for everything and then do
**another** deploy to make sure the correct passwords are deployed.
```
instances:
inmap: {}
uiidmap: {}
passwd:
deskpro: xxx # deskpro api key
djangokey: xxx # django secret
google_geoloc_api: xxx # google geolocation api key
peeringdb: xxx # database password
recaptcha: xxx # recaptcha secret
```
## Create api-cache dir
```
mkdir ~/srv/dev.peeringdb.com/etc/api-cache
```
## Symlink for convenience
In order to be able to run the manage.py command out of the pdb repository you can symlink the peeringdb_com directory from deploy location
In the peeringdb repo root:
```sh
ln -s ~/srv/dev.peeringdb.com/peeringdb/peeringdb_com peeringdb_com
```
## Setup database
During deploy facsimile will have created a sql file at `.facsimile/tmp/RELEASE/dev/peeringdb/init.sql` - load it into mysql.
```sh
mysql -u root -p < .facsimile/tmp/RELEASE/dev/peeringdb/init.sql
```
## Migrate database - empty, from scratch
```sh
./manage.py migrate
./manage.py createcachetable
./manage.py loaddata fixtures/initial_data.json
```
## Running the dev instance
```sh
./manage.py runserver
```
## Hangups
### Authentication not working
This is usually caused by misconfigured session settings
In `peeringdb_com/settings.d/01-local.conf`
- Check that `SESSION_COOKIE_DOMAIN` is set to the apropriate domain
- Check that `SESSION_COOKIE_SECURE` is `False` if youre not serving over https
# Versioning
Everything is versioned for deploy, using facsimile.
```sh
# to update dev versions
version_bump_dev
# to update release versions
version_merge_release
```
# Tests
```sh
pytest -v -rxs --cov-report term-missing --cov=peeringdb_server/ --capture=sys tests/
```

126
docs/development.md Normal file
View File

@@ -0,0 +1,126 @@
# PeeringDB Server Development
## Models
Note: to add fk's to base models, you must add in both peeringdb.models. and in django_peeringdb.models concrete class
models.py
- make model
- add ref_tag_
serializers.py
- add serializer
peeringdb/rest.py
- make ViewSet
- register
perms
ALWAYS
- on the model create a classmethod called nsp_namespace_from_id
that should take all the ids it needs to make its namespace
and return that namespace
Look at the Network or NetworkContact class for examples
- on the model create a property method called nsp_namespace
that calls and returns __class__.nsp_namespace_from_id with
the aproporiate ids
- on the serializer create a method called nsp_namespace_create
that returns the namespace to be checked for creation perms
this method will be passed the validated serializer data so
you can use the ids / objects in there to help build your namespace
SOMETIMES
- on the model create a method called nsp_has_perms_PUT that
chould return weither or not the user has access to update
the instance. This is needed because in some cases in order
to update an existing object the user may need to be checked
on perms for more than one namespace - this lets you do that
Look at validate_PUT_ownership for helper function
- if the model is supposed to be rendered in a list somewhere
eg network contacts in poc_set under network make sure list
namespacing is setup correctly - again look at Network
and NetworkContact for examples.
## Modules
### RDAP
- Add output to parsing test
```sh
curl -L https://rdap.db.ripe.net/autnum/$ASN > tests/data/rdap/autnum/$ASN.input
```
or
```sh
scripts/rdap_getasn.sh
scripts/rdap_getent.sh
```
- Pretty print RDAP data
```sh
munge json:https://rdap.arin.net/registry/autnum/2914 yaml:
```
### Whois Server
- To locally test whois, setup `/etc/xinetd.d/pdb-whois` with similar:
```
service whois
{
disable = no
socket_type = stream
wait = no
user = $USER
passenv =
server = /home/$USER/srv/dev.peeringdb.com/peeringdb/in.whoisd
log_on_failure = HOST
}
```
- Deploy and test against local
```sh
facs peeringdb dev --src-dir=. ; whois -h 127.0.0.1 as63311
pytest -v -rxs --cov-report term-missing --cov=peeringdb_server/ --capture=sys tests/
```
## Troubleshooting
### 404 on static files with runserver:
Make sure it's in debug mode
### api tests fail
You need to specify the test directory:
```sh
pytest tests/
```
### Can't see error because of warnings
Run pytest with `-p no:warnings`
### Run one specific test
Run pytest with `-k $test_name`

35
docs/translation.md Normal file
View File

@@ -0,0 +1,35 @@
# Integerating translations (Developers)
## Generate a new locale
Call makemessages and pass the locale to the `-l` option
Clone https://github.com/peeringdb/django-peeringdb somewhere
Symlink django_peeringdb in the same location as manage.py - this is so makemessages collects the locale from there as well.
```
django-admin makemessages -l de -s --no-wrap
django-admin makemessages -d djangojs -l de -s --no-wrap
```
## Updating messages in existing locale
This will add any new messages to all locale files. In other words if there has been new features added, you want to call this to make sure that their messages exist in gettext so they can be translated.
Clone https://github.com/peeringdb/django-peeringdb somewhere
Symlink django_peeringdb in the same location as manage.py - this is so makemessages collects the locale from there as well.
```
django-admin makemessages -a -s --no-wrap
django-admin makemessages -d djangojs -a -s --no-wrap
```
## Compile messages
Once translation files are ready, you need to compile them so django can use them.
```
django-admin compilemessages
```