Centralize data API auth handling · Entire

Centralize data API auth handling

81a9dfa→main·

evjan·1mo ago·6 files·+229 added/-192 removed

Sessions

0ee0f475b9f7View transcript

Changes

6

1 unmodified line

2
3
4
5
5
6
7
4 unmodified lines

12
13
14
16
15
16
17
38 unmodified lines

56
57
58
61
62
63
64
65
66
67
68
69
59
60
61
62
63
71
72
73
74
75
76
77
78
79
80
81
64
83
84
85
86
87
88
65
66
67
68
69

1 unmodified line

import (
    "context"
    "errors"
    "fmt"
    "io"
    "net/url"
    
    "time"
    
    "github.com/entireio/cli/cmd/entire/cli/api"
    "github.com/entireio/cli/cmd/entire/cli/auth"
    "github.com/entireio/cli/cmd/entire/cli/interactive"
    "github.com/spf13/cobra"
    "golang.org/x/sync/errgroup"
    38 unmodified lines
)

func runActivity(ctx context.Context, w, errW io.Writer) error {
    client, err := NewAuthenticatedAPIClient(ctx, false)
    if err != nil {
        if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
            return NewSilentError(err)
        }
        return runAuthenticatedDataAPI(ctx, errW, false, func(ctx context.Context, client *api.Client) error {
        if !interactive.IsTerminalWriter(w) || IsAccessibleMode() {
            return runActivityStatic(ctx, w, client)
        }
        if errors.Is(err, auth.ErrNotLoggedIn) {
            fmt.Fprintln(errW, "Not logged in. Run 'entire login' to authenticate.")
            return NewSilentError(err)
        }
        return err
    })
}

func runActivityStatic(ctx context.Context, w io.Writer, client *api.Client) error {
}

mcmd/entire/cli/activity_cmd.go+6/-28

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

package cli

import ( "context" "errors" "fmt" "io"

"github.com/entireio/cli/cmd/entire/cli/api" "github.com/entireio/cli/cmd/entire/cli/auth" )

func runAuthenticatedDataAPI(ctx context.Context, errW io.Writer, insecureHTTP bool, fn func(context.Context, *api.Client) error) error { client, err := NewAuthenticatedAPIClient(ctx, insecureHTTP) if err != nil { return renderDataAPIAuthError(errW, err) } return fn(ctx, client) }

func renderDataAPIAuthError(errW io.Writer, err error) error { if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) { return NewSilentError(err) } if errors.Is(err, auth.ErrNotLoggedIn) { fmt.Fprintln(errW, "Not logged in. Run 'entire login' to authenticate.") return NewSilentError(err) } return err }

mcmd/entire/cli/authcmd.go+33

49 unmodified lines

50
51
52
53
53
54
55
56
37 unmodified lines

94
95
96
97
98
99
100
101
97
98
99
100
101
102
103
103
104
105
106
104
105
106
107
108
108
109
110
111
109
110
111
112
113
114
115
116
113
114
115
116
117
118
119
120
121
122
117
118
119
120
121
122
29 unmodified lines

152
153
154
158
155
156
157
158
7 unmodified lines

166
167
168
172
169
170
171
172
173
174
175
176
177
178
13 unmodified lines

192
193
194
192
193
194
195
196
195
196
197
358 unmodified lines

556
557
558
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
559
589
590
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
49 unmodified lines

641
642
643
646
644
645
646
647
648
649
648
649
650
651
650
651
652
653
654
655
656
657
653
654
655
656
657
658
659
660
658
659
660
662
661
662
664
663
664
665
666
666
667
668
669
670
671
672
673
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
675
676
677
678
679
680
681
682
683
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
685
686
687
704
705
706
707
708
709
710
711
689
712
691
692
693
713
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
714
715
716
717
718
719
720
721
712
722
723
724
725
726
727
728
729
730
714
715
716
717
718
731
732
733
734
720
735
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
736
737
738
739
740
741

49 unmodified lines

Running 'entire trail' without a subcommand shows the trail for the current branch, or lists recent trails if no trail exists for the current branch.`