-
Notifications
You must be signed in to change notification settings - Fork 8
/
grpcurl.go
84 lines (73 loc) · 2.71 KB
/
grpcurl.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright 2022 Namespace Labs Inc; All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
package grpcurl
import (
"context"
"fmt"
"path/filepath"
specs "github.com/opencontainers/image-spec/specs-go/v1"
"namespacelabs.dev/foundation/internal/artifacts"
"namespacelabs.dev/foundation/internal/artifacts/download"
"namespacelabs.dev/foundation/internal/artifacts/unpack"
"namespacelabs.dev/foundation/internal/compute"
"namespacelabs.dev/foundation/internal/fnerrors"
"namespacelabs.dev/foundation/internal/fnfs/tarfs"
"namespacelabs.dev/foundation/schema"
"namespacelabs.dev/foundation/std/tasks"
)
const version = "1.8.6"
var Pins = map[string]artifacts.Reference{
"linux/amd64": {
URL: "https://github.com/fullstorydev/grpcurl/releases/download/v1.8.6/grpcurl_1.8.6_linux_x86_64.tar.gz",
Digest: schema.Digest{
Algorithm: "sha256",
Hex: "5d6768248ea75b30fba09c09ff8ba91fbc0dd1a33361b847cdaf4825b1b514a7",
},
},
"linux/arm64": {
URL: "https://github.com/fullstorydev/grpcurl/releases/download/v1.8.6/grpcurl_1.8.6_linux_arm64.tar.gz",
Digest: schema.Digest{
Algorithm: "sha256",
Hex: "8e68cef2b493e79ebf8cb6d867678cbba0b9c5dea75f238575fca4f3bcc539b2",
},
},
"darwin/arm64": {
URL: "https://github.com/fullstorydev/grpcurl/releases/download/v1.8.6/grpcurl_1.8.6_osx_arm64.tar.gz",
Digest: schema.Digest{
Algorithm: "sha256",
Hex: "fe3ce63efb168e894f4af58512b1bd9e3327166f1616975a7dbb249a990ce6cf",
},
},
"darwin/amd64": {
URL: "https://github.com/fullstorydev/grpcurl/releases/download/v1.8.6/grpcurl_1.8.6_osx_x86_64.tar.gz",
Digest: schema.Digest{
Algorithm: "sha256",
Hex: "f908d8d2006efaf702097593a2e030ddc9274c7d349b85bee9d3cfa099018854",
},
},
}
type Grpcurl string
func EnsureSDK(ctx context.Context, p specs.Platform) (Grpcurl, error) {
sdk, err := SDK(ctx, p)
if err != nil {
return "", err
}
return compute.GetValue(ctx, sdk)
}
func SDK(ctx context.Context, p specs.Platform) (compute.Computable[Grpcurl], error) {
key := fmt.Sprintf("%s/%s", p.OS, p.Architecture)
ref, ok := Pins[key]
if !ok {
return nil, fnerrors.New("platform not supported: %s", key)
}
fsys := unpack.Unpack("grpcurl", tarfs.TarGunzip(download.URL(ref)))
return compute.Map(
tasks.Action("grpcurl.ensure").Arg("version", version).HumanReadablef("Ensuring grpcurl %s is installed", version),
compute.Inputs().Computable("fsys", fsys).JSON("platform", p),
compute.Output{},
func(ctx context.Context, r compute.Resolved) (Grpcurl, error) {
unpacked := compute.MustGetDepValue(r, fsys, "fsys")
return Grpcurl(filepath.Join(unpacked.Files, "grpcurl")), nil
}), nil
}