| 12 | ) |
| 13 | |
| 14 | func OpenCmd(ch *cmdutil.Helper) *cobra.Command { |
| 15 | var branch string |
| 16 | var ttlSeconds uint32 |
| 17 | var userID string |
| 18 | var userEmail string |
| 19 | var userAttributes string |
| 20 | var externalUserID string |
| 21 | var resourceType string |
| 22 | var resource string |
| 23 | var theme string |
| 24 | var themeMode string |
| 25 | var navigation bool |
| 26 | var query map[string]string |
| 27 | var noOpen bool |
| 28 | |
| 29 | openCmd := &cobra.Command{ |
| 30 | Use: "open <org> <project>", |
| 31 | Args: cobra.ExactArgs(2), |
| 32 | Short: "Open an embedded dashboard in the browser", |
| 33 | RunE: func(cmd *cobra.Command, args []string) error { |
| 34 | org := args[0] |
| 35 | project := args[1] |
| 36 | |
| 37 | req := &adminv1.GetIFrameRequest{ |
| 38 | Org: org, |
| 39 | Project: project, |
| 40 | Branch: branch, |
| 41 | TtlSeconds: ttlSeconds, |
| 42 | ExternalUserId: externalUserID, |
| 43 | Type: resourceType, |
| 44 | Resource: resource, |
| 45 | Theme: theme, |
| 46 | ThemeMode: themeMode, |
| 47 | Navigation: navigation, |
| 48 | Query: query, |
| 49 | SuperuserForceAccess: true, |
| 50 | } |
| 51 | |
| 52 | // Set user identity: only one of user_id, user_email, or user_attributes can be specified. |
| 53 | n := 0 |
| 54 | if userID != "" { |
| 55 | n++ |
| 56 | req.For = &adminv1.GetIFrameRequest_UserId{UserId: userID} |
| 57 | } |
| 58 | if userEmail != "" { |
| 59 | n++ |
| 60 | req.For = &adminv1.GetIFrameRequest_UserEmail{UserEmail: userEmail} |
| 61 | } |
| 62 | if userAttributes != "" { |
| 63 | n++ |
| 64 | var attrs map[string]any |
| 65 | if err := json.Unmarshal([]byte(userAttributes), &attrs); err != nil { |
| 66 | return fmt.Errorf("invalid --user-attributes JSON: %w", err) |
| 67 | } |
| 68 | s, err := structpb.NewStruct(attrs) |
| 69 | if err != nil { |
| 70 | return fmt.Errorf("failed to parse --user-attributes: %w", err) |
| 71 | } |