Skip to content

feat: Add user provisioning without email confirmation #182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions sdcclient/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,35 @@ def download_sysdig_capture(self, capture_id):

return True, res.content

def create_user(self, user_email, first_name=None, last_name=None, password=None):
'''
Provisions a new user to use Sysdig without sending an email notification.
If password is not set through this request a random one is generated for the user
which requires them to reset password on first login.

Args:
user_email (str): Email of the user to provision.
first_name (str): First name of the user to provision. Can be null.
last_name (str): Last name of the user to provision. Can be null.
password (str): Default password for the user to provision. If this is not set, a random one is generated.

Returns:
The provisioned user information.

'''

user_info = {
"username": user_email,
"firstName": first_name,
"lastName": last_name,
"password": password,
}
user_info = {k: v for k, v in user_info.items() if v}

res = self.http.post(self.url + '/api/user/provisioning/', headers=self.hdrs, data=json.dumps(user_info),
verify=self.ssl_verify)
return self._request_result(res)

def create_user_invite(self, user_email, first_name=None, last_name=None, system_role=None):
'''**Description**
Invites a new user to use Sysdig Monitor. This should result in an email notification to the specified address.
Expand Down
45 changes: 45 additions & 0 deletions specs/_common/user_provisioning_spec.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import os
from random import choice
from string import ascii_letters

from expects import expect, contain
from mamba import before, description, after, it, context

from sdcclient import SdcClient
from specs import be_successful_api_call

with description("User Provisioning", "integration") as self:
with before.each:
self.client = SdcClient(sdc_url=os.getenv("SDC_MONITOR_URL", "https://app.sysdigcloud.com"),
token=os.getenv("SDC_MONITOR_TOKEN"))
self.user_name = "[email protected]"

with after.each:
self.client.delete_user(self.user_name)

with it("is able to provision the user with only the username"):
ok, res = self.client.create_user(self.user_name)
expect((ok, res)).to(be_successful_api_call)

with it("is able to provision the user with name and lastname"):
ok, res = self.client.create_user(self.user_name, "Name", "LastName")
expect((ok, res)).to(be_successful_api_call)

with it("is able to provision the user with password"):
random_password = "".join(choice(ascii_letters) for _ in range(20))
ok, res = self.client.create_user(self.user_name, password=random_password)
expect((ok, res)).to(be_successful_api_call)

with it("is able to provision the user with name, lastname and password"):
random_password = "".join(choice(ascii_letters) for _ in range(20))
ok, res = self.client.create_user(self.user_name, "Name", "LastName", random_password)
expect((ok, res)).to(be_successful_api_call)

with context("when the customer already exists"):
with it("returns an error saying it already exists"):
ok, res = self.client.create_user(self.user_name)
expect((ok, res)).to(be_successful_api_call)

ok, res = self.client.create_user(self.user_name)
expect((ok, res)).not_to(be_successful_api_call)
expect(res).to(contain(f"User {self.user_name} already exists"))