|
|
@@ -23,6 +23,7 @@ import (
|
|
|
"github.com/peterbourgon/ff/v3/ffcli"
|
|
|
"github.com/tailscale/hujson"
|
|
|
"golang.org/x/oauth2/clientcredentials"
|
|
|
+ "tailscale.com/client/tailscale"
|
|
|
"tailscale.com/util/httpm"
|
|
|
)
|
|
|
|
|
|
@@ -270,7 +271,7 @@ func applyNewACL(ctx context.Context, client *http.Client, tailnet, apiKey, poli
|
|
|
got := resp.StatusCode
|
|
|
want := http.StatusOK
|
|
|
if got != want {
|
|
|
- var ate ACLTestError
|
|
|
+ var ate ACLGitopsTestError
|
|
|
err := json.NewDecoder(resp.Body).Decode(&ate)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
@@ -306,7 +307,7 @@ func testNewACLs(ctx context.Context, client *http.Client, tailnet, apiKey, poli
|
|
|
}
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
- var ate ACLTestError
|
|
|
+ var ate ACLGitopsTestError
|
|
|
err = json.NewDecoder(resp.Body).Decode(&ate)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
@@ -327,12 +328,12 @@ func testNewACLs(ctx context.Context, client *http.Client, tailnet, apiKey, poli
|
|
|
|
|
|
var lineColMessageSplit = regexp.MustCompile(`line ([0-9]+), column ([0-9]+): (.*)$`)
|
|
|
|
|
|
-type ACLTestError struct {
|
|
|
- Message string `json:"message"`
|
|
|
- Data []ACLTestErrorDetail `json:"data"`
|
|
|
+// ACLGitopsTestError is redefined here so we can add a custom .Error() response
|
|
|
+type ACLGitopsTestError struct {
|
|
|
+ tailscale.ACLTestError
|
|
|
}
|
|
|
|
|
|
-func (ate ACLTestError) Error() string {
|
|
|
+func (ate ACLGitopsTestError) Error() string {
|
|
|
var sb strings.Builder
|
|
|
|
|
|
if *githubSyntax && lineColMessageSplit.MatchString(ate.Message) {
|
|
|
@@ -349,20 +350,28 @@ func (ate ACLTestError) Error() string {
|
|
|
fmt.Fprintln(&sb)
|
|
|
|
|
|
for _, data := range ate.Data {
|
|
|
- fmt.Fprintf(&sb, "For user %s:\n", data.User)
|
|
|
- for _, err := range data.Errors {
|
|
|
- fmt.Fprintf(&sb, "- %s\n", err)
|
|
|
+ if data.User != "" {
|
|
|
+ fmt.Fprintf(&sb, "For user %s:\n", data.User)
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(data.Errors) > 0 {
|
|
|
+ fmt.Fprint(&sb, "Errors found:\n")
|
|
|
+ for _, err := range data.Errors {
|
|
|
+ fmt.Fprintf(&sb, "- %s\n", err)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(data.Warnings) > 0 {
|
|
|
+ fmt.Fprint(&sb, "Warnings found:\n")
|
|
|
+ for _, err := range data.Warnings {
|
|
|
+ fmt.Fprintf(&sb, "- %s\n", err)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return sb.String()
|
|
|
}
|
|
|
|
|
|
-type ACLTestErrorDetail struct {
|
|
|
- User string `json:"user"`
|
|
|
- Errors []string `json:"errors"`
|
|
|
-}
|
|
|
-
|
|
|
func getACLETag(ctx context.Context, client *http.Client, tailnet, apiKey string) (string, error) {
|
|
|
req, err := http.NewRequestWithContext(ctx, httpm.GET, fmt.Sprintf("https://%s/api/v2/tailnet/%s/acl", *apiServer, tailnet), nil)
|
|
|
if err != nil {
|