Is there an API call to set the default login environment?

I automate launching a Rancher cluster, launching a stack, and creating a user.
But when the user logs into the Rancher server the first time, she is prompted to switch to an environment or select the environment as the default login environment.
I would like to automate that selection as well so when the user logs in that first time she is put into the environment from the start.
So, I’m hoping there’s an API call to set the default login environment or if not, some programmatic way to do this.

Hi,
can you post an example on how to create a github user via an API call?

thanks in advance,

Charles.

If the question was towards me, I’m afraid I can’t help.
I’m just using local users which I create via the /v1/localauthconfig API call.

thanks for the reply.
Maybe by looking with your localauthconfig API call, i can fix the github one.

can you post it (beware to replace before any sensitive data)?

best regards,

Charles.

The default environment is a userPreference for each account. So after you create the account you should be able to (with an admin credential) POST /v1/userPreferences {"accountId": "<id>", "name": "defaultProjectId", "value": "<projectId>"}.

I’m not sure from the question if you have multiple projects and want to pick a specific one every time, or if they’re logging in and have no projects yet. I’m guessing you’re not adding the users to any projects, but they’re marked admins?

The UI sends you to the “manage environments” screen on login if you are a memboer of no projects. But if you’re an admin, when you get there you can see all the projects whether you’re a member or not. So it sounds like you may just want to add each user as a member of one or more projects after creating them, with setMembers on the Project.

@clescot: Is there a reason you want to pre-create GitHub accounts? They are automatically created when the person logs in if they don’t already have an account. What’s actually stored is the GitHub numeric user_id that you wouldn’t know without talking to the GitHub API. e.g. you’re 910188, not clescot, because you could change your username and then someone else could acquire clescot and log in if we just stored usernames.

hi @vincent,
i think my purpose was not clear.
I want to create a rancher cluster, create one admin user, some environments, and stacks, all stored in a git repository, and populated via ansible.
I can ship via ansible a cluster (server and agents).
But i cannot create in the cluster, a first admin user with a github id (cf Enable github access via API).
If you can provide an example of an API call to create in the rancher cluster an admin user by referencing a github id, or some oauth stuff from github), it will be very useful.

best regards,
Charles.