Skip to content

Commit f7fe626

Browse files
authored
Merge pull request #2 from pratik-vii/metering
signature authorisation added for demon request
2 parents 75c79b5 + 3a29e7c commit f7fe626

30 files changed

+1074
-1
lines changed

metering/.gitignore

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Distribution / packaging
2+
.Python
3+
env/
4+
build/
5+
develop-eggs/
6+
dist/
7+
downloads/
8+
eggs/
9+
.eggs/
10+
lib/
11+
lib64/
12+
parts/
13+
sdist/
14+
var/
15+
*.egg-info/
16+
.installed.cfg
17+
*.egg
18+
settings.py
19+
20+
# Serverless directories
21+
.serverless

metering/__init__.py

Whitespace-only changes.

metering/adaptors.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
def usage_entity_to_model():
2+
pass
3+
4+
5+
def usage_model_to_entity():
6+
pass

metering/alembic.ini

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# A generic, single database configuration.
2+
3+
[alembic]
4+
# path to migration scripts
5+
script_location = alembic
6+
7+
# template used to generate migration files
8+
# file_template = %%(rev)s_%%(slug)s
9+
10+
# timezone to use when rendering the date
11+
# within the migration file as well as the filename.
12+
# string value is passed to dateutil.tz.gettz()
13+
# leave blank for localtime
14+
# timezone =
15+
16+
# max length of characters to apply to the
17+
# "slug" field
18+
# truncate_slug_length = 40
19+
20+
# set to 'true' to run the environment during
21+
# the 'revision' command, regardless of autogenerate
22+
# revision_environment = false
23+
24+
# set to 'true' to allow .pyc and .pyo files without
25+
# a source .py file to be detected as revisions in the
26+
# versions/ directory
27+
# sourceless = false
28+
29+
# version location specification; this defaults
30+
# to alembic/versions. When using multiple version
31+
# directories, initial revisions must be specified with --version-path
32+
# version_locations = %(here)s/bar %(here)s/bat alembic/versions
33+
34+
# the output encoding used when revision files
35+
# are written from script.py.mako
36+
# output_encoding = utf-8
37+
38+
sqlalchemy.url = mysql+pymysql://url
39+
40+
41+
# Logging configuration
42+
[loggers]
43+
keys = root,sqlalchemy,alembic
44+
45+
[handlers]
46+
keys = console
47+
48+
[formatters]
49+
keys = generic
50+
51+
[logger_root]
52+
level = WARN
53+
handlers = console
54+
qualname =
55+
56+
[logger_sqlalchemy]
57+
level = WARN
58+
handlers =
59+
qualname = sqlalchemy.engine
60+
61+
[logger_alembic]
62+
level = INFO
63+
handlers =
64+
qualname = alembic
65+
66+
[handler_console]
67+
class = StreamHandler
68+
args = (sys.stderr,)
69+
level = NOTSET
70+
formatter = generic
71+
72+
[formatter_generic]
73+
format = %(levelname)-5.5s [%(name)s] %(message)s
74+
datefmt = %H:%M:%S

metering/alembic/README

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Generic single-database configuration.

metering/alembic/env.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
2+
from logging.config import fileConfig
3+
4+
from sqlalchemy import engine_from_config
5+
from sqlalchemy import pool
6+
7+
from alembic import context
8+
9+
# this is the Alembic Config object, which provides
10+
# access to the values within the .ini file in use.
11+
from models import Base
12+
13+
config = context.config
14+
15+
# Interpret the config file for Python logging.
16+
# This line sets up loggers basically.
17+
fileConfig(config.config_file_name)
18+
19+
# add your model's MetaData object here
20+
# for 'autogenerate' support
21+
# from myapp import mymodel
22+
# target_metadata = mymodel.Base.metadata
23+
target_metadata = Base.metadata
24+
25+
# other values from the config, defined by the needs of env.py,
26+
# can be acquired:
27+
# my_important_option = config.get_main_option("my_important_option")
28+
# ... etc.
29+
30+
31+
def run_migrations_offline():
32+
"""Run migrations in 'offline' mode.
33+
34+
This configures the context with just a URL
35+
and not an Engine, though an Engine is acceptable
36+
here as well. By skipping the Engine creation
37+
we don't even need a DBAPI to be available.
38+
39+
Calls to context.execute() here emit the given string to the
40+
script output.
41+
42+
"""
43+
url = config.get_main_option("sqlalchemy.url")
44+
context.configure(
45+
url=url, target_metadata=target_metadata, literal_binds=True
46+
)
47+
48+
with context.begin_transaction():
49+
context.run_migrations()
50+
51+
52+
def run_migrations_online():
53+
"""Run migrations in 'online' mode.
54+
55+
In this scenario we need to create an Engine
56+
and associate a connection with the context.
57+
58+
"""
59+
connectable = engine_from_config(
60+
config.get_section(config.config_ini_section),
61+
prefix="sqlalchemy.",
62+
poolclass=pool.NullPool,
63+
)
64+
65+
with connectable.connect() as connection:
66+
context.configure(
67+
connection=connection, target_metadata=target_metadata
68+
)
69+
70+
with context.begin_transaction():
71+
context.run_migrations()
72+
73+
74+
if context.is_offline_mode():
75+
run_migrations_offline()
76+
else:
77+
run_migrations_online()

