ce7cb702218693d08ea6d83464d2457c9250027c
This commit is contained in:
commit
34c5f8963c
1 changed files with 145336 additions and 0 deletions
42
services/grafana-plugins/install.fsx
Normal file
42
services/grafana-plugins/install.fsx
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
module Install
|
||||
|
||||
#r "/opt/fsi/packages/AWSSDK.Core.dll"
|
||||
#r "/opt/fsi/packages/AWSSDK.S3.dll"
|
||||
|
||||
open System
|
||||
open System.IO
|
||||
open System.IO.Compression
|
||||
open System.Security.Cryptography
|
||||
open Amazon.Runtime
|
||||
open Amazon.S3
|
||||
open Amazon.S3.Model
|
||||
|
||||
[<CLIMutable>]
|
||||
type Settings =
|
||||
{ Endpoint: string
|
||||
Bucket: string
|
||||
Key: string
|
||||
Sha256: string
|
||||
AccessKey: string }
|
||||
|
||||
let unpack expected (input: Stream) destination =
|
||||
use archive = new MemoryStream()
|
||||
input.CopyTo archive
|
||||
archive.Position <- 0L
|
||||
let actual = SHA256.HashData archive |> Convert.ToHexString |> _.ToLowerInvariant()
|
||||
if actual <> expected then
|
||||
invalidOp "plugin archive checksum differs"
|
||||
archive.Position <- 0L
|
||||
use zip = new ZipArchive(archive, ZipArchiveMode.Read)
|
||||
zip.ExtractToDirectory(destination, true)
|
||||
for entry in zip.Entries do
|
||||
if entry.Name <> "" then
|
||||
File.SetUnixFileMode(Path.Combine(destination, entry.FullName), enum<UnixFileMode> ((entry.ExternalAttributes >>> 16) &&& 0o777))
|
||||
|
||||
let run settings password destination =
|
||||
let config = AmazonS3Config(ServiceURL = settings.Endpoint, AuthenticationRegion = "us-east-1", ForcePathStyle = true)
|
||||
use client = new AmazonS3Client(BasicAWSCredentials(settings.AccessKey, password), config)
|
||||
let request = GetObjectRequest(BucketName = settings.Bucket, Key = settings.Key)
|
||||
use reply = client.GetObjectAsync(request).GetAwaiter().GetResult()
|
||||
unpack settings.Sha256 reply.ResponseStream destination
|
||||
printfn "Installed plugin archive sha256:%s" settings.Sha256
|
||||
Loading…
Reference in a new issue