Skip to content

Commit d4b77cd

Browse files
authored
feat: Add user provisioning without email confirmation (#182)
* feat: Add user provisioning without email confirmation * lint: Remove unused import
1 parent f2671bb commit d4b77cd

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

sdcclient/_common.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,35 @@ def download_sysdig_capture(self, capture_id):
547547

548548
return True, res.content
549549

550+
def create_user(self, user_email, first_name=None, last_name=None, password=None):
551+
'''
552+
Provisions a new user to use Sysdig without sending an email notification.
553+
If password is not set through this request a random one is generated for the user
554+
which requires them to reset password on first login.
555+
556+
Args:
557+
user_email (str): Email of the user to provision.
558+
first_name (str): First name of the user to provision. Can be null.
559+
last_name (str): Last name of the user to provision. Can be null.
560+
password (str): Default password for the user to provision. If this is not set, a random one is generated.
561+
562+
Returns:
563+
The provisioned user information.
564+
565+
'''
566+
567+
user_info = {
568+
"username": user_email,
569+
"firstName": first_name,
570+
"lastName": last_name,
571+
"password": password,
572+
}
573+
user_info = {k: v for k, v in user_info.items() if v}
574+
575+
res = self.http.post(self.url + '/api/user/provisioning/', headers=self.hdrs, data=json.dumps(user_info),
576+
verify=self.ssl_verify)
577+
return self._request_result(res)
578+
550579
def create_user_invite(self, user_email, first_name=None, last_name=None, system_role=None):
551580
'''**Description**
552581
Invites a new user to use Sysdig Monitor. This should result in an email notification to the specified address.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import os
2+
from random import choice
3+
from string import ascii_letters
4+
5+
from expects import expect, contain
6+
from mamba import before, description, after, it, context
7+
8+
from sdcclient import SdcClient
9+
from specs import be_successful_api_call
10+
11+
with description("User Provisioning", "integration") as self:
12+
with before.each:
13+
self.client = SdcClient(sdc_url=os.getenv("SDC_MONITOR_URL", "https://app.sysdigcloud.com"),
14+
token=os.getenv("SDC_MONITOR_TOKEN"))
15+
self.user_name = "[email protected]"
16+
17+
with after.each:
18+
self.client.delete_user(self.user_name)
19+
20+
with it("is able to provision the user with only the username"):
21+
ok, res = self.client.create_user(self.user_name)
22+
expect((ok, res)).to(be_successful_api_call)
23+
24+
with it("is able to provision the user with name and lastname"):
25+
ok, res = self.client.create_user(self.user_name, "Name", "LastName")
26+
expect((ok, res)).to(be_successful_api_call)
27+
28+
with it("is able to provision the user with password"):
29+
random_password = "".join(choice(ascii_letters) for _ in range(20))
30+
ok, res = self.client.create_user(self.user_name, password=random_password)
31+
expect((ok, res)).to(be_successful_api_call)
32+
33+
with it("is able to provision the user with name, lastname and password"):
34+
random_password = "".join(choice(ascii_letters) for _ in range(20))
35+
ok, res = self.client.create_user(self.user_name, "Name", "LastName", random_password)
36+
expect((ok, res)).to(be_successful_api_call)
37+
38+
with context("when the customer already exists"):
39+
with it("returns an error saying it already exists"):
40+
ok, res = self.client.create_user(self.user_name)
41+
expect((ok, res)).to(be_successful_api_call)
42+
43+
ok, res = self.client.create_user(self.user_name)
44+
expect((ok, res)).not_to(be_successful_api_call)
45+
expect(res).to(contain(f"User {self.user_name} already exists"))

0 commit comments

Comments
 (0)