-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from GSA-TTS/add-user-report
Add cloud.gov user report
- Loading branch information
Showing
10 changed files
with
197 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1 +1 @@ | ||
3.11.9 | ||
3.11.10 |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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,14 @@ | ||
{#- -*- mode:jinja2; coding: utf-8 -*- -#} | ||
|
||
# {{ test.title }} {{ now.strftime('%Y-%m-%d') }} | ||
|
||
The following users have access to our cloud.gov infrastructure. | ||
|
||
{% for section_heading, user_guids in all_successes.items() -%} | ||
## {{ section_heading }} | ||
{% for guid in user_guids: %} | ||
{% set user = test.users[guid] -%} | ||
* **User**: {{ user["user_name"] }}<br /> | ||
**Roles**: {{ user["roles"] | join(', ') }} | ||
{% endfor %} | ||
{% endfor %} |
This file contains 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,81 @@ | ||
from subprocess import check_output | ||
import json | ||
from compliance.config import get_config | ||
from cloudfoundry_client.client import CloudFoundryClient | ||
|
||
client = CloudFoundryClient.build_from_cf_config() | ||
|
||
def retrieve_cf_client(space_name=None): | ||
if space_name is None: | ||
guid = check_output(f"cf org {get_config().get('gov.cloud.org-name')} --guid", shell=True).decode().strip() | ||
else: | ||
guid = check_output(f"cf space {space_name} --guid", shell=True).decode().strip() | ||
return (client, guid) | ||
|
||
|
||
class RoleCollector: | ||
def __init__(self): | ||
self._map = {} | ||
|
||
def add(self, role): | ||
user = role.user | ||
if self._map.get(user.guid) is None: | ||
self._map[user.guid] = {"user": user, "roles": [role]} | ||
else: | ||
self._map[user.guid]["roles"].append(role) | ||
|
||
def to_json(self): | ||
data = [] | ||
for user_roles in self._map.values(): | ||
user = user_roles["user"] | ||
roles = user_roles["roles"] | ||
data.append({ | ||
"user_guid": user.guid, | ||
"user_type": user.type, | ||
"user_name": user.username, | ||
"roles": list((role.description for role in roles)) | ||
}) | ||
return json.dumps(data) | ||
|
||
|
||
class User: | ||
def __init__(self, entity): | ||
self.guid = entity["guid"] | ||
self._username = entity["username"] | ||
self._is_service_account = entity["origin"] != "gsa.gov" | ||
self.type = "Bot" if self._is_service_account else "User" | ||
|
||
@property | ||
def username(self): | ||
if self._is_service_account: | ||
return client.v3.service_credential_bindings.get( | ||
self._username, include="service_instance" | ||
).service_instance()["name"] | ||
else: | ||
return self._username | ||
|
||
|
||
class Space: | ||
def __init__(self, entity): | ||
self.name = entity["name"] | ||
|
||
|
||
class Role: | ||
def __init__(self, entity): | ||
self._fields = entity | ||
self.type = entity["type"] | ||
self.user = User(entity.user()) | ||
|
||
@property | ||
def description(self): | ||
if self.space: | ||
return f"{self.type} in space \"{self.space.name}\"" | ||
else: | ||
return self.type | ||
|
||
@property | ||
def space(self): | ||
try: | ||
return Space(self._fields.space()) | ||
except AttributeError: | ||
return None |
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
auditree-framework @ git+https://github.com/ComplianceAsCode/auditree-framework.git | ||
auditree-arboretum ~= 0.17 | ||
auditree-prune @ git+https://github.com/ComplianceAsCode/auditree-prune.git | ||
auditree-plant @ git+https://github.com/rahearn/auditree-plant.git | ||
auditree-plant @ git+https://github.com/ComplianceAsCode/auditree-plant.git | ||
compliance-to-policy ~= 0.4 | ||
cloudfoundry-client ~= 1.37 |