day2 0.2.7__tar.gz → 0.2.8__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. {day2-0.2.7 → day2-0.2.8}/PKG-INFO +1 -1
  2. {day2-0.2.7 → day2-0.2.8}/day2/models/__init__.py +18 -0
  3. day2-0.2.8/day2/models/azure_assessment.py +142 -0
  4. day2-0.2.8/day2/resources/azure_assessment.py +207 -0
  5. {day2-0.2.7 → day2-0.2.8}/day2/session.py +12 -0
  6. {day2-0.2.7 → day2-0.2.8}/day2.egg-info/PKG-INFO +1 -1
  7. {day2-0.2.7 → day2-0.2.8}/day2.egg-info/SOURCES.txt +4 -0
  8. {day2-0.2.7 → day2-0.2.8}/day2_cli/cli.py +2 -0
  9. day2-0.2.8/day2_cli/commands/azure_assessment.py +377 -0
  10. day2-0.2.8/day2_cli/utils/helpers.py +44 -0
  11. {day2-0.2.7 → day2-0.2.8}/pyproject.toml +1 -1
  12. {day2-0.2.7 → day2-0.2.8}/LICENSE +0 -0
  13. {day2-0.2.7 → day2-0.2.8}/README.md +0 -0
  14. {day2-0.2.7 → day2-0.2.8}/day2/__init__.py +0 -0
  15. {day2-0.2.7 → day2-0.2.8}/day2/_version.py +0 -0
  16. {day2-0.2.7 → day2-0.2.8}/day2/auth/__init__.py +0 -0
  17. {day2-0.2.7 → day2-0.2.8}/day2/auth/credentials.py +0 -0
  18. {day2-0.2.7 → day2-0.2.8}/day2/client/__init__.py +0 -0
  19. {day2-0.2.7 → day2-0.2.8}/day2/client/base.py +0 -0
  20. {day2-0.2.7 → day2-0.2.8}/day2/client/config.py +0 -0
  21. {day2-0.2.7 → day2-0.2.8}/day2/client/constants.py +0 -0
  22. {day2-0.2.7 → day2-0.2.8}/day2/client/profile.py +0 -0
  23. {day2-0.2.7 → day2-0.2.8}/day2/client/user_context.py +0 -0
  24. {day2-0.2.7 → day2-0.2.8}/day2/exceptions.py +0 -0
  25. {day2-0.2.7 → day2-0.2.8}/day2/models/assessment.py +0 -0
  26. {day2-0.2.7 → day2-0.2.8}/day2/models/bot.py +0 -0
  27. {day2-0.2.7 → day2-0.2.8}/day2/models/cost.py +0 -0
  28. {day2-0.2.7 → day2-0.2.8}/day2/models/report.py +0 -0
  29. {day2-0.2.7 → day2-0.2.8}/day2/models/resource.py +0 -0
  30. {day2-0.2.7 → day2-0.2.8}/day2/models/tenant.py +0 -0
  31. {day2-0.2.7 → day2-0.2.8}/day2/resources/__init__.py +0 -0
  32. {day2-0.2.7 → day2-0.2.8}/day2/resources/assessment.py +0 -0
  33. {day2-0.2.7 → day2-0.2.8}/day2/resources/bot.py +0 -0
  34. {day2-0.2.7 → day2-0.2.8}/day2/resources/cost.py +0 -0
  35. {day2-0.2.7 → day2-0.2.8}/day2/resources/report.py +0 -0
  36. {day2-0.2.7 → day2-0.2.8}/day2/resources/resource.py +0 -0
  37. {day2-0.2.7 → day2-0.2.8}/day2/resources/tenant.py +0 -0
  38. {day2-0.2.7 → day2-0.2.8}/day2/resources/user.py +0 -0
  39. {day2-0.2.7 → day2-0.2.8}/day2/utils/__init__.py +0 -0
  40. {day2-0.2.7 → day2-0.2.8}/day2/utils/helpers.py +0 -0
  41. {day2-0.2.7 → day2-0.2.8}/day2.egg-info/dependency_links.txt +0 -0
  42. {day2-0.2.7 → day2-0.2.8}/day2.egg-info/entry_points.txt +0 -0
  43. {day2-0.2.7 → day2-0.2.8}/day2.egg-info/requires.txt +0 -0
  44. {day2-0.2.7 → day2-0.2.8}/day2.egg-info/top_level.txt +0 -0
  45. {day2-0.2.7 → day2-0.2.8}/day2_cli/__init__.py +0 -0
  46. {day2-0.2.7 → day2-0.2.8}/day2_cli/commands/__init__.py +0 -0
  47. {day2-0.2.7 → day2-0.2.8}/day2_cli/commands/assessment.py +0 -0
  48. {day2-0.2.7 → day2-0.2.8}/day2_cli/commands/auth.py +0 -0
  49. {day2-0.2.7 → day2-0.2.8}/day2_cli/commands/bot.py +0 -0
  50. {day2-0.2.7 → day2-0.2.8}/day2_cli/commands/cost.py +0 -0
  51. {day2-0.2.7 → day2-0.2.8}/day2_cli/commands/profile.py +0 -0
  52. {day2-0.2.7 → day2-0.2.8}/day2_cli/commands/report.py +0 -0
  53. {day2-0.2.7 → day2-0.2.8}/day2_cli/commands/resource.py +0 -0
  54. {day2-0.2.7 → day2-0.2.8}/day2_cli/commands/tenant.py +0 -0
  55. {day2-0.2.7 → day2-0.2.8}/day2_cli/utils/__init__.py +0 -0
  56. {day2-0.2.7 → day2-0.2.8}/day2_cli/utils/context.py +0 -0
  57. {day2-0.2.7 → day2-0.2.8}/day2_cli/utils/exit_codes.py +0 -0
  58. {day2-0.2.7 → day2-0.2.8}/day2_cli/utils/formatters.py +0 -0
  59. {day2-0.2.7 → day2-0.2.8}/day2_cli/utils/output_formatter.py +0 -0
  60. {day2-0.2.7 → day2-0.2.8}/setup.cfg +0 -0
  61. {day2-0.2.7 → day2-0.2.8}/tests/test_exceptions.py +0 -0
  62. {day2-0.2.7 → day2-0.2.8}/tests/test_rate_limiting.py +0 -0
  63. {day2-0.2.7 → day2-0.2.8}/tests/test_rate_limiting_retry.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: day2
