FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(team): get team will fetch only from selected product by filiptubic · Pull Request #243 · sysdiglabs/sysdig-sdk-python · GitHub

This repository was archived by the owner on May 7, 2026. It is now read-only.
13 changes: 9 additions & 4 deletions sdcclient/_common.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import requests
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.retry import Retry
from urllib3.util.retry import Retry


class SysdigHTTPAdapter(HTTPAdapter):
Expand Down Expand Up @@ -710,12 +710,17 @@ def get_teams(self, team_filter='', product_filter=''):
**Success Return Value**
The teams that match the filter.
'''
res = self.http.get(self.url + '/api/teams', headers=self.hdrs, verify=self.ssl_verify)
url = f'{self.url}/api/teams'
if product_filter:
if product_filter not in ['SDC', 'SDS']:
return [False, 'invalid product header, allowed only "SDC" or "SDS"']
url = f'{url}?product={product_filter}'

res = self.http.get(url, headers=self.hdrs, verify=self.ssl_verify)
if not self._checkResponse(res):
return [False, self.lasterr]
ret = [t for t in res.json()['teams'] if team_filter in t['name']]
if product_filter:
ret = [t for t in ret if product_filter in t['products']]

return [True, ret]

def get_team_by_id(self, id):
Expand Down
72 changes: 72 additions & 0 deletions specs/_common/team_spec.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import os
import uuid
from expects import expect, equal
from mamba import before, description, it
from sdcclient import SdSecureClient, SdMonitorClient
from specs import be_successful_api_call
from collections import defaultdict

TEAM_PREFIX_NAME = 'sysdig-sdk - '

with description("Teams", "integration", "teams") as self:
with before.all:
self.secure_client = SdSecureClient(
sdc_url=os.getenv("SDC_SECURE_URL", "https://secure.sysdig.com"),
Comment thread
luzeno marked this conversation as resolved.
token=os.getenv("SDC_SECURE_TOKEN")
)
self.monitor_client = SdMonitorClient(
sdc_url=os.getenv("SDC_MONITOR_URL", "https://app.sysdigcloud.com"),
token=os.getenv("SDC_MONITOR_TOKEN")
)

with before.each:
self.team_name = f'{TEAM_PREFIX_NAME}{uuid.uuid4()}'

with it("it should list all teams"):
ok, teams_monitor = self.monitor_client.get_teams()
expect((ok, teams_monitor)).to(be_successful_api_call)

ok, teams_secure = self.secure_client.get_teams()
expect((ok, teams_secure)).to(be_successful_api_call)

count_monitor = defaultdict(int)
count_secure = defaultdict(int)

def count_products(teams, count):
for team in teams:
for product in team['products']:
count[product] += 1

count_products(teams_monitor, count_monitor)
count_products(teams_secure, count_secure)

expect(len(count_secure)).to(equal(len(count_monitor)))
for k, v in count_monitor.items():
expect(count_secure[k]).to(equal(v))
expect(len(teams_secure)).to(equal(len(teams_monitor)))

with it("it should list only monitor teams"):
ok, team = self.secure_client.create_team(self.team_name)
expect((ok, team)).to(be_successful_api_call)

ok, teams = self.monitor_client.get_teams(product_filter='SDC')
expect((ok, teams)).to(be_successful_api_call)

secure_teams = [t for t in teams if 'SDS' in t['products']]
expect(len(secure_teams)).to(equal(0))

ok, res = self.secure_client.delete_team(self.team_name)
expect((ok, res)).to(be_successful_api_call)

with it("it should list only secure teams"):
ok, team = self.monitor_client.create_team(self.team_name)
expect((ok, team)).to(be_successful_api_call)

ok, teams = self.secure_client.get_teams(product_filter='SDS')
expect((ok, teams)).to(be_successful_api_call)

monitor_teams = [t for t in teams if 'SDC' in t['products']]
expect(len(monitor_teams)).to(equal(0))

ok, res = self.monitor_client.delete_team(self.team_name)
expect((ok, res)).to(be_successful_api_call)

Back | FazBrowse Home | New Git URL