@@ -72,41 +72,6 @@ func NewRootCommand(parent argparser.Registerer, g *global.Data) *RootCommand {
72
72
func (c * RootCommand ) Exec (in io.Reader , out io.Writer ) error {
73
73
profileName , _ := c .identifyProfileAndFlow ()
74
74
75
- // We need to prompt the user, so they know we're about to open their web
76
- // browser, but we also need to handle the scenario where the `sso` command is
77
- // invoked indirectly via ../../app/run.go as that package will have its own
78
- // (similar) prompt before invoking this command. So to avoid a double prompt,
79
- // the app package will set `SkipAuthPrompt: true`.
80
- if ! c .Globals .SkipAuthPrompt && ! c .Globals .Flags .AutoYes && ! c .Globals .Flags .NonInteractive {
81
- msg := fmt .Sprintf ("We're going to authenticate the '%s' profile" , profileName )
82
- text .Important (out , "%s. We need to open your browser to authenticate you." , msg )
83
- text .Break (out )
84
- cont , err := text .AskYesNo (out , text .BoldYellow ("Do you want to continue? [y/N]: " ), in )
85
- text .Break (out )
86
- if err != nil {
87
- return err
88
- }
89
- if ! cont {
90
- return fsterr.SkipExitError {
91
- Skip : true ,
92
- Err : fsterr .ErrDontContinue ,
93
- }
94
- }
95
- }
96
-
97
- var serverErr error
98
- go func () {
99
- err := c .Globals .AuthServer .Start ()
100
- if err != nil {
101
- serverErr = err
102
- }
103
- }()
104
- if serverErr != nil {
105
- return serverErr
106
- }
107
-
108
- text .Info (out , "Starting a local server to handle the authentication flow." )
109
-
110
75
// For creating/updating a profile we set `prompt` because we want to ensure
111
76
// that another session (from a different profile) doesn't cause unexpected
112
77
// errors for the user flow. This forces a re-auth.
@@ -122,12 +87,18 @@ func (c *RootCommand) Exec(in io.Reader, out io.Writer) error {
122
87
c .Globals .AuthServer .SetParam ("account_hint" , c .ProfileSwitchCustomerID )
123
88
}
124
89
default :
90
+ if c .profile != "" {
91
+ profileName = c .profile
92
+ }
125
93
// Handle `fastly sso` being invoked directly.
126
94
p := profile .Get (profileName , c .Globals .Config .Profiles )
127
95
if p == nil {
128
96
err := fmt .Errorf (profile .DoesNotExist , profileName )
129
97
c .Globals .ErrLog .Add (err )
130
- return err
98
+ return fsterr.RemediationError {
99
+ Inner : err ,
100
+ Remediation : fsterr .ProfileRemediation ,
101
+ }
131
102
}
132
103
c .Globals .AuthServer .SetParam ("prompt" , "login" )
133
104
c .Globals .AuthServer .SetParam ("login_hint" , p .Email )
@@ -142,6 +113,45 @@ func (c *RootCommand) Exec(in io.Reader, out io.Writer) error {
142
113
c .InvokedFromSSO = true
143
114
}
144
115
116
+ // We need to prompt the user, so they know we're about to open their web
117
+ // browser, but we also need to handle the scenario where the `sso` command is
118
+ // invoked indirectly via ../../app/run.go as that package will have its own
119
+ // (similar) prompt before invoking this command. So to avoid a double prompt,
120
+ // the app package will set `SkipAuthPrompt: true`.
121
+ if ! c .Globals .SkipAuthPrompt && ! c .Globals .Flags .AutoYes && ! c .Globals .Flags .NonInteractive {
122
+ var defaultMsg string
123
+ if c .InvokedFromSSO {
124
+ defaultMsg = " and make it the default"
125
+ }
126
+ msg := fmt .Sprintf ("We're going to authenticate the '%s' profile%s" , profileName , defaultMsg )
127
+ text .Important (out , "%s. We need to open your browser to authenticate you." , msg )
128
+ text .Break (out )
129
+ cont , err := text .AskYesNo (out , text .BoldYellow ("Do you want to continue? [y/N]: " ), in )
130
+ text .Break (out )
131
+ if err != nil {
132
+ return err
133
+ }
134
+ if ! cont {
135
+ return fsterr.SkipExitError {
136
+ Skip : true ,
137
+ Err : fsterr .ErrDontContinue ,
138
+ }
139
+ }
140
+ }
141
+
142
+ var serverErr error
143
+ go func () {
144
+ err := c .Globals .AuthServer .Start ()
145
+ if err != nil {
146
+ serverErr = err
147
+ }
148
+ }()
149
+ if serverErr != nil {
150
+ return serverErr
151
+ }
152
+
153
+ text .Info (out , "Starting a local server to handle the authentication flow." )
154
+
145
155
authorizationURL , err := c .Globals .AuthServer .AuthURL ()
146
156
if err != nil {
147
157
return fsterr.RemediationError {
0 commit comments