purescript / registry-dev

Development work related to the PureScript Registry
https://github.com/purescript/registry
95 stars 80 forks source link

Update from deprecated aws-sdk bindings #678

Closed thomashoneyman closed 9 months ago

thomashoneyman commented 9 months ago

Fixes #629. I manually verified that the inputs (params we pass to the s3 object) and outputs (data we receive) are unchanged in the new SDK, but I haven't actually run this code against our live bucket because the giant legacy importer run is going.

f-f commented 9 months ago

Now that you're also online we can merge this and eventually revert it real quick if it's broken 😄

thomashoneyman commented 9 months ago

I was actually putting together a little script to upload, download, and delete an object in storage to be sure before I merge :) Let me give that a quick try and if it works I'll merge! I'll need about 1.5hrs before I can do it.

f-f commented 9 months ago

Ah that's lovely, thank you 🙂

thomashoneyman commented 9 months ago

Ran this script to test things out, with a tarball at delete-me-1.0.0 locally:

ain :: Effect Unit
main = launchAff_ do
  -- Environment
  _ <- Env.loadEnvFile ".env"
  resources <- Env.lookupResourceEnv
  s3 <- lift2 { key: _, secret: _ } (Env.lookupRequired Env.spacesKey) (Env.lookupRequired Env.spacesSecret)

  let
    cache = Path.concat [ scratchDir, ".cache" ]

    work = do
      Storage.upload (unsafePackageName "delete-me") (unsafeVersion "1.0.0") (Path.concat [ scratchDir, "delete-me-1.0.0" ])
      versions <- Storage.query (unsafePackageName "delete-me")
      Console.log $ "Versions (uploaded): " <> String.joinWith ", " (map Version.print (Set.toUnfoldable versions))
      Storage.download (unsafePackageName "delete-me") (unsafeVersion "1.0.0") (Path.concat [ scratchDir, "delete-me-2.0.0" ])
      Storage.delete (unsafePackageName "delete-me") (unsafeVersion "1.0.0")
      versions2 <- Storage.query (unsafePackageName "delete-me")
      Console.log $ "Versions (deleted): " <> String.joinWith ", " (map Version.print (Set.toUnfoldable versions2))

  work
    # Storage.interpret (Storage.handleS3 { s3, cache })
    # Log.interpret (Log.handleTerminal Verbose)
    # Except.catch (\e -> Run.liftEffect (Console.log e *> Process.exit 1))
    # Env.runResourceEnv resources
    # Run.runBaseAff'

This works just fine with the v2 of aws-sdk:

Read file for delete-me@1.0.0, now uploading to delete-me/1.0.0.tar.gz...
Connecting to the bucket purescript-registry at space https://ams3.digitaloceanspaces.com with public key YMQJ24GQQ2ZOGFXZWVQB
Connected to S3!
Uploading release to the bucket at path delete-me/1.0.0.tar.gz
Uploaded delete-me@1.0.0 to the bucket at path delete-me/1.0.0.tar.gz
Connecting to the bucket purescript-registry at space https://ams3.digitaloceanspaces.com with public key YMQJ24GQQ2ZOGFXZWVQB
Connected to S3!
Versions (uploaded): 1.0.0
Deleting delete-me@1.0.0
Connecting to the bucket purescript-registry at space https://ams3.digitaloceanspaces.com with public key YMQJ24GQQ2ZOGFXZWVQB
Connected to S3!
Deleting release from the bucket at path delete-me/1.0.0.tar.gz
Deleted release of delete-me@1.0.0 from S3 at the path delete-me/1.0.0.tar.gz
Connecting to the bucket purescript-registry at space https://ams3.digitaloceanspaces.com with public key YMQJ24GQQ2ZOGFXZWVQB
Connected to S3!
Versions (deleted):

However, it turns out that the Contents key is now optional in the response; with that fixed this PR works as well.