identifyNewlyAuthenticatedUser re-sends an Identify when the user signed in during the command (e.g. `application create` while logged out): the Identify from PersistentPreRunE went out anonymous, so the identity would otherwise only ship on the next invocation. Runs before the deferred Command Comp
(ctx context.Context, cmd *cobra.Command)
| 263 | // otherwise only ship on the next invocation. Runs before the deferred |
| 264 | // Command Completed so that event carries the user too. |
| 265 | func identifyNewlyAuthenticatedUser(ctx context.Context, cmd *cobra.Command) { |
| 266 | if cmd == nil || !cmdutil.ShouldTrackUsage(cmd) { |
| 267 | return |
| 268 | } |
| 269 | // Same gating as trackCommandCompleted: an empty command path means |
| 270 | // PersistentPreRunE never ran, so no login could have happened either. |
| 271 | metadata := telemetry.GetEventMetadata(ctx) |
| 272 | if metadata == nil || metadata.CommandPath == "" || metadata.UserID != "" { |
| 273 | return |
| 274 | } |
| 275 | token := auth.LoadToken() |
| 276 | if token == nil || token.UserID == "" { |
| 277 | return |
| 278 | } |
| 279 | metadata.SetUser(token.UserID, token.Email, token.Name) |
| 280 | client := telemetry.GetTelemetryClient(ctx) |
| 281 | if client == nil { |
| 282 | return |
| 283 | } |
| 284 | _ = client.Identify(ctx) |
| 285 | } |
| 286 | |
| 287 | // trackCommandCompleted reports how the command ended: success, failure (with |
| 288 | // the class of the error) or user cancellation. |
no test coverage detected