quorate/services/minecraft/store.fsx

36 lines
1.4 KiB
FSharp

module Store
#r "/opt/fsi/packages/AWSSDK.Core.dll"
#r "/opt/fsi/packages/AWSSDK.S3.dll"
#load "bootstrap.fsx"
open System.IO
open Amazon.Runtime
open Amazon.S3
open Amazon.S3.Model
open Bootstrap
let connect auth =
let credential name = File.ReadAllText(Path.Combine(auth, name))
let config = AmazonS3Config(ServiceURL = "https://s3.quorate.internal", AuthenticationRegion = "us-east-1", ForcePathStyle = true)
new AmazonS3Client(BasicAWSCredentials(credential "accesskey", credential "secretkey"), config)
let request key = GetObjectRequest(BucketName = "artifacts", Key = key)
let manifest (client: AmazonS3Client) key =
use reply = client.GetObjectAsync(request ("minecraft/" + key)).GetAwaiter().GetResult()
use reader = new StreamReader(reply.ResponseStream)
reader.ReadToEnd()
let fetchObject (client: AmazonS3Client) key hash path =
if not (File.Exists path) || digest path <> hash then
let temporary = path + ".download"
use reply = client.GetObjectAsync(request key).GetAwaiter().GetResult()
use output = File.Create temporary
reply.ResponseStream.CopyTo output
output.Close()
if digest temporary <> hash then invalidOp "download checksum differs"
File.Move(temporary, path, true)
let fetch client key = fetchObject client ("minecraft/" + key)
let saltatory client hash = fetchObject client ("saltatory/" + hash + ".jar") hash