mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 02:11:11 -05:00
Add a new table to store the api information for a service inbound sms message.
Including: - url to push the inbound sms to - bearer_token to be added to the header of the request. The services will be expected to manage these properties.
This commit is contained in:
10
app/dao/service_inbound_api_dao.py
Normal file
10
app/dao/service_inbound_api_dao.py
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
from app import db
|
||||||
|
from app.authentication.utils import generate_secret
|
||||||
|
from app.dao.dao_utils import transactional
|
||||||
|
|
||||||
|
|
||||||
|
@transactional
|
||||||
|
def save_service_inbound_api(service_inbound_api):
|
||||||
|
|
||||||
|
service_inbound_api.bearer_token = generate_secret(service_inbound_api.bearer_token)
|
||||||
|
db.session.add(service_inbound_api)
|
||||||
@@ -295,6 +295,19 @@ class ServiceWhitelist(db.Model):
|
|||||||
return 'Recipient {} of type: {}'.format(self.recipient, self.recipient_type)
|
return 'Recipient {} of type: {}'.format(self.recipient, self.recipient_type)
|
||||||
|
|
||||||
|
|
||||||
|
class ServiceInboundApi(db.Model):
|
||||||
|
__tablename__ = 'service_inbound_api'
|
||||||
|
id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||||
|
service_id = db.Column(UUID(as_uuid=True), db.ForeignKey('services.id'), index=True, nullable=False)
|
||||||
|
service = db.relationship('Service')
|
||||||
|
url = db.Column(db.String(255), nullable=False)
|
||||||
|
bearer_token = db.Column(db.String(255), nullable=False)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def unsigned_bearer_token(self):
|
||||||
|
return get_secret(self.bearer_token)
|
||||||
|
|
||||||
|
|
||||||
class ApiKey(db.Model, Versioned):
|
class ApiKey(db.Model, Versioned):
|
||||||
__tablename__ = 'api_keys'
|
__tablename__ = 'api_keys'
|
||||||
|
|
||||||
|
|||||||
31
migrations/versions/0098_service_inbound_api.py
Normal file
31
migrations/versions/0098_service_inbound_api.py
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
"""empty message
|
||||||
|
|
||||||
|
Revision ID: 0098_service_inbound_api
|
||||||
|
Revises: 0097_notnull_inbound_provider
|
||||||
|
Create Date: 2017-06-13 15:02:33.609656
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
from sqlalchemy.dialects import postgresql
|
||||||
|
|
||||||
|
revision = '0098_service_inbound_api'
|
||||||
|
down_revision = '0097_notnull_inbound_provider'
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
op.create_table(
|
||||||
|
'service_inbound_api',
|
||||||
|
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
|
||||||
|
sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=False),
|
||||||
|
sa.Column('url', sa.String, nullable=False),
|
||||||
|
sa.Column('bearer_token', sa.String, nullable=False),
|
||||||
|
|
||||||
|
sa.ForeignKeyConstraint(['service_id'], ['services.id'], ),
|
||||||
|
sa.PrimaryKeyConstraint('id')
|
||||||
|
)
|
||||||
|
op.create_index(op.f('ix_service_inbound_api_id'), 'service_inbound_api', ['service_id'], unique=False)
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
op.drop_table("service_inbound_api")
|
||||||
20
tests/app/dao/test_save_service_inbound_api.py
Normal file
20
tests/app/dao/test_save_service_inbound_api.py
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
from app.dao.service_inbound_api_dao import save_service_inbound_api
|
||||||
|
from app.models import ServiceInboundApi
|
||||||
|
|
||||||
|
|
||||||
|
def test_save_service_inbound_api(sample_service):
|
||||||
|
service_inbound_api = ServiceInboundApi(
|
||||||
|
service_id=sample_service.id,
|
||||||
|
url="https::/some_service/inbound_messages",
|
||||||
|
bearer_token="some_unique_string"
|
||||||
|
)
|
||||||
|
|
||||||
|
save_service_inbound_api(service_inbound_api)
|
||||||
|
|
||||||
|
results = ServiceInboundApi.query.all()
|
||||||
|
assert len(results) == 1
|
||||||
|
assert results[0].id
|
||||||
|
assert results[0].service_id == sample_service.id
|
||||||
|
assert results[0].url == "https::/some_service/inbound_messages"
|
||||||
|
assert results[0].unsigned_bearer_token == "some_unique_string"
|
||||||
|
assert results[0].bearer_token != "some_unique_string"
|
||||||
Reference in New Issue
Block a user