Skip to content

Commit ade7aa4

Browse files
authored
feat: Publish command (cloudquery#13948)
This adds a `cloudquery publish` command to the CLI that can publish plugins to the upcoming CloudQuery registry. It reads a `dist` directory with package.json, created by the plugin-sdk, and calls the CloudQuery API to upload the files and metadata in the directory as a new plugin version. This command will mainly be used by plugin authors to upload a new version of their plugin to the registry.
1 parent 15b0b69 commit ade7aa4

14 files changed

Lines changed: 1172 additions & 23 deletions

cli/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ test:
1010
.PHONY: gen-docs
1111
gen-docs:
1212
rm -rf ../website/pages/docs/reference/cli/*.md
13-
go run main.go doc ../website/pages/docs/reference/cli/
13+
go run main.go doc ../website/pages/docs/reference/cli/

cli/cmd/login.go

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import (
1313
"syscall"
1414
"time"
1515

16-
"github.com/adrg/xdg"
1716
"github.com/cenkalti/backoff/v4"
17+
"github.com/cloudquery/cloudquery/cli/internal/auth"
1818
"github.com/pkg/browser"
1919
"github.com/spf13/cobra"
2020
)
@@ -47,7 +47,6 @@ func newCmdLogin() *cobra.Command {
4747

4848
go func() {
4949
<-sigChan
50-
fmt.Println("Received SIGTERM!")
5150
cancel()
5251
}()
5352

@@ -81,21 +80,6 @@ func waitForServer(ctx context.Context, url string) error {
8180
}
8281

8382
func runLogin(ctx context.Context) (err error) {
84-
tokenFilePath, err := xdg.DataFile("cloudquery/token")
85-
if err != nil {
86-
return fmt.Errorf("can't determine a proper location for token file: %w", err)
87-
}
88-
tokenFile, err := os.OpenFile(tokenFilePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o644)
89-
if err != nil {
90-
return fmt.Errorf("can't open token file %q for writing: %w", tokenFilePath, err)
91-
}
92-
defer func() {
93-
e := tokenFile.Close()
94-
if err == nil && e != nil {
95-
err = fmt.Errorf("can't close token file %q after writing: %w", tokenFilePath, e)
96-
}
97-
}()
98-
9983
mux := http.NewServeMux()
10084
refreshToken := ""
10185
gotToken := make(chan struct{})
@@ -158,8 +142,9 @@ func runLogin(ctx context.Context) (err error) {
158142
if refreshToken == "" {
159143
return fmt.Errorf("failed to get refresh token")
160144
}
161-
if _, err = tokenFile.WriteString(refreshToken); err != nil {
162-
return fmt.Errorf("failed to write token to %q: %w", tokenFilePath, err)
145+
err = auth.SaveRefreshToken(refreshToken)
146+
if err != nil {
147+
return fmt.Errorf("failed to save refresh token: %w", err)
163148
}
164149

165150
fmt.Println("CLI successfully authenticated.")

0 commit comments

Comments
 (0)