Skip to content

Commit 82c294f

Browse files
olblakdduportal
andauthored
Add Updatecli integration with Udash (updatecli#1344)
* Add updatecli login for authenticating on an API backend Signed-off-by: Olblak <[email protected]> * mitigate slowloris attack handle error Signed-off-by: Olblak <[email protected]> * fix logrus error-wrapping directive Signed-off-by: Olblak <[email protected]> * Add checkspelling allow word Signed-off-by: Olblak <[email protected]> * Update url used to publish report Signed-off-by: Olblak <[email protected]> * refactor publish command Signed-off-by: Olblak <[email protected]> * Rename target result field OldInformation to information Signed-off-by: Olblak <[email protected]> * Remove missing line Signed-off-by: Olblak <[email protected]> * show url after publishing Signed-off-by: Olblak <[email protected]> * sanitize audience name by removing http scheme Signed-off-by: Olblak <[email protected]> * Refactor auth package Signed-off-by: Olblak <[email protected]> * Remove pointer in pipeline report Signed-off-by: Olblak <[email protected]> * refactor report Signed-off-by: Olblak <[email protected]> * Add ID for each result Signed-off-by: Olblak <[email protected]> * go mod tidy Signed-off-by: Olblak <[email protected]> * Add allow text to spellcheck Signed-off-by: Olblak <[email protected]> * fix cross site scripting error Signed-off-by: Olblak <[email protected]> * Only run updatecli in experimental mode Signed-off-by: Olblak <[email protected]> * Set scm ID Add reportURL param Signed-off-by: Olblak <[email protected]> * Show report url in final report Signed-off-by: Olblak <[email protected]> * refactor auth package Signed-off-by: Olblak <[email protected]> * Improve report publishing UX The purpose of this commit is to reduce the need to specify front and back url by storing those two informations in the configuration file Then a report API can either be specified using a environment variable or relying on the default config Signed-off-by: Olblak <[email protected]> * handle error Signed-off-by: Olblak <[email protected]> * Specify correct return Signed-off-by: Olblak <[email protected]> * fix spelling warning Signed-off-by: Olblak <[email protected]> * Update pkg/core/result/target.go Co-authored-by: Damien Duportal <[email protected]> * Revert "Remove pointer in pipeline report" This reverts commit fc32d7f. * Show report url per pipeline Signed-off-by: Olblak <[email protected]> * Add dryRun information to target result Signed-off-by: Olblak <[email protected]> * Remove reports.Publish in favor of report.Publish Signed-off-by: Olblak <[email protected]> * rename OAUTH to Oauth Signed-off-by: Olblak <[email protected]> --------- Signed-off-by: Olblak <[email protected]> Co-authored-by: Damien Duportal <[email protected]>
1 parent 4d6ec5b commit 82c294f

File tree

35 files changed

+900
-33
lines changed

35 files changed

+900
-33
lines changed

.github/actions/spelling/allow.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,13 @@ minoronly
1010
majoronly
1111
nce
1212
WRONLY
13+
nirasan
14+
skratchdot
15+
pkce
16+
errmsg
17+
authdata
18+
APIURL
1319
oidc
20+
udash
21+
Udash
22+
CLIENTID

cmd/apply.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ var (
3737

3838
func init() {
3939
applyCmd.Flags().StringVarP(&cfgFile, "config", "c", "", "Sets config file or directory. By default, Updatecli looks for a file named 'updatecli.yaml' or a directory named 'updatecli.d'")
40+
applyCmd.Flags().StringVar(&oAuthAudience, "reportAPI", "", "Set the report API URL where to publish pipeline reports")
4041
applyCmd.Flags().StringArrayVarP(&valuesFiles, "values", "v", []string{}, "Sets values file uses for templating")
4142
applyCmd.Flags().StringArrayVar(&secretsFiles, "secrets", []string{}, "Sets Sops secrets file uses for templating")
4243

cmd/diff.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ var (
3535

3636
func init() {
3737
diffCmd.Flags().StringVarP(&cfgFile, "config", "c", "", "Sets config file or directory. By default, Updatecli looks for a file named 'updatecli.yaml' or a directory named 'updatecli.d'")
38+
diffCmd.Flags().StringVar(&oAuthAudience, "reportAPI", "", "Set the report API URL where to publish pipeline reports")
3839
diffCmd.Flags().StringArrayVarP(&valuesFiles, "values", "v", []string{}, "Sets values file uses for templating")
3940
diffCmd.Flags().StringArrayVar(&secretsFiles, "secrets", []string{}, "Sets Sops secrets file uses for templating")
4041
diffCmd.Flags().BoolVar(&diffClean, "clean", false, "Remove updatecli working directory like '--clean=true'")

cmd/login.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package cmd
2+
3+
import (
4+
"os"
5+
6+
"github.com/sirupsen/logrus"
7+
8+
"github.com/spf13/cobra"
9+
)
10+
11+
var (
12+
oAuthClientID string
13+
oAuthIssuer string
14+
oAuthAudience string
15+
endpointURL string
16+
17+
loginCmd = &cobra.Command{
18+
Use: "login url",
19+
Short: "[Experimental] login authenticates with the Updatecli service.",
20+
Example: "updatecli login app.updatecli.io",
21+
Run: func(cmd *cobra.Command, args []string) {
22+
23+
// TODO: To be removed once not experimental anymore
24+
if !experimental {
25+
logrus.Warningf("The 'login' feature requires the flag experimental to work, such as:\n\t`updatecli login --experimental`")
26+
os.Exit(1)
27+
}
28+
29+
switch len(args) {
30+
case 0:
31+
logrus.Errorf("missing URL to login to")
32+
os.Exit(1)
33+
case 1:
34+
endpointURL = args[0]
35+
default:
36+
logrus.Errorf("can only login to one URL at a time")
37+
os.Exit(1)
38+
}
39+
40+
err := run("login")
41+
if err != nil {
42+
logrus.Errorf("command failed")
43+
os.Exit(1)
44+
}
45+
},
46+
}
47+
)
48+
49+
func init() {
50+
loginCmd.Flags().StringVar(&oAuthClientID, "oauth-clientId", "", "oauth-clientId defines the Oauth client ID")
51+
loginCmd.Flags().StringVar(&oAuthIssuer, "oauth-issuer", "", "oauth-issuer defines the Oauth authentication URL")
52+
loginCmd.Flags().StringVar(&oAuthAudience, "oauth-audience", "", "oauth-audience defines the Oauth audience URL")
53+
}

cmd/root.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"os"
55

66
"github.com/sirupsen/logrus"
7+
"github.com/updatecli/updatecli/pkg/core/auth"
78
"github.com/updatecli/updatecli/pkg/core/cmdoptions"
89
"github.com/updatecli/updatecli/pkg/core/log"
910

@@ -63,6 +64,7 @@ func init() {
6364
diffCmd,
6465
prepareCmd,
6566
manifestCmd,
67+
loginCmd,
6668
showCmd,
6769
versionCmd,
6870
docsCmd,
@@ -74,6 +76,7 @@ func run(command string) error {
7476

7577
switch command {
7678
case "apply":
79+
auth.Audience = oAuthAudience
7780
if applyClean {
7881
defer func() {
7982
if err := e.Clean(); err != nil {
@@ -94,6 +97,7 @@ func run(command string) error {
9497
return err
9598
}
9699
case "diff":
100+
auth.Audience = oAuthAudience
97101
if diffClean {
98102
defer func() {
99103
if err := e.Clean(); err != nil {
@@ -134,6 +138,13 @@ func run(command string) error {
134138
return err
135139
}
136140

141+
case "login":
142+
err := auth.Login(endpointURL, oAuthClientID, oAuthIssuer, oAuthAudience)
143+
if err != nil {
144+
logrus.Errorf("%s %s", result.FAILURE, err)
145+
return err
146+
}
147+
137148
// Show is deprecated
138149
case "show", "manifest/show":
139150
if showClean {

go.mod

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ require (
4343
github.com/invopop/jsonschema v0.7.0
4444
github.com/muesli/mango-cobra v1.2.0
4545
github.com/muesli/roff v0.1.0
46+
github.com/nirasan/go-oauth-pkce-code-verifier v0.0.0-20220510032225-4f9f17eaec4c
47+
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966
48+
github.com/spf13/viper v1.15.0
4649
github.com/tomwright/dasel v1.27.3
4750
golang.org/x/text v0.10.0
4851
golang.org/x/time v0.3.0
@@ -53,7 +56,13 @@ require (
5356
cloud.google.com/go/compute/metadata v0.2.3 // indirect
5457
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230106234847-43070de90fa1 // indirect
5558
github.com/containerd/stargz-snapshotter/estargz v0.14.3 // indirect
59+
github.com/fsnotify/fsnotify v1.6.0 // indirect
5660
github.com/go-logr/stdr v1.2.2 // indirect
61+
github.com/magiconair/properties v1.8.7 // indirect
62+
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
63+
github.com/spf13/afero v1.9.3 // indirect
64+
github.com/spf13/jwalterweatherman v1.1.0 // indirect
65+
github.com/subosito/gotenv v1.4.2 // indirect
5766
github.com/vbatts/tar-split v0.11.3 // indirect
5867
go.opentelemetry.io/otel v1.14.0 // indirect
5968
go.opentelemetry.io/otel/trace v1.14.0 // indirect
@@ -80,7 +89,7 @@ require (
8089
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
8190
github.com/acomagu/bufpipe v1.0.4 // indirect
8291
github.com/alecthomas/chroma v0.9.2 // indirect
83-
github.com/armon/go-metrics v0.3.10 // indirect
92+
github.com/armon/go-metrics v0.4.0 // indirect
8493
github.com/armon/go-radix v1.0.0 // indirect
8594
github.com/asaskevich/govalidator v0.0.0-20200428143746-21a406dcc535 // indirect
8695
github.com/beorn7/perks v1.0.1 // indirect

0 commit comments

Comments
 (0)