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

Feature/twitter oauth #23

Merged
merged 15 commits into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.circleci
notes
docker-compose*
*.md
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Custom
venv/
.env
.env*
!.env.example

certs/

Expand Down
11 changes: 4 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.7.4-slim-buster
FROM python:3.7-slim-bullseye
joerick marked this conversation as resolved.
Show resolved Hide resolved

WORKDIR /sirius

Expand Down Expand Up @@ -29,12 +29,9 @@ RUN tar jxf phantomjs-2.1.1-linux-x86_64.tar.bz2 && \
rm phantomjs-2.1.1-linux-x86_64.tar.bz2 && \
mv phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/local/bin/phantomjs

RUN pip install --upgrade pip

ADD ./requirements.txt /sirius/requirements.txt
RUN pip install --no-cache-dir -r requirements.txt

RUN pip install honcho
RUN pip install --upgrade pip setuptools wheel
ADD ./pyproject.toml /sirius/pyproject.toml
RUN pip install --no-cache-dir .

EXPOSE 5000

Expand Down
23 changes: 6 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,25 @@ docker-compose -f docker-compose.yml -f docker-compose.development.yml up

Or if you have your own database, you can configure the `DEV_DATABASE_URL` environment variable in `.env`, and then simply run:

```
```sh
docker-compose up
```

### Environment variables

The server can be configured with the following variables:

```
TWITTER_CONSUMER_KEY=...
TWITTER_CONSUMER_SECRET=...
```properties
TWITTER_OAUTH_CLIENT_KEY=...
TWITTER_OAUTH_CLIENT_SECRET=...
OAUTH_REDIRECT_URI=...
FLASK_CONFIG=...
DATABASE_URL=...
```

These can be set in the `.env` file, and an example is available in `.env.sample` in your checkout.

### Creating fake printers and friends
### Creating fake printers

Resetting the actual hardware all the time gets a bit tiresome so
there's a fake command that creates unclaimed fake little printers:
Expand All @@ -83,18 +84,6 @@ Created printer

Functionally there is no difference between resetting and creating a new printer so we don't distinguish between the two.

To create a fake friend from twitter who signed up do this:

```console
$ ./manage.py fake user stephenfry
```

You can also claim a printer in somebody else's name:

```console
$ ./manage.py fake claim b7235a2b432585eb quentinsf 342f-eyh0-korc-msej testprinter
```

## Sirius Architecture

### Layers
Expand Down
46 changes: 46 additions & 0 deletions migrations/versions/89a031bd9657_remove_friends.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"""Remove friends

Revision ID: 89a031bd9657
Revises: 44c4368c2db1
Create Date: 2023-07-04 18:44:13.041005

"""

# revision identifiers, used by Alembic.
revision = "89a031bd9657"
down_revision = "44c4368c2db1"

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_unique_constraint(None, "claim_code", ["claim_code"])
op.create_foreign_key(None, "print_key", "print_key", ["parent_id"], ["id"])
op.create_unique_constraint(None, "printer", ["used_claim_code"])
phillipjf marked this conversation as resolved.
Show resolved Hide resolved
op.drop_column("twitter_o_auth", "last_friend_refresh")
op.drop_column("twitter_o_auth", "friends")
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column(
"twitter_o_auth",
sa.Column("friends", postgresql.BYTEA(), autoincrement=False, nullable=True),
)
op.add_column(
"twitter_o_auth",
sa.Column(
"last_friend_refresh",
postgresql.TIMESTAMP(),
autoincrement=False,
nullable=True,
),
)
op.drop_constraint(None, "printer", type_="unique")
op.drop_constraint(None, "print_key", type_="foreignkey")
op.drop_constraint(None, "claim_code", type_="unique")
phillipjf marked this conversation as resolved.
Show resolved Hide resolved
# ### end Alembic commands ###
54 changes: 54 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
[build-system]
requires = ["setuptools", "wheel"]

