(cli *cli)
| 854 | } |
| 855 | |
| 856 | func importUsersCmd(cli *cli) *cobra.Command { |
| 857 | var inputs struct { |
| 858 | ConnectionName string |
| 859 | ConnectionID string |
| 860 | Template string |
| 861 | UsersBody string |
| 862 | Upsert bool |
| 863 | SendCompletionEmail bool |
| 864 | } |
| 865 | cmd := &cobra.Command{ |
| 866 | Use: "import", |
| 867 | Args: cobra.NoArgs, |
| 868 | Short: "Import users from schema", |
| 869 | Long: `Import users from schema. Issues a Create Import Users Job. |
| 870 | The file size limit for a bulk import is 500KB. You will need to start multiple imports if your data exceeds this size.`, |
| 871 | Example: ` auth0 users import |
| 872 | auth0 users import --connection-name "Username-Password-Authentication" |
| 873 | auth0 users import --connection-name "Username-Password-Authentication" --users "[]" |
| 874 | auth0 users import --connection-name "Username-Password-Authentication" --users "$(cat path/to/users.json)" |
| 875 | cat path/to/users.json | auth0 users import --connection-name "Username-Password-Authentication" |
| 876 | auth0 users import -c "Username-Password-Authentication" --template "Basic Example" |
| 877 | auth0 users import -c "Username-Password-Authentication" --users "$(cat path/to/users.json)" --upsert --email-results |
| 878 | auth0 users import -c "Username-Password-Authentication" --users "$(cat path/to/users.json)" --upsert --email-results --no-input |
| 879 | cat path/to/users.json | auth0 users import -c "Username-Password-Authentication" --upsert --email-results --no-input |
| 880 | auth0 users import -c "Username-Password-Authentication" -u "$(cat path/to/users.json)" --upsert --email-results |
| 881 | cat path/to/users.json | auth0 users import -c "Username-Password-Authentication" --upsert --email-results |
| 882 | auth0 users import -c "Username-Password-Authentication" -t "Basic Example" --upsert --email-results |
| 883 | auth0 users import -c "Username-Password-Authentication" -t "Basic Example" --upsert=false --email-results=false |
| 884 | auth0 users import -c "Username-Password-Authentication" -t "Basic Example" --upsert=false --email-results=false`, |
| 885 | RunE: func(cmd *cobra.Command, args []string) error { |
| 886 | // Users API currently only supports database connections. |
| 887 | dbConnectionOptions, err := cli.databaseAndPasswordlessConnectionOptions(cmd.Context()) |
| 888 | if err != nil { |
| 889 | return err |
| 890 | } |
| 891 | |
| 892 | if err := userConnectionName.Select(cmd, &inputs.ConnectionName, dbConnectionOptions, nil); err != nil { |
| 893 | return err |
| 894 | } |
| 895 | |
| 896 | connection, err := cli.api.Connection.ReadByName(cmd.Context(), inputs.ConnectionName) |
| 897 | if err != nil { |
| 898 | return fmt.Errorf("failed to read connection with name %q: %w", inputs.ConnectionName, err) |
| 899 | } |
| 900 | |
| 901 | inputs.ConnectionID = connection.GetID() |
| 902 | |
| 903 | hasClients, err := connectionHasEnabledClients(cmd.Context(), cli.api.Connection, inputs.ConnectionID) |
| 904 | if err != nil { |
| 905 | return fmt.Errorf("failed to check enabled clients for connection %q: %w", inputs.ConnectionName, err) |
| 906 | } |
| 907 | if !hasClients { |
| 908 | return fmt.Errorf( |
| 909 | "failed to continue due to the connection with name %q being disabled, enable an application on this connection and try again", |
| 910 | inputs.ConnectionName, |
| 911 | ) |
| 912 | } |
| 913 |
no test coverage detected