metering/alembic/script.py.mako

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""${message}
2+
3+
Revision ID: ${up_revision}
4+
Revises: ${down_revision | comma,n}
5+
Create Date: ${create_date}
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
${imports if imports else ""}
11+
12+
# revision identifiers, used by Alembic.
13+
revision = ${repr(up_revision)}
14+
down_revision = ${repr(down_revision)}
15+
branch_labels = ${repr(branch_labels)}
16+
depends_on = ${repr(depends_on)}
17+
18+
19+
def upgrade():
20+
${upgrades if upgrades else "pass"}
21+
22+
23+
def downgrade():
24+
${downgrades if downgrades else "pass"}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""status added in calls tables
2+
3+
Revision ID: 9ecbd29ee907
4+
Revises: eeec29a1af7b
5+
Create Date: 2019-08-12 15:13:51.507698
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
11+
12+
# revision identifiers, used by Alembic.
13+
revision = '9ecbd29ee907'
14+
down_revision = 'eeec29a1af7b'
15+
branch_labels = None
16+
depends_on = None
17+
18+
19+
def upgrade():
20+
# ### commands auto generated by Alembic - please adjust! ###
21+
op.add_column('usage_table', sa.Column('status', sa.VARCHAR(length=225), nullable=False))
22+
# ### end Alembic commands ###
23+
24+
25+
def downgrade():
26+
# ### commands auto generated by Alembic - please adjust! ###
27+
op.drop_column('usage_table', 'status')
28+
# ### end Alembic commands ###
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
"""added tables
2+
3+
Revision ID: eeec29a1af7b
4+
Revises:
5+
Create Date: 2019-08-08 19:15:24.337631
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
11+
12+
# revision identifiers, used by Alembic.
13+
revision = 'eeec29a1af7b'
14+
down_revision = None
15+
branch_labels = None
16+
depends_on = None
17+
18+
19+
def upgrade():
20+
# ### commands auto generated by Alembic - please adjust! ###
21+
op.create_table('service_config',
22+
sa.Column('id', sa.Integer(), nullable=False),
23+
sa.Column('org_id', sa.VARCHAR(
24+
length=225), nullable=False),
25+
sa.Column('service_id', sa.VARCHAR(
26+
length=225), nullable=False),
27+
sa.Column('free_calls', sa.Integer(), nullable=False),
28+
sa.Column('effective_start_date', sa.TIMESTAMP(
29+
timezone=True), nullable=True),
30+
sa.Column('effective_end_date', sa.TIMESTAMP(timezone=True),
31+
server_default=sa.text('CURRENT_TIMESTAMP'), nullable=True),
32+
sa.Column('created_at', sa.TIMESTAMP(
33+
timezone=True), nullable=True),
34+
sa.PrimaryKeyConstraint('id')
35+
)
36+
op.create_table('user_org_group',
37+
sa.Column('id', sa.Integer(), nullable=False),
38+
sa.Column('group', sa.VARCHAR(length=225), nullable=True),
39+
sa.Column('org_id', sa.VARCHAR(
40+
length=225), nullable=False),
41+
sa.Column('user_name', sa.VARCHAR(
42+
length=225), nullable=False),
43+
sa.Column('created_at', sa.TIMESTAMP(timezone=True),
44+
server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
45+
sa.Column('service_id', sa.VARCHAR(
46+
length=225), nullable=False),
47+
sa.Column('resource', sa.VARCHAR(
48+
length=225), nullable=True),
49+
sa.PrimaryKeyConstraint('id')
50+
)
51+
op.create_table('usage_table',
52+
sa.Column('id', sa.Integer(), nullable=False),
53+
sa.Column('user_org_group_id',
54+
sa.Integer(), nullable=False),
55+
sa.Column('usage_type', sa.VARCHAR(
56+
length=225), nullable=False),
57+
sa.Column('usage_value', sa.Integer(), nullable=False),
58+
sa.Column('start_time', sa.TIMESTAMP(
59+
timezone=True), nullable=True),
60+
sa.Column('end_time', sa.TIMESTAMP(
61+
timezone=True), nullable=True),
62+
sa.Column('created_at', sa.TIMESTAMP(timezone=True),
63+
server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
64+
sa.ForeignKeyConstraint(['user_org_group_id'], [
65+
'user_org_group.id'], ),
66+
sa.PrimaryKeyConstraint('id')
67+
)
68+
# ### end Alembic commands ###
69+
70+
71+
def downgrade():
72+
# ### commands auto generated by Alembic - please adjust! ###
73+
op.drop_table('usage_table')
74+
op.drop_table('user_org_group')
75+
op.drop_table('service_config')
76+
# ### end Alembic commands ###

metering/constants.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class StatusCode:
2+
BAD_PARAMETERS_CODE = 400
3+
SERVER_ERROR_CODE = 500
4+
SUCCESS_POST_CODE = 201
5+
SUCCESS_GET_CODE = 200
6+
7+
8+
HEADER_POST_RESPONSE = {
9+
"Content-Type": "application/json",
10+
"Access-Control-Allow-Origin": "*",
11+
"Access-Control-Allow-Methods": "OPTIONS,POST,GET"
12+
}
13+
14+
15+
class StatusMessage:
16+
BAD_PARAMETER = "Request validation failed"
17+
SERVER_ERROR_MSG = "failed"
18+
SUCCESS_POST_CODE = "successful"

0 commit comments

Comments
 (0)