3
- Version: 0.2.7
3
+ Version: 0.2.8
4
4
  Summary: MontyCloud DAY2 SDK for Python
5
5
  Author-email: MontyCloud <info@montycloud.com>
6
6
  Requires-Python: >=3.11
@@ -11,6 +11,18 @@ from day2.models.assessment import (
11
11
  RunAssessmentInput,
12
12
  RunAssessmentOutput,
13
13
  )
14
+ from day2.models.azure_assessment import Assessment as AzureAssessment
15
+ from day2.models.azure_assessment import (
16
+ CreateAssessmentInput as AzureCreateAssessmentInput,
17
+ )
18
+ from day2.models.azure_assessment import (
19
+ CreateAssessmentOutput as AzureCreateAssessmentOutput,
20
+ )
21
+ from day2.models.azure_assessment import Finding as AzureFinding
22
+ from day2.models.azure_assessment import (
23
+ ListAssessmentsOutput as AzureListAssessmentsOutput,
24
+ )
25
+ from day2.models.azure_assessment import ListFindingsOutput as AzureListFindingsOutput
14
26
  from day2.models.bot import (
15
27
  ComplianceBotFinding,
16
28
  ListComplianceBotFindingsOutput,
@@ -41,9 +53,15 @@ __all__ = [
41
53
  "TenantDetails",
42
54
  "ListTenantsOutput",
43
55
  "Assessment",
56
+ "AzureAssessment",
57
+ "AzureFinding",
44
58
  "ListAssessmentsOutput",
59
+ "AzureListAssessmentsOutput",
60
+ "AzureListFindingsOutput",
45
61
  "CreateAssessmentInput",
46
62
  "CreateAssessmentOutput",
63
+ "AzureCreateAssessmentInput",
64
+ "AzureCreateAssessmentOutput",
47
65
  "GetAssessmentOutput",
48
66
  "GetCostByChargeTypeOutput",
49
67
  "RunAssessmentInput",
@@ -0,0 +1,142 @@
1
+ """Azure Assessment Models for MontyCloud DAY2 SDK."""
2
+
3
+ from datetime import datetime
4
+ from typing import Any, Dict, List, Optional
5
+
6
+ from pydantic import BaseModel, ConfigDict, Field
7
+
8
+
9
+ class Assessment(BaseModel):
10
+ """Details of an Azure assessment.
11
+
12
+ Attributes:
13
+ id: Assessment identifier
14
+ name: Name of the assessment
15
+ description: Description of the assessment
16
+ scope: Scope of the assessment containing subscription and resource group information
17
+ review_owner: Review owner of the assessment
18
+ created_at: Timestamp when the assessment was created
19
+ last_run_at: Timestamp when the assessment was last run (if completed)
20
+ """
21
+
22
+ id: str = Field(alias="AssessmentId")
23
+ name: str = Field(alias="AssessmentName")
24
+ description: str = Field(alias="Description")
25
+ scope: Optional[Dict[str, Any]] = Field(None, alias="Scope")
26
+ review_owner: Optional[str] = Field(None, alias="ReviewOwner")
27
+ created_at: Optional[datetime] = Field(None, alias="CreatedAt")
28
+ last_run_at: Optional[datetime] = Field(None, alias="LastRunAt")
29
+
30
+ # Allow extra fields and population by name (Python field names)
31
+ model_config = ConfigDict(extra="allow", populate_by_name=True)
32
+
33
+
34
+ class ListAssessmentsOutput(BaseModel):
35
+ """Output of list Azure assessments operation.
36
+
37
+ Attributes:
38
+ assessments: List of Azure assessment details
39
+ page_number: Current page number
40
+ has_more: Whether there are more pages available
41
+ """
42
+
43
+ assessments: List[Assessment] = Field(alias="Assessments")
44
+ page_number: Optional[int] = Field(None, alias="PageNumber")
45
+ has_more: Optional[bool] = Field(None, alias="HasMore")
46
+
47
+ # Allow extra fields and population by name (Python field names)
48
+ model_config = ConfigDict(extra="allow", populate_by_name=True)
49
+
50
+
51
+ class CreateAssessmentInput(BaseModel):
52
+ """Input for creating an Azure assessment.
53
+
54
+ Attributes:
55
+ name: Name of the Azure assessment
56
+ description: Description of the assessment
57
+ scope: Array of scope objects containing subscription and resource group information
58
+ review_owner: Review owner of the assessment
59
+ environment: Environment type (e.g., PRODUCTION, DEVELOPMENT)
60
+ industry_type: Type of industry
61
+ industry: Industry category
62
+ diagram_url: URL to the architecture diagram
63
+ """
64
+
65
+ name: str = Field(alias="AssessmentName")
66
+ description: str = Field(alias="Description")
67
+ scope: List[Dict[str, Any]] = Field(alias="Scope")
68
+ review_owner: str = Field(alias="ReviewOwner")
69
+ environment: str = Field(alias="Environment")
70
+ industry_type: Optional[str] = Field(None, alias="IndustryType")
71
+ industry: Optional[str] = Field(None, alias="Industry")
72
+ diagram_url: Optional[str] = Field(None, alias="DiagramURL")
73
+
74
+ # Allow extra fields and population by name (Python field names)
75
+ model_config = ConfigDict(extra="allow", populate_by_name=True)
76
+
77
+
78
+ class CreateAssessmentOutput(BaseModel):
79
+ """Output of create Azure assessment operation.
80
+
81
+ Attributes:
82
+ id: Newly created Azure assessment identifier
83
+ """
84
+
85
+ id: str = Field(alias="AssessmentId")
86
+
87
+ # Allow extra fields and population by name (Python field names)
88
+ model_config = ConfigDict(extra="allow", populate_by_name=True)
89
+
90
+
91
+ class Finding(BaseModel):
92
+ """Details of an Azure finding.
93
+
94
+ Attributes:
95
+ resource_id: ID of the affected resource
96
+ resource_name: Name of the affected resource
97
+ resource_type: Type of the affected resource
98
+ resource_group: Resource group where the resource exists
99
+ severity: Severity level (e.g., High, Medium, Low)
100
+ description: Detailed description of the finding
101
+ status: Current status of the finding (e.g., Failed, Passed)
102
+ category: Category of the finding (e.g., Security, Governance)
103
+ subscription_id: Azure subscription ID where the resource exists
104
+ check_title: Title of the check that generated this finding
105
+ additional_information: Additional information about the finding
106
+ recommended_actions: Recommended actions to address the finding
107
+ created_at: Timestamp when the finding was created
108
+ updated_at: Timestamp when the finding was last updated
109
+ """
110
+
111
+ resource_id: Optional[str] = Field(None, alias="ResourceId")
112
+ resource_name: Optional[str] = Field(None, alias="ResourceName")
113
+ resource_type: Optional[str] = Field(None, alias="ResourceType")
114
+ resource_group: Optional[str] = Field(None, alias="ResourceGroup")
115
+ severity: Optional[str] = Field(None, alias="Severity")
116
+ description: Optional[str] = Field(None, alias="Description")
117
+ status: Optional[str] = Field(None, alias="Status")
118
+ category: Optional[str] = Field(None, alias="Category")
119
+ subscription_id: Optional[str] = Field(None, alias="SubscriptionId")
120
+ check_title: Optional[str] = Field(None, alias="CheckTitle")
121
+ additional_information: Optional[dict] = Field(None, alias="AdditionalInformation")
122
+ recommended_actions: Optional[str] = Field(None, alias="RecommendedActions")
123
+ created_at: Optional[datetime] = Field(None, alias="CreatedAt")
124
+ updated_at: Optional[datetime] = Field(None, alias="UpdatedAt")
125
+
126
+ # Allow extra fields
127
+ model_config = ConfigDict(extra="allow")
128
+
129
+
130
+ class ListFindingsOutput(BaseModel):
131
+ """Output of list Azure findings operation.
132
+
133
+ Attributes:
134
+ records: List of Azure finding details
135
+ next_page_token: Token for next page pagination
136
+ """
137
+
138
+ records: List[Finding] = Field(alias="Findings", default=[])
139
+ next_page_token: Optional[str] = Field(None, alias="PageToken")
140
+
141
+ # Allow extra fields
142
+ model_config = ConfigDict(extra="allow")
@@ -0,0 +1,207 @@
1
+ """Azure Assessment resource implementation for the MontyCloud DAY2 SDK."""
2
+
3
+ from typing import Any, Dict, List, Optional, Union
4
+
5
+ from day2.client.base import BaseClient
6
+ from day2.models.azure_assessment import (
7
+ CreateAssessmentInput,
8
+ CreateAssessmentOutput,
9
+ ListAssessmentsOutput,
10
+ ListFindingsOutput,
11
+ )
12
+ from day2.session import Session
13
+
14
+
15
+ class AzureAssessmentClient(BaseClient):
16
+ """Client for interacting with Azure Assessment service."""
17
+
18
+ def __init__(self, session: Session) -> None:
19
+ """Initialize a new AzureAssessmentClient.
20
+
21
+ Args:
22
+ session: MontyCloud session.
23
+ """
24
+ super().__init__(session, "azure_assessment")
25
+
26
+ def list_assessments(
27
+ self,
28
+ tenant_id: str,
29
+ keyword: Optional[str] = None,
30
+ page_size: int = 10,
31
+ page_number: Optional[int] = None,
32
+ ) -> ListAssessmentsOutput:
33
+ """List Azure assessments in a tenant.
34
+
35
+ Args:
36
+ tenant_id: The ID of the tenant to list assessments for.
37
+ keyword: Optional keyword to filter assessments by name or description.
38
+ page_size: The number of assessments per page (default: 10, valid range: 1-100).
39
+ page_number: Page number for pagination.
40
+
41
+ Returns:
42
+ ListAssessmentsOutput: Object containing list of Azure assessments and pagination info.
43
+
44
+ Raises:
45
+ ClientError: If the request is invalid.
46
+ ServerError: If an internal server error occurs.
47
+ AuthenticationError: If authentication fails.
48
+
49
+ Examples:
50
+ >>> session = Session(api_key="your-api-key", api_secret_key="your-secret-key")
51
+ >>> client = session.azure_assessment
52
+ >>> response = client.list_assessments("tenant-123")
53
+ >>> for assessment in response.assessments:
54
+ ... print(f"{assessment.name}: {assessment.description}")
55
+ """
56
+ params = {}
57
+ if keyword:
58
+ params["Keyword"] = keyword
59
+ if page_size:
60
+ params["PageSize"] = str(page_size)
61
+ if page_number:
62
+ params["PageNumber"] = str(page_number)
63
+
64
+ endpoint = f"tenants/{tenant_id}/azure/azure-wafr/assessments"
65
+ response = self._make_request("GET", endpoint, params=params)
66
+ return ListAssessmentsOutput.model_validate(response)
67
+
68
+ def create_assessment(
69
+ self, tenant_id: str, data: CreateAssessmentInput
70
+ ) -> CreateAssessmentOutput:
71
+ """Create a new Azure assessment in a tenant.
72
+
73
+ Args:
74
+ tenant_id: The ID of the tenant to create the assessment in.
75
+ data: The Azure assessment data to create.
76
+
77
+ Returns:
78
+ CreateAssessmentOutput: Object containing the created assessment details.
79
+
80
+ Raises:
81
+ ClientError: If the request is invalid.
82
+ ServerError: If an internal server error occurs.
83
+ AuthenticationError: If authentication fails.
84
+
85
+ Examples:
86
+ >>> session = Session(api_key="your-api-key", api_secret_key="your-secret-key")
87
+ >>> client = session.azure_assessment
88
+ >>> data = CreateAssessmentInput(
89
+ ... name="Azure Assessment",
90
+ ... description="Azure assessment description",
91
+ ... scope=[{"SubscriptionId": "subscription-id", "ResourceGroups": ["rg-1", "rg-2"]}],
92
+ ... review_owner="Azure Team",
93
+ ... environment="PRODUCTION",
94
+ ... industry_type="Software",
95
+ ... industry="Technology",
96
+ ... diagram_url="https://example.com/architecture-diagram"
97
+ ... )
98
+ >>> response = client.create_assessment("tenant-123", data)
99
+ >>> print(f"Created Azure assessment with ID: {response.id}")
100
+ """
101
+ # Create the payload for Azure assessment
102
+ azure_payload: Dict[str, Any] = {
103
+ "AssessmentName": data.name,
104
+ "Description": data.description,
105
+ "Scope": data.scope,
106
+ "ReviewOwner": data.review_owner,
107
+ "Environment": data.environment,
108
+ }
109
+
110
+ # Add optional fields if provided
111
+ if data.industry_type:
112
+ azure_payload["IndustryType"] = data.industry_type
113
+ if data.industry:
114
+ azure_payload["Industry"] = data.industry
115
+ if data.diagram_url:
116
+ azure_payload["DiagramURL"] = data.diagram_url
117
+
118
+ response = self._make_request(
119
+ "POST",
120
+ f"tenants/{tenant_id}/azure/azure-wafr/assessments",
121
+ json=azure_payload,
122
+ )
123
+ return CreateAssessmentOutput.model_validate(response)
124
+
125
+ def list_findings(
126
+ self,
127
+ tenant_id: str,
128
+ assessment_id: str,
129
+ page_size: int = 10,
130
+ page_token: Optional[str] = None,
131
+ severity: Optional[List[str]] = None,
132
+ status: Optional[List[str]] = None,
133
+ resource_type: Optional[List[str]] = None,
134
+ resource_id: Optional[str] = None,
135
+ resource_group: Optional[List[str]] = None,
136
+ subscription_id: Optional[List[str]] = None,
137
+ category: Optional[List[str]] = None,
138
+ check_title: Optional[str] = None,
139
+ ) -> ListFindingsOutput:
140
+ """List findings for a specific Azure assessment in a tenant.
141
+
142
+ Args:
143
+ tenant_id: ID of the tenant the assessment belongs to.
144
+ assessment_id: ID of the assessment to list findings for.
145
+ page_size: The number of findings per page (default: 10, valid range: 1-100).
146
+ page_token: Token for pagination.
147
+ severity: Optional list of severities to filter findings by ('High', 'Medium', 'Low').
148
+ status: Optional list of statuses to filter findings by ('Failed', 'Passed').
149
+ resource_type: Optional list of resource types to filter findings by.
150
+ resource_id: Optional resource ID to filter findings by (single value).
151
+ resource_group: Optional list of resource groups to filter findings by.
152
+ subscription_id: Optional list of subscription IDs to filter findings by.
153
+ category: Optional list of categories to filter findings by.
154
+ check_title: Optional check title to filter findings by.
155
+
156
+ Returns:
157
+ ListFindingsOutput: Object containing list of Azure findings and pagination info.
158
+
159
+ Raises:
160
+ ResourceNotFoundError: If the assessment does not exist.
161
+ ClientError: If the request is invalid.
162
+ ServerError: If an internal server error occurs.
163
+ AuthenticationError: If authentication fails.
164
+
165
+ Examples:
166
+ >>> session = Session(api_key="your-api-key", api_secret_key="your-secret-key")
167
+ >>> client = session.azure_assessment
168
+ >>> response = client.list_findings(
169
+ ... tenant_id="tenant-123",
170
+ ... assessment_id="assessment-123",
171
+ ... resource_group=["vm-test-01_group"],
172
+ ... page_size=10
173
+ ... )
174
+ >>> for finding in response.records:
175
+ ... print(f"{finding.resource_id}: {finding.check_title}")
176
+ """
177
+ params: Dict[str, Union[str, List[str]]] = {}
178
+
179
+ # Add Azure parameters
180
+ if resource_id is not None:
181
+ params["ResourceId"] = resource_id
182
+ if check_title is not None:
183
+ params["CheckTitle"] = check_title
184
+ if page_size is not None:
185
+ params["PageSize"] = str(page_size)
186
+ if page_token is not None:
187
+ params["PageToken"] = page_token
188
+
189
+ # Add list parameters for Azure
190
+ azure_list_params = [
191
+ ("ResourceType", resource_type),
192
+ ("ResourceGroup", resource_group),
193
+ ("Severity", severity),
194
+ ("Category", category),
195
+ ("SubscriptionId", subscription_id),
196
+ ("Status", status),
197
+ ]
198
+
199
+ for param_name, param_value in azure_list_params:
200
+ if param_value is not None and param_value:
201
+ params[param_name] = param_value
202
+
203
+ endpoint = (
204
+ f"tenants/{tenant_id}/azure/azure-wafr/assessments/{assessment_id}/findings"
205
+ )
206
+ response = self._make_request("GET", endpoint, params=params)
207
+ return ListFindingsOutput.model_validate(response)
@@ -12,6 +12,7 @@ from day2.client.user_context import get_user_context
12
12
 
13
13
  if TYPE_CHECKING:
14
14
  from day2.resources.assessment import AssessmentClient
15
+ from day2.resources.azure_assessment import AzureAssessmentClient
15
16
  from day2.resources.bot import BotClient
16
17
  from day2.resources.cost import CostClient
17
18
  from day2.resources.report import ReportClient
@@ -302,6 +303,15 @@ class Session:
302
303
  """
303
304
  return cast("ResourceClient", self.client("resource"))
304
305
 
306
+ @property
307
+ def azure_assessment(self) -> "AzureAssessmentClient":
308
+ """Get the Azure assessment client.
309
+
310
+ Returns:
311
+ AzureAssessmentClient: The Azure assessment client.
312
+ """
313
+ return cast("AzureAssessmentClient", self.client("azure_assessment"))
314
+
305
315
  @property
306
316
  def config(self) -> Config:
307
317
  """Get the session configuration.
@@ -325,6 +335,7 @@ class Session:
325
335
  """
326
336
  # Import the actual classes at runtime to avoid circular imports
327
337
  from day2.resources.assessment import AssessmentClient
338
+ from day2.resources.azure_assessment import AzureAssessmentClient
328
339
  from day2.resources.bot import BotClient
329
340
  from day2.resources.cost import CostClient
330
341
  from day2.resources.report import ReportClient
@@ -340,6 +351,7 @@ class Session:
340
351
  "report": ReportClient,
341
352
  "bot": BotClient,
342
353
  "resource": ResourceClient,
354
+ "azure_assessment": AzureAssessmentClient,
343
355
  }
344
356
 
345
357
  if service_name not in service_map:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: day2
3
- Version: 0.2.7
3
+ Version: 0.2.8
4
4
  Summary: MontyCloud DAY2 SDK for Python
5
5
  Author-email: MontyCloud <info@montycloud.com>
6
6
  Requires-Python: >=3.11
@@ -21,6 +21,7 @@ day2/client/profile.py
21
21
  day2/client/user_context.py
22
22
  day2/models/__init__.py
23
23
  day2/models/assessment.py
24
+ day2/models/azure_assessment.py
24
25
  day2/models/bot.py
25
26
  day2/models/cost.py
26
27
  day2/models/report.py
@@ -28,6 +29,7 @@ day2/models/resource.py
28
29
  day2/models/tenant.py
29
30
  day2/resources/__init__.py
30
31
  day2/resources/assessment.py
32
+ day2/resources/azure_assessment.py
31
33
  day2/resources/bot.py
32
34
  day2/resources/cost.py
33
35
  day2/resources/report.py
@@ -41,6 +43,7 @@ day2_cli/cli.py
41
43
  day2_cli/commands/__init__.py
42
44
  day2_cli/commands/assessment.py
43
45
  day2_cli/commands/auth.py
46
+ day2_cli/commands/azure_assessment.py
44
47
  day2_cli/commands/bot.py
45
48
  day2_cli/commands/cost.py
46
49
  day2_cli/commands/profile.py
@@ -51,6 +54,7 @@ day2_cli/utils/__init__.py
51
54
  day2_cli/utils/context.py
52
55
  day2_cli/utils/exit_codes.py
53
56
  day2_cli/utils/formatters.py
57
+ day2_cli/utils/helpers.py
54
58
  day2_cli/utils/output_formatter.py
55
59
  tests/test_exceptions.py
56
60
  tests/test_rate_limiting.py
@@ -13,6 +13,7 @@ from day2_cli.commands.assessment import assessment
13
13
  # Import from day2 package
14
14
  # Import from day2_cli package
15
15
  from day2_cli.commands.auth import auth
16
+ from day2_cli.commands.azure_assessment import azure_assessment
16
17
  from day2_cli.commands.bot import bot
17
18
  from day2_cli.commands.cost import cost
18
19
  from day2_cli.commands.profile import profile
@@ -38,6 +39,7 @@ cli.add_command(auth)
38
39
  cli.add_command(profile)
39
40
  cli.add_command(tenant)
40
41
  cli.add_command(assessment)
42
+ cli.add_command(azure_assessment)
41
43
  cli.add_command(cost)
42
44
  cli.add_command(resource)
43
45
  cli.add_command(report)
@@ -0,0 +1,377 @@
1
+ """Azure Assessment commands for the MontyCloud DAY2 CLI."""
2
+
3
+ import json
4
+ from typing import Optional, Tuple
5
+
6
+ import click
7
+ from rich.console import Console
8
+
9
+ from day2.exceptions import Day2Error, ProfileNotFoundError
10
+ from day2.models.azure_assessment import CreateAssessmentInput
11
+ from day2_cli.utils.context import get_enhanced_context, with_common_options
12
+ from day2_cli.utils.exit_codes import ExitCodes, exit_with_error, handle_error_with_exit
13
+ from day2_cli.utils.helpers import format_datetime_string
14
+ from day2_cli.utils.output_formatter import (
15
+ format_item_output,
16
+ format_list_output,
17
+ format_simple_output,
18
+ )
19
+
20
+ console = Console()
21
+
22
+
23
+ @click.group(name="azure-assessment")
24
+ def azure_assessment() -> None:
25
+ """Azure assessment commands."""
26
+
27
+
28
+ @azure_assessment.command("list")
29
+ @click.option("--keyword", help="Filter by keyword")
30
+ @click.option("--page-number", type=int, help="Page number for pagination")
31
+ @click.option(
32
+ "--page-size", type=int, default=10, help="Page size (valid range: 1-100)"
33
+ )
34
+ @with_common_options(include_tenant_id=True)
35
+ def list_azure_assessments(
36
+ keyword: Optional[str],
37
+ page_number: Optional[int],
38
+ page_size: int,
39
+ output: Optional[str] = None,
40
+ profile: Optional[str] = None,
41
+ tenant_id: Optional[str] = None,
42
+ ) -> None:
43
+ """List Azure assessments for a tenant.
44
+
45
+ If --tenant-id is not provided, uses the default tenant configured with 'day2 profile create' or 'day2 auth login'.
46
+ """
47
+ try:
48
+ # Get enhanced context with tenant resolution
49
+ context = get_enhanced_context(
50
+ output=output, profile=profile, tenant_id=tenant_id, require_tenant=True
51
+ )
52
+ session = context["session"]
53
+ output_format = context["output_format"]
54
+ resolved_tenant_id = context["tenant_id"]
55
+
56
+ # Call the client method with explicit parameters for Azure assessments
57
+ result = session.azure_assessment.list_assessments(
58
+ tenant_id=resolved_tenant_id,
59
+ keyword=keyword,
60
+ page_number=page_number,
61
+ page_size=page_size,
62
+ )
63
+
64
+ if not result.assessments:
65
+ format_simple_output(
66
+ "No Azure assessments found.", format_override=output_format
67
+ )
68
+ return
69
+
70
+ # Convert assessment objects to dictionaries for the formatter
71
+ assessments_data = []
72
+ for assessment_item in result.assessments:
73
+ created_at = format_datetime_string(assessment_item.created_at)
74
+ last_run_at = format_datetime_string(assessment_item.last_run_at)
75
+
76
+ # Include Azure-specific fields
77
+ assessments_data.append(
78
+ {
79
+ "id": assessment_item.id,
80
+ "name": assessment_item.name,
81
+ "description": assessment_item.description or "N/A",
82
+ "scope": assessment_item.scope,
83
+ "review_owner": getattr(assessment_item, "review_owner", "N/A"),
84
+ "created_at": created_at,
85
+ "last_run_at": last_run_at,
86
+ }
87
+ )
88
+
89
+ # Define column mapping for the formatter
90
+ columns = {
91
+ "id": "Assessment ID",
92
+ "name": "Name",
93
+ "description": "Description",
94
+ "review_owner": "Review Owner",
95
+ "created_at": "Created At",
96
+ "last_run_at": "Last Run At",
97
+ }
98
+
99
+ # Format and output the results
100
+ format_list_output(
101
+ items=assessments_data,
102
+ title=f"Azure Assessments for Tenant: {resolved_tenant_id}",
103
+ columns=columns,
104
+ format_override=output_format,
105
+ )
106
+
107
+ # Display pagination information for Azure
108
+ if hasattr(result, "has_more") and result.has_more:
109
+ next_page = (page_number or 1) + 1
110
+ format_simple_output(
111
+ f"More results available. Use --page-number={next_page} to get the next page.",
112
+ format_override=output_format,
113
+ )
114
+
115
+ except (Day2Error, ProfileNotFoundError) as e:
116
+ handle_error_with_exit(e)
117
+
118
+
119
+ @azure_assessment.command("create")
120
+ @click.option("--name", required=True, help="Name of the Azure assessment")
121
+ @click.option("--description", help="Description of the Azure assessment")
122
+ @click.option("--review-owner", help="Review owner of the assessment")
123
+ @click.option(
124
+ "--scope",
125
+ required=True,
126
+ help='Scope of the Azure assessment as JSON string. Format: [{"SubscriptionId": "11111111-1111-1111-1111-111111111111", "ResourceGroups": ["rg-web", "rg-database"]}]',
127
+ )
128
+ @click.option(
129
+ "--environment", default="PRODUCTION", help="Environment (default: PRODUCTION)"
130
+ )
131
+ @click.option("--industry-type", help="Industry type (e.g., Technology)")
132
+ @click.option("--industry", help="Industry (e.g., Software)")
133
+ @click.option("--diagram-url", help="URL to the architecture diagram")
134
+ @with_common_options(include_tenant_id=True)
135
+ def create_azure_assessment(
136
+ name: str,
137
+ description: Optional[str],
138
+ review_owner: Optional[str],
139
+ scope: str,
140
+ environment: str,
141
+ industry_type: Optional[str],
142
+ industry: Optional[str],
143
+ diagram_url: Optional[str],
144
+ output: Optional[str] = None,
145
+ profile: Optional[str] = None,
146
+ tenant_id: Optional[str] = None,
147
+ ) -> None:
148
+ """Create a new Azure assessment.
149
+
150
+ If --tenant-id is not provided, uses the default tenant configured with 'day2 profile create' or 'day2 auth login'.
151
+ """
152
+ try:
153
+ # Validate required inputs first before creating session
154
+ if not scope:
155
+ exit_with_error(
156
+ "Scope is required for Azure assessments",
157
+ ExitCodes.VALIDATION_ERROR,
158
+ )
159
+
160
+ try:
161
+ scope_data = json.loads(scope)
162
+ if not isinstance(scope_data, list):
163
+ exit_with_error(
164
+ "Azure scope must be a JSON array of subscription objects",
165
+ ExitCodes.VALIDATION_ERROR,
166
+ )
167
+ except json.JSONDecodeError:
168
+ exit_with_error(
169
+ "Scope must be a valid JSON string for Azure",
170
+ ExitCodes.VALIDATION_ERROR,
171
+ )
172
+
173
+ # Get enhanced context with tenant resolution
174
+ context = get_enhanced_context(
175
+ output=output, profile=profile, tenant_id=tenant_id, require_tenant=True
176
+ )
177
+ session = context["session"]
178
+ output_format = context["output_format"]
179
+ resolved_tenant_id = context["tenant_id"]
180
+
181
+ # Set default values for optional parameters
182
+ description_value = description or ""
183
+ review_owner_value = review_owner or ""
184
+
185
+ azure_input = CreateAssessmentInput(
186
+ AssessmentName=name,
187
+ Description=description_value,
188
+ Scope=scope_data,
189
+ ReviewOwner=review_owner_value,
190
+ Environment=environment,
191
+ IndustryType=industry_type,
192
+ Industry=industry,
193
+ DiagramURL=diagram_url,
194
+ )
195
+ result = session.azure_assessment.create_assessment(
196
+ tenant_id=resolved_tenant_id, data=azure_input
197
+ )
198
+ title = "Azure Assessment Created Successfully"
199
+ assessment_data = {
200
+ "ID": result.id,
201
+ "Name": name,
202
+ "Description": description_value or "N/A",
203
+ "Environment": environment,
204
+ "Review Owner": review_owner_value or "N/A",
205
+ "Industry Type": industry_type or "N/A",
206
+ "Industry": industry or "N/A",
207
+ "Diagram URL": diagram_url or "N/A",
208
+ }
209
+
210
+ # Format and output the result
211
+ format_item_output(
212
+ item=assessment_data,
213
+ title=title,
214
+ format_override=output_format,
215
+ )
216
+
217
+ except (Day2Error, ProfileNotFoundError) as e:
218
+ handle_error_with_exit(e)
219
+
220
+
221
+ @azure_assessment.command("findings")
222
+ @click.argument("assessment-id")
223
+ @click.option(
224
+ "--severity",
225
+ multiple=True,
226
+ help="Filter by severity (High, Medium, Low) - Azure specific values (can be used multiple times)",
227
+ )
228
+ @click.option(
229
+ "--status",
230
+ multiple=True,
231
+ help="Filter by status (Failed, Passed) - Azure specific values (can be used multiple times)",
232
+ )
233
+ @click.option(
234
+ "--resource-group",
235
+ multiple=True,
236
+ help="Filter by Azure resource group (can be used multiple times)",
237
+ )
238
+ @click.option(
239
+ "--subscription-id",
240
+ multiple=True,
241
+ help="Filter by Azure subscription ID (can be used multiple times)",
242
+ )
243
+ @click.option(
244
+ "--resource-type",
245
+ multiple=True,
246
+ help="Filter by Azure resource type (e.g., microsoft.compute/virtualmachines) (can be used multiple times)",
247
+ )
248
+ @click.option(
249
+ "--category",
250
+ multiple=True,
251
+ help="Filter by finding category (Security, Governance, etc.) (can be used multiple times)",
252
+ )
253
+ @click.option(
254
+ "--resource-id",
255
+ help="Filter by Azure resource ID (single value)",
256
+ )
257
+ @click.option(
258
+ "--check-title",
259
+ help="Filter by specific check title",
260
+ )
261
+ @click.option("--page-token", help="Page token for pagination")
262
+ @click.option(
263
+ "--page-size", type=int, default=10, help="Page size (valid range: 1-200)"
264
+ )
265
+ @with_common_options(include_tenant_id=True)
266
+ def list_azure_findings(
267
+ assessment_id: str,
268
+ severity: Tuple[str, ...],
269
+ status: Tuple[str, ...],
270
+ resource_group: Tuple[str, ...],
271
+ subscription_id: Tuple[str, ...],
272
+ resource_type: Tuple[str, ...],
273
+ category: Tuple[str, ...],
274
+ resource_id: Optional[str],
275
+ check_title: Optional[str],
276
+ page_token: Optional[str],
277
+ page_size: int,
278
+ output: Optional[str] = None,
279
+ profile: Optional[str] = None,
280
+ tenant_id: Optional[str] = None,
281
+ ) -> None:
282
+ """List findings for an Azure assessment.
283
+
284
+ If --tenant-id is not provided, uses the default tenant configured with 'day2 profile create' or 'day2 auth login'.
285
+
286
+ ASSESSMENT-ID: ID of the Azure assessment to list findings for.
287
+ """
288
+ try:
289
+ # Get enhanced context with tenant resolution
290
+ context = get_enhanced_context(
291
+ output=output, profile=profile, tenant_id=tenant_id, require_tenant=True
292
+ )
293
+ session = context["session"]
294
+ output_format = context["output_format"]
295
+ resolved_tenant_id = context["tenant_id"]
296
+
297
+ result = session.azure_assessment.list_findings(
298
+ tenant_id=resolved_tenant_id,
299
+ assessment_id=assessment_id,
300
+ resource_id=resource_id,
301
+ resource_type=list(resource_type) if resource_type else None,
302
+ resource_group=list(resource_group) if resource_group else None,
303
+ severity=list(severity) if severity else None,
304
+ category=list(category) if category else None,
305
+ subscription_id=list(subscription_id) if subscription_id else None,
306
+ status=list(status) if status else None,
307
+ check_title=check_title,
308
+ page_size=page_size,
309
+ page_token=page_token,
310
+ )
311
+ title = f"Azure Findings for Assessment: {assessment_id}"
312
+
313
+ if not result.records:
314
+ format_simple_output(
315
+ "No Azure findings found.",
316
+ format_override=output_format,
317
+ )
318
+ return
319
+
320
+ findings_list = result.records
321
+
322
+ # Process Azure findings
323
+ findings_data = []
324
+ for finding in findings_list:
325
+ findings_data.append(
326
+ {
327
+ "resource_id": finding.resource_id,
328
+ "resource_name": finding.resource_name,
329
+ "resource_type": finding.resource_type,
330
+ "resource_group": finding.resource_group,
331
+ "subscription_id": finding.subscription_id,
332
+ "severity": finding.severity,
333
+ "status": finding.status,
334
+ "category": finding.category,
335
+ "check_title": finding.check_title,
336
+ "description": finding.description,
337
+ "additional_information": finding.additional_information,
338
+ "recommended_actions": finding.recommended_actions,
339
+ "created_at": format_datetime_string(finding.created_at),
340
+ "updated_at": format_datetime_string(finding.updated_at),
341
+ }
342
+ )
343
+
344
+ # Define column mapping for the formatter
345
+ columns = {
346
+ "resource_id": "Resource ID",
347
+ "resource_name": "Resource Name",
348
+ "resource_type": "Resource Type",
349
+ "resource_group": "Resource Group",
350
+ "subscription_id": "Subscription ID",
351
+ "severity": "Severity",
352
+ "status": "Status",
353
+ "category": "Category",
354
+ "check_title": "Check Title",
355
+ "description": "Description",
356
+ "recommended_actions": "Recommended Actions",
357
+ "created_at": "Created At",
358
+ "updated_at": "Updated At",
359
+ }
360
+
361
+ # Format and output the results
362
+ format_list_output(
363
+ items=findings_data,
364
+ title=title,
365
+ columns=columns,
366
+ format_override=output_format,
367
+ )
368
+
369
+ # Display pagination information
370
+ if result.next_page_token:
371
+ format_simple_output(
372
+ f"More results available. Use --page-token={result.next_page_token} to get the next page.",
373
+ format_override=output_format,
374
+ )
375
+
376
+ except (Day2Error, ProfileNotFoundError) as e:
377
+ handle_error_with_exit(e)
@@ -0,0 +1,44 @@
1
+ """Helper utilities for the DAY2 CLI."""
2
+
3
+ from datetime import datetime
4
+ from typing import Optional, Union
5
+
6
+
7
+ def format_datetime_string(
8
+ datetime_value: Optional[Union[str, datetime]],
9
+ format_str: str = "%Y-%m-%d %H:%M:%S",
10
+ ) -> str:
11
+ """Format a datetime string or datetime object to a more readable format.
12
+
13
+ Args:
14
+ datetime_value: ISO 8601 datetime string or datetime object (e.g., "2025-09-04T12:05:47.102332Z")
15
+ format_str: Format string for strftime (default: "%Y-%m-%d %H:%M:%S")
16
+
17
+ Returns:
18
+ Formatted datetime string or "N/A" if input is None or invalid
19
+
20
+ Examples:
21
+ >>> format_datetime_string("2025-09-04T12:05:47.102332Z")
22
+ "2025-09-04 12:05:47"
23
+ >>> format_datetime_string(None)
24
+ "N/A"
25
+ """
26
+ if not datetime_value:
27
+ return "N/A"
28
+
29
+ # If it's already a datetime object, format it directly
30
+ if isinstance(datetime_value, datetime):
31
+ return datetime_value.strftime(format_str)
32
+
33
+ # If it's a string, parse it first
34
+ try:
35
+ # Handle ISO format with timezone
36
+ if isinstance(datetime_value, str):
37
+ if datetime_value.endswith("Z"):
38
+ datetime_value = datetime_value[:-1] + "+00:00"
39
+ dt = datetime.fromisoformat(datetime_value)
40
+ return dt.strftime(format_str)
41
+ except (ValueError, AttributeError):
42
+ pass
43
+
44
+ return "N/A"
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "day2"
3
- version = "0.2.7"
3
+ version = "0.2.8"
4
4
  description = "MontyCloud DAY2 SDK for Python"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.11"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes