Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
9457727
style(pkg/app): reorder defined types so symbol AST is more logical
Integralist Dec 13, 2022
1ba6232
build(pkg/app): ignore semgrep errors for assigning to global
Integralist Dec 13, 2022
e35c287
refactor(pkg/github): add type comments for LSP client hover information
Integralist Dec 13, 2022
71f0855
feat(pkg/github): replace implementation with DevHub endpoint
Integralist Dec 13, 2022
e789ada
refactor(pkg/github): rename GitHub type to avoid stutter
Integralist Dec 15, 2022
3db59d8
refactor(main): inline variable declarations
Integralist Dec 15, 2022
40b8c0f
refactor: rename cliVersioner
Integralist Dec 15, 2022
589e981
refactor: rename viceroyVersioner
Integralist Dec 15, 2022
70fb8f5
build(pkg/commands/version): ignore semgrep error for exec.Command call
Integralist Dec 15, 2022
aaef412
refactor(pkg/mock): remove unused fields
Integralist Dec 15, 2022
d6f1d21
refactor: rename Versioner.Binary
Integralist Dec 15, 2022
9b6024e
refactor(pkg/github): rename Versioner
Integralist Dec 15, 2022
fb59283
refactor(pkg/github): rename dir variable
Integralist Dec 15, 2022
8bc5d77
refactor(pkg/commands/update): rename latestPath variable
Integralist Dec 15, 2022
0ba2509
refactor(pkg/github): extract inline logic to separate functions
Integralist Dec 15, 2022
5a3ea9b
docs(pkg/github) add documentation to extracted functions
Integralist Dec 15, 2022
6de6006
refactor(pkg/github): avoid bad return pattern
Integralist Dec 15, 2022
df5d6ba
docs(pkg/errors): add comments to RemediationError type
Integralist Dec 15, 2022
5f5b0eb
style(pkg/github): move functions around to align with symbols AST
Integralist Dec 15, 2022
afbb7f0
refactor(pkg/github): avoid mutation side-effect
Integralist Dec 15, 2022
298a7a5
refactor(pkg/github): add context to error messages
Integralist Dec 15, 2022
33428b5
docs(pkg/github): document end-to-end integration test
Integralist Dec 15, 2022
8ea70a1
build(pkg/commands/update): ignore semgrep invalid-usage-of-modified-…
Integralist Jan 3, 2023
1555a8e
refactor(pkg/commands/update): rename variable
Integralist Jan 3, 2023
c12cbe1
build(goreleaser): convert number to string
Integralist Jan 3, 2023
fcd4890
build(goreleaser): generate tar.gz for all platforms
Integralist Jan 3, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ builds:
- <<: *build_defaults
id: linux
goos: [linux]
goarch: [386, amd64, arm64]
goarch: ["386", amd64, arm64]
- <<: *build_defaults
id: windows
goos: [windows]
goarch: [386, amd64, arm64]
goarch: ["386", amd64, arm64]
- <<: *build_defaults
id: generate-usage
goos: [linux]
Expand All @@ -37,20 +37,14 @@ builds:
hooks:
post:
- cmd: "scripts/documentation.sh {{ .Path }}"
# https://goreleaser.com/customization/archive/
# NOTE:Default `format` is tar.gz
archives:
- id: nix
builds: [macos, linux]
<<: &archive_defaults
name_template: "{{ .ProjectName }}_v{{ .Version }}_{{ .Os }}-{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
files:
- none*
- builds: [macos, linux, windows]
name_template: "{{ .ProjectName }}_v{{ .Version }}_{{ .Os }}-{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
files:
- none* # https://goreleaser.com/customization/archive/#packaging-only-the-binaries
wrap_in_directory: false
format: tar.gz
- id: windows
builds: [windows]
<<: *archive_defaults
wrap_in_directory: false
format: zip
aurs:
-
homepage: "https://github.com/fastly/cli"
Expand Down
24 changes: 12 additions & 12 deletions cmd/fastly/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,6 @@ func main() {
httpClient = &http.Client{Timeout: time.Second * 5}
in io.Reader = os.Stdin
out io.Writer = sync.NewWriter(color.Output)
versionerCLI = github.New(github.Opts{
Org: "fastly",
Repo: "cli",
Binary: "fastly",
})
versionerViceroy = github.New(github.Opts{
Org: "fastly",
Repo: "viceroy",
Binary: "viceroy",
})
)

