-
Notifications
You must be signed in to change notification settings - Fork 57
/
extsvc.go
79 lines (63 loc) · 1.79 KB
/
extsvc.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
package main
import (
"context"
"flag"
"fmt"
"github.com/sourcegraph/sourcegraph/lib/errors"
"github.com/sourcegraph/src-cli/internal/api"
)
var extsvcCommands commander
func init() {
usage := `'src extsvc' is a tool that manages external services on a Sourcegraph instance.
Usage:
src extsvc command [command options]
The commands are:
list lists the external services on the Sourcegraph instance
edit edits external services on the Sourcegraph instance
add add an external service on the Sourcegraph instance
Use "src extsvc [command] -h" for more information about a command.
`
flagSet := flag.NewFlagSet("extsvc", flag.ExitOnError)
handler := func(args []string) error {
extsvcCommands.run(flagSet, "src extsvc", usage, args)
return nil
}
// Register the command.
commands = append(commands, &command{
flagSet: flagSet,
aliases: []string{"extsvc", "external-service"},
handler: handler,
usageFunc: func() {
fmt.Println(usage)
},
})
}
type externalService struct {
ID string
Kind string
DisplayName string
Config string
CreatedAt, UpdatedAt string
}
var errServiceNotFound = errors.New("no such external service")
func lookupExternalService(ctx context.Context, client api.Client, byID, byName string) (*externalService, error) {
var result struct {
ExternalServices struct {
Nodes []*externalService
}
}
if ok, err := client.NewRequest(externalServicesListQuery, map[string]interface{}{
"first": 99999,
}).Do(ctx, &result); err != nil || !ok {
return nil, err
}
for _, svc := range result.ExternalServices.Nodes {
if byID != "" && svc.ID == byID {
return svc, nil
}
if byName != "" && svc.DisplayName == byName {
return svc, nil
}
}
return nil, errServiceNotFound
}