[project]
name = "sirius"
readme = "README.md"
requires-python = ">=3.7,<3.8"
version = "0.0.0"
dependencies = [
"Flask==1.1.1",
"Flask-Bootstrap==3.3.7.1",
"Flask-Cors==3.0.8",
"Flask-Login==0.4.1",
"Flask-Migrate==2.5.2",
"Flask-SQLAlchemy==2.4.0",
"Flask-Script==2.0.6",
"Flask-Sockets==0.2.1",
"Flask-WTF==0.14.2",
"Jinja2==2.10.1",
"Mako==1.1.0",
"MarkupSafe==1.1.1",
"Pillow==6.1.0",
"SQLAlchemy==1.3.8",
"WTForms==2.2.1",
"Werkzeug==0.15.6",
"alembic==1.1.0",
"argparse==1.2.1",
"backports.ssl-match-hostname==3.7.0.1",
"blinker==1.4",
"gevent==1.4.0",
"gevent-websocket==0.10.1",
"greenlet==0.4.15",
"gunicorn==19.9.0",
"httplib2==0.13.1",
"itsdangerous==1.1.0",
"nose==1.3.7",
"oauthlib==3.2.2",
"psycopg2-binary==2.8.3",
"pycrypto==2.6.1",
"redis==3.3.8",
"requests==2.22.0",
"requests-oauthlib==1.3.1",
"selenium==3.141.0",
"six==1.12.0",
"twitter==1.18.0",
"websocket-client==0.56.0",
"honcho",
]

[project.optional-dependencies]
test = [
"snapshottest @ git+git://github.com/syrusakbary/snapshottest.git@4ac2b4fb09e9e7728bebb11967c164a914775d1d#snapshottest",
"Flask-Testing==0.7.1",
]
41 changes: 0 additions & 41 deletions requirements.txt

This file was deleted.

40 changes: 26 additions & 14 deletions sirius/config.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,52 @@
import os

basedir = os.path.abspath(os.path.dirname(__file__))


class Config:
SECRET_KEY = os.environ.get('SECRET_KEY') or 'this is the lp2 secret'
SECRET_KEY = os.environ.get("SECRET_KEY") or "this is the lp2 secret"
SQLALCHEMY_COMMIT_ON_TEARDOWN = True
SQLALCHEMY_TRACK_MODIFICATIONS = False
# printer not seen for 60 seconds: Mark offline.
PRINTER_OFFLINE_CUTOFF_SECONDS = 60
TWITTER_OAUTH_CLIENT_KEY = os.getenv("TWITTER_OAUTH_CLIENT_KEY")
TWITTER_OAUTH_CLIENT_SECRET = os.getenv("TWITTER_OAUTH_CLIENT_SECRET")
OAUTH_REDIRECT_URI = os.getenv("OAUTH_REDIRECT_URI")

@staticmethod
def init_app(app):
pass


class TestConfig(Config):
DEBUG = False
SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL') or \
'sqlite:///' + os.path.join(basedir, 'data-dev.sqlite')
SQLALCHEMY_DATABASE_URI = os.environ.get(
"DATABASE_URL"
) or "sqlite:///" + os.path.join(basedir, "data-dev.sqlite")
TESTING = True
WTF_CSRF_ENABLED = False
LOGIN_DISABLED = False


class DevelopmentConfig(Config):
DEBUG = True
SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL') or \
'sqlite:///' + os.path.join(basedir, 'data-dev.sqlite')
SQLALCHEMY_DATABASE_URI = os.environ.get(
"DATABASE_URL"
) or "sqlite:///" + os.path.join(basedir, "data-dev.sqlite")


class ProductionConfig(Config):
SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL') or \
'sqlite:///' + os.path.join(basedir, 'data.sqlite')
SQLALCHEMY_DATABASE_URI = os.environ.get(
"DATABASE_URL"
) or "sqlite:///" + os.path.join(basedir, "data.sqlite")

@classmethod
def init_app(cls, app):
Config.init_app(app)


class HerokuConfig(ProductionConfig):
SSL_DISABLE = bool(os.environ.get('SSL_DISABLE'))
SSL_DISABLE = bool(os.environ.get("SSL_DISABLE"))
DEBUG = True

@classmethod
Expand All @@ -44,21 +55,22 @@ def init_app(cls, app):

# handle proxy server headers
from werkzeug.contrib.fixers import ProxyFix

app.wsgi_app = ProxyFix(app.wsgi_app)

# log to stderr
import logging
from logging import StreamHandler

file_handler = StreamHandler()
file_handler.setLevel(logging.WARNING)
app.logger.addHandler(file_handler)


config = {
'development': DevelopmentConfig,
'production': ProductionConfig,
'heroku': HerokuConfig,
'test': TestConfig,

'default': DevelopmentConfig
"development": DevelopmentConfig,
"production": ProductionConfig,
"heroku": HerokuConfig,
"test": TestConfig,
"default": DevelopmentConfig,
}
Loading