// We have to manually handle the inclusion of the verbose flag here because
Expand Down Expand Up @@ -126,8 +116,18 @@ func main() {
Stdin: in,
Stdout: out,
Versioners: app.Versioners{
CLI: versionerCLI,
Viceroy: versionerViceroy,
CLI: github.New(github.Opts{
HTTPClient: httpClient,
Org: "fastly",
Repo: "cli",
Binary: "fastly",
}),
Viceroy: github.New(github.Opts{
HTTPClient: httpClient,
Org: "fastly",
Repo: "viceroy",
Binary: "viceroy",
}),
},
}
err = app.Run(opts)
Expand Down
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ require (
github.com/fsnotify/fsnotify v1.6.0
github.com/getsentry/sentry-go v0.16.0
github.com/google/go-cmp v0.5.9
github.com/google/go-github/v38 v38.1.0
github.com/mattn/go-isatty v0.0.16
github.com/mholt/archiver/v3 v3.5.1
github.com/mitchellh/go-wordwrap v1.0.1
Expand Down Expand Up @@ -55,7 +54,6 @@ require (
github.com/rogpeppe/go-internal v1.8.0 // indirect
github.com/ulikunitz/xz v0.5.10 // indirect
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
golang.org/x/crypto v0.0.0-20220926161630-eccd6366d1be // indirect
golang.org/x/net v0.2.0 // indirect
golang.org/x/text v0.4.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
9 changes: 0 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbS
github.com/getsentry/sentry-go v0.16.0 h1:owk+S+5XcgJLlGR/3+3s6N4d+uKwqYvh/eS0AIMjPWo=
github.com/getsentry/sentry-go v0.16.0/go.mod h1:ZXCloQLj0pG7mja5NK6NPf2V4A88YJ4pNlc2mOHwh6Y=
github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/snappy v0.0.2/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
Expand All @@ -42,9 +41,6 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-github/v38 v38.1.0 h1:C6h1FkaITcBFK7gAmq4eFzt6gbhEhk7L5z6R3Uva+po=
github.com/google/go-github/v38 v38.1.0/go.mod h1:cStvrz/7nFr0FoENgG6GLbp53WaelXucT+BBz/3VKx4=
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/google/jsonapi v1.0.0 h1:qIGgO5Smu3yJmSs+QlvhQnrscdZfFhiV6S8ryJAglqU=
Expand Down Expand Up @@ -140,18 +136,14 @@ github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20220926161630-eccd6366d1be h1:fmw3UbQh+nxngCAHrDCCztao/kbYFnWjoqop8dHx05A=
golang.org/x/crypto v0.0.0-20220926161630-eccd6366d1be/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.2.0 h1:sZfSu1wtKLGlWI4ZZayP0ck9Y73K1ynO6gqzTdBVdPU=
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down Expand Up @@ -187,7 +179,6 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
Expand Down
55 changes: 27 additions & 28 deletions pkg/app/run.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package app

import (
"context"
"fmt"
"io"
"os"
"strings"
"time"

"github.com/fastly/cli/pkg/api"
"github.com/fastly/cli/pkg/commands/update"
Expand All @@ -23,24 +21,11 @@ import (
"github.com/fastly/kingpin"
)

// Versioners represents all supported versioner types.
type Versioners struct {
CLI github.Versioner
Viceroy github.Versioner
}

// RunOpts represent arguments to Run()
type RunOpts struct {
APIClient APIClientFactory
Args []string
ConfigFile config.File
ConfigPath string
Env config.Environment
ErrLog fsterr.LogInterface
HTTPClient api.HTTPClient
Stdin io.Reader
Stdout io.Writer
Versioners Versioners
// FastlyAPIClient is a ClientFactory that returns a real Fastly API client
// using the provided token and endpoint.
func FastlyAPIClient(token, endpoint string) (api.Interface, error) {
client, err := fastly.NewClientForEndpoint(token, endpoint)
return client, err
}

// Run constructs the application including all of the subcommands, parses the
Expand Down Expand Up @@ -175,23 +160,24 @@ func Run(opts RunOpts) error {
}
}

// NOTE: We return error immediately so there's no issue assigning to global.
// nosemgrep
globals.APIClient, err = opts.APIClient(token, endpoint)
if err != nil {
globals.ErrLog.Add(err)
return fmt.Errorf("error constructing Fastly API client: %w", err)
}

// NOTE: We return error immediately so there's no issue assigning to global.
// nosemgrep
globals.RTSClient, err = fastly.NewRealtimeStatsClientForEndpoint(token, fastly.DefaultRealtimeStatsEndpoint)
if err != nil {
globals.ErrLog.Add(err)
return fmt.Errorf("error constructing Fastly realtime stats client: %w", err)
}

if opts.Versioners.CLI != nil && name != "update" && !version.IsPreRelease(revision.AppVersion) {
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
defer cancel() // push cancel on the defer stack first...
f := update.CheckAsync(
ctx,
revision.AppVersion,
opts.Versioners.CLI,
globals.Flag.Quiet,
Expand All @@ -202,18 +188,31 @@ func Run(opts RunOpts) error {
return command.Exec(opts.Stdin, opts.Stdout)
}

// RunOpts represent arguments to Run()
type RunOpts struct {
APIClient APIClientFactory
Args []string
ConfigFile config.File
ConfigPath string
Env config.Environment
ErrLog fsterr.LogInterface
HTTPClient api.HTTPClient
Stdin io.Reader
Stdout io.Writer
Versioners Versioners
}

// APIClientFactory creates a Fastly API client (modeled as an api.Interface)
// from a user-provided API token. It exists as a type in order to parameterize
// the Run helper with it: in the real CLI, we can use NewClient from the Fastly
// API client library via RealClient; in tests, we can provide a mock API
// interface via MockClient.
type APIClientFactory func(token, endpoint string) (api.Interface, error)

// FastlyAPIClient is a ClientFactory that returns a real Fastly API client
// using the provided token and endpoint.
func FastlyAPIClient(token, endpoint string) (api.Interface, error) {
client, err := fastly.NewClientForEndpoint(token, endpoint)
return client, err
// Versioners represents all supported versioner types.
type Versioners struct {
CLI github.AssetVersioner
Viceroy github.AssetVersioner
}

// displayTokenSource prints the token source.
Expand Down
Loading