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

Add pingback support (bug 1377305) #16

Merged
merged 1 commit into from
Jul 10, 2017

Conversation

zalun
Copy link
Contributor

@zalun zalun commented Jun 27, 2017

Added POST API endpoint /landings/{landing_id}/update.
landing_id (from path) and request_id (from data) have to correspond
with database entry, otherwise 404 is raised.
Modified the schema by adding error and result.

@zalun zalun requested a review from mars-f June 27, 2017 22:36
@zalun zalun assigned purelogiq and unassigned purelogiq Jun 27, 2017
@zalun zalun requested a review from purelogiq June 27, 2017 22:37
@zalun zalun force-pushed the add-callback branch 2 times, most recently from 924f1a5 to 568b1a8 Compare June 27, 2017 23:35
@@ -42,35 +51,45 @@ class Landing(db.Model):
request_id = db.Column(db.Integer, unique=True)
revision_id = db.Column(db.String(30))
status = db.Column(db.Integer)
auth = db.Column(db.String(30))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the auth mechanism should be stored in the database. The security design doc says we should consider a shared API key for validating the client doing the update, and that means we'll end up adding a second migration at a later to remove the auth column. I recommend we split this user story into two parts: one for this patch to perform status updates with no auth, and a second story to have a special API key for a pingback client to use to update statuses.

@zalun zalun force-pushed the add-callback branch 2 times, most recently from f108205 to 4f3ae83 Compare June 29, 2017 20:55
Copy link
Contributor

@purelogiq purelogiq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks like it is on the right track!

@@ -17,6 +17,7 @@ services:
- PHABRICATOR_UNPRIVILEGED_API_KEY=api-123456789
- TRANSPLANT_URL=https://stub.transplant.example.com
- DATABASE_URL=sqlite:////db/sqlite.db
- HOST_URL=https://landoapi.mozilla.org
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree that we will need this variable. Lets set to http://lando-api.test and in ckolos change it for dev, stage, and prod.

description: |
Retrieve status of the landing job
required: true
schema:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

)
landing.status = data['status']
landing.save()
return landing.serialize(), 202
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does transplant expect a 202, or 200?
https://httpstatuses.com/202 vs https://httpstatuses.com/200

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it just checks for errors

from landoapi.models.storage import db
from landoapi.phabricator_client import PhabricatorClient
from landoapi.transplant_client import TransplantClient

TRANSPLANT_JOB_STARTING = 'starting'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for me, what is the difference between 'starting' and 'started'?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is set before request is made. No idea if it is started on the Transplant side.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is set before request is made. No idea if it is started on the Transplant side.

'pending' might be a better word to communicate the status.

@zalun zalun changed the title WIP Add callback Add callback Jun 29, 2017
@zalun zalun dismissed purelogiq’s stale review June 29, 2017 23:41

just do another one

@zalun zalun requested review from mars-f and purelogiq June 29, 2017 23:42
@zalun zalun force-pushed the add-callback branch 5 times, most recently from 9a8f50d to 45fd5ce Compare June 30, 2017 18:24

landing.error = data.get('error_msg', '')
landing.result = data.get('result', '')
landing.status = TRANSPLANT_JOB_LANDED if data['landed'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line confuses me. If the 'landed' field is present, regardless of value, everything is OK, and if an update is ever made with this field missing, it's a failure in the other system? I think there should be a comment or two in here to explain what the possible combinations of incoming values are, and to explain what they represent in the other system and in our system.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm adding description of fields which are received from Transplant (from Google doc)

trans = TransplantClient()
callback = '%s/landings/%s/update' % (
os.getenv('HOST_URL'), landing.id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This setting's name could be improved. I can't tell from the name alone that it is used for pingbacks. Maybe something like PINGBACK_HOST_URL or just PINGBACK_URL?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's the lando-api host url - I thought we might use it for something else.

Copy link
Contributor

@mars-f mars-f Jul 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed on IRC, I'm fine with either keeping the variable as-is or with changing it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think HOST_URL works well, imo.

description: Revision does not exist
description:
Revision does not exist or its request_id doesn't correspond to
the saved one
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably best not to mention internal implementation details here. I don't see a request_id mentioned in the POST parameters, either?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right - it should stay as it was before
request_id is mentioned as "in body" parameter

post:
operationId: landoapi.api.landings.update
description: |
Sends request to transplant service and responds just the status code
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo, "responds with just the status code"

Added POST API endpoint `/landings/{landing_id}/update`.
`landing_id` (from path) and `request_id` (from data) have to correspond
with database entry, otherwise 404 is raised.
Modified the schema by adding error and result.
Copy link
Contributor

@purelogiq purelogiq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this and was able to update a landing request via the swagger api tester. LGTM!

@zalun zalun requested a review from mars-f July 7, 2017 12:21
@zalun zalun changed the title Add callback Add pingback support (bug 1377305) Jul 7, 2017
@zalun zalun merged commit 50007e4 into mozilla-conduit:master Jul 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants