fission icon indicating copy to clipboard operation
fission copied to clipboard

Check for auth on app first, and add error for 401 unauthorized

Open bmann opened this issue 5 years ago • 1 comments

I just fission up'd the events directory, but because I have a handful of keys that I switch between, it failed at the end because I guess my loyal-short-sand-bat was owned by another one of my accounts.

We should check for auth first, THEN ipfs add everything, and THEN set the top level DAG CID.

Error message was 401, so it should be more like:

This account USERNAME doesn't have access to upload to this app APP-HAS-NAME

Debug failure at the bottom:

FailureResponse (Request {requestPath = (BaseUrl {baseUrlScheme = Https, baseUrlHost = "runfission.com", baseUrlPort = 443, baseUrlPath = ""},"/app/loyal-short-sand-bat.fission.app/QmfP5dFsxC1pMhBAniLdrC3FafKXjAJEJZLEd7njaw8Ngc"), requestQueryString = fromList [("copy-data",Just "true")], requestBody = Nothing, requestAccept = fromList [], requestHeaders = fromList [("Authorization","Bearer eyJ1YXYiOiIxLjAuMCIsImFsZyI6IkVkMjU1MTkiLCJjdHkiOm51bGwsInR5cCI6IkpXVCJ9.eyJwdGMiOiJBUFBFTkQiLCJuYmYiOjE1OTY3NTk0MTgsInJzYyI6eyJmbG9vZnMiOiIvIn0sImV4cCI6MTU5Njc1OTQ3OCwiaXNzIjoiZGlkOmtleTp6U3RFa3NEcnhrd1ltcHpxQmRBUWpqeDFQUmJIRzNmcTRDaEdlSmNZVVlVNDRhNENCVUV4VFRqZUNib3A2VXVyIiwicHJmIjpudWxsLCJhdWQiOiJkaWQ6a2V5OnpTdEVacHpTTXRUdDlrMnZzemd2Q3dGNGZMUVFTeUExNVc1QVE0ejNBUjZCeDRlRko1Y3JKRmJ1R3hLbWJtYTQifQ.ADK5iWG7a0wS5SGQJXT88u8H5P9MfmDLXOV7DECSVrsmWpwJfaKf1AsXZqQ7koTfQ3hFdmf_Qr7A9y5eQhJlAg")], requestHttpVersion = HTTP/1.1, requestMethod = "PATCH"}) (Response {responseStatusCode = Status {statusCode = 401, statusMessage = "Unauthorized"}, responseHeaders = fromList [("Date","Fri, 07 Aug 2020 00:17:29 GMT"),("Transfer-Encoding","chunked"),("Connection","keep-alive"),("Server","Warp/3.3.10")], responseHttpVersion = HTTP/1.1, responseBody = ""})
@(<unknown>:0:0)
🚫 Server unable to sync data

bmann avatar Aug 07 '20 00:08 bmann

Doing this every time feels like overkill, but you're right that waiting for it to fail sucks. Here's a strategy:

  1. Read in the app's fission.yaml
  2. Look at known_writers field
  3. If current DID is in the list, continue as normal. Otherwise:
  4. Attempt with ?dry_run flag set on HTTP request (would need to be implemented)
  5. If response isn't a 2xx, report error to the user. Otherwise:
  6. Write DID to known_writers
  7. Continue as normal

Alternately to avoid leaking who has written to this app before, you can store the name of apps for the local machine in the global ~/.config/fission/config.yaml (❗ probably this actually version)

expede avatar Apr 24 '21 20:04 expede