aquasec 0.1.1__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.
- aquasec-0.1.1/LICENSE +21 -0
- aquasec-0.1.1/MANIFEST.in +3 -0
- aquasec-0.1.1/PKG-INFO +174 -0
- aquasec-0.1.1/README.md +144 -0
- aquasec-0.1.1/aquasec/__init__.py +97 -0
- aquasec-0.1.1/aquasec/auth.py +175 -0
- aquasec-0.1.1/aquasec/common.py +47 -0
- aquasec-0.1.1/aquasec/config.py +338 -0
- aquasec-0.1.1/aquasec/enforcers.py +157 -0
- aquasec-0.1.1/aquasec/licenses.py +107 -0
- aquasec-0.1.1/aquasec/repositories.py +33 -0
- aquasec-0.1.1/aquasec/scopes.py +40 -0
- aquasec-0.1.1/aquasec.egg-info/PKG-INFO +174 -0
- aquasec-0.1.1/aquasec.egg-info/SOURCES.txt +17 -0
- aquasec-0.1.1/aquasec.egg-info/dependency_links.txt +1 -0
- aquasec-0.1.1/aquasec.egg-info/requires.txt +3 -0
- aquasec-0.1.1/aquasec.egg-info/top_level.txt +1 -0
- aquasec-0.1.1/setup.cfg +4 -0
- aquasec-0.1.1/setup.py +34 -0
aquasec-0.1.1/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Andrea Zorzetto
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
aquasec-0.1.1/PKG-INFO
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: aquasec
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: API client library for Aqua Security platform
|
|
5
|
+
Home-page: https://github.com/andreazorzetto/aquasec
|
|
6
|
+
Author: Andrea Zorzetto
|
|
7
|
+
Author-email: your-email@example.com
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
14
|
+
Requires-Python: >=3.7
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Requires-Dist: requests>=2.28.0
|
|
18
|
+
Requires-Dist: prettytable>=3.5.0
|
|
19
|
+
Requires-Dist: cryptography>=41.0.0
|
|
20
|
+
Dynamic: author
|
|
21
|
+
Dynamic: author-email
|
|
22
|
+
Dynamic: classifier
|
|
23
|
+
Dynamic: description
|
|
24
|
+
Dynamic: description-content-type
|
|
25
|
+
Dynamic: home-page
|
|
26
|
+
Dynamic: license-file
|
|
27
|
+
Dynamic: requires-dist
|
|
28
|
+
Dynamic: requires-python
|
|
29
|
+
Dynamic: summary
|
|
30
|
+
|
|
31
|
+
# Aqua Library
|
|
32
|
+
|
|
33
|
+
A Python library providing a clean API interface for interacting with Aqua Security platform.
|
|
34
|
+
|
|
35
|
+
## Overview
|
|
36
|
+
|
|
37
|
+
The `aqua-lib` library is extracted from the andreactl tool to provide reusable components for building Aqua Security utilities. It includes modules for authentication, API calls, and configuration management.
|
|
38
|
+
|
|
39
|
+
## Installation
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install aqua-lib
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Features
|
|
46
|
+
|
|
47
|
+
- **Authentication**: Support for API keys and username/password authentication
|
|
48
|
+
- **Configuration Management**: Secure credential storage with profile support
|
|
49
|
+
- **API Modules**: Organized by domain (licenses, enforcers, repositories, etc.)
|
|
50
|
+
- **Utilities**: Common functions for data export and processing
|
|
51
|
+
|
|
52
|
+
## Quick Start
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
from aqua import authenticate, get_licences, interactive_setup
|
|
56
|
+
|
|
57
|
+
# Setup credentials interactively
|
|
58
|
+
interactive_setup()
|
|
59
|
+
|
|
60
|
+
# Or use environment variables
|
|
61
|
+
import os
|
|
62
|
+
os.environ['AQUA_KEY'] = 'your-api-key'
|
|
63
|
+
os.environ['AQUA_SECRET'] = 'your-api-secret'
|
|
64
|
+
os.environ['CSP_ENDPOINT'] = 'https://xyz.cloud.aquasec.com'
|
|
65
|
+
|
|
66
|
+
# Authenticate
|
|
67
|
+
token = authenticate()
|
|
68
|
+
|
|
69
|
+
# Get license information
|
|
70
|
+
licenses = get_licences(os.environ['CSP_ENDPOINT'], token)
|
|
71
|
+
print(licenses)
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Library Structure
|
|
75
|
+
|
|
76
|
+
```
|
|
77
|
+
aqua/
|
|
78
|
+
├── __init__.py # Main exports
|
|
79
|
+
├── auth.py # Authentication functions
|
|
80
|
+
├── config.py # Configuration management
|
|
81
|
+
├── licenses.py # License-related API calls
|
|
82
|
+
├── scopes.py # Application scope functions
|
|
83
|
+
├── enforcers.py # Enforcer-related functions
|
|
84
|
+
├── repositories.py # Repository API calls
|
|
85
|
+
└── common.py # Utility functions
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Configuration Management
|
|
89
|
+
|
|
90
|
+
The library includes a configuration management system that stores credentials securely:
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
from aqua import ConfigManager, load_profile_credentials
|
|
94
|
+
|
|
95
|
+
# Create configuration manager
|
|
96
|
+
config_mgr = ConfigManager()
|
|
97
|
+
|
|
98
|
+
# Save a profile
|
|
99
|
+
config = {
|
|
100
|
+
'auth_method': 'api_keys',
|
|
101
|
+
'api_endpoint': 'https://api.cloudsploit.com',
|
|
102
|
+
'csp_endpoint': 'https://xyz.cloud.aquasec.com',
|
|
103
|
+
'api_role': 'Administrator',
|
|
104
|
+
'api_methods': 'ANY'
|
|
105
|
+
}
|
|
106
|
+
creds = {
|
|
107
|
+
'api_key': 'your-key',
|
|
108
|
+
'api_secret': 'your-secret'
|
|
109
|
+
}
|
|
110
|
+
config_mgr.save_config('production', config)
|
|
111
|
+
config_mgr.encrypt_credentials(creds)
|
|
112
|
+
|
|
113
|
+
# Load profile
|
|
114
|
+
load_profile_credentials('production')
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## API Examples
|
|
118
|
+
|
|
119
|
+
### License Management
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
from aqua import get_licences, get_app_scopes, get_repo_count_by_scope
|
|
123
|
+
|
|
124
|
+
# Get license info
|
|
125
|
+
licenses = get_licences(server, token)
|
|
126
|
+
|
|
127
|
+
# Get application scopes
|
|
128
|
+
scopes = get_app_scopes(server, token)
|
|
129
|
+
|
|
130
|
+
# Get repository count by scope
|
|
131
|
+
repo_counts = get_repo_count_by_scope(server, token, [s['name'] for s in scopes])
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### Enforcer Management
|
|
135
|
+
|
|
136
|
+
```python
|
|
137
|
+
from aqua import get_enforcer_count, get_enforcer_groups
|
|
138
|
+
|
|
139
|
+
# Get enforcer count
|
|
140
|
+
count = get_enforcer_count(server, token)
|
|
141
|
+
|
|
142
|
+
# Get enforcer groups
|
|
143
|
+
groups = get_enforcer_groups(server, token)
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## Building Custom Utilities
|
|
147
|
+
|
|
148
|
+
The library makes it easy to create focused utilities:
|
|
149
|
+
|
|
150
|
+
```python
|
|
151
|
+
#!/usr/bin/env python3
|
|
152
|
+
import json
|
|
153
|
+
from aqua import authenticate, load_profile_credentials, get_licences
|
|
154
|
+
|
|
155
|
+
# Load saved credentials
|
|
156
|
+
load_profile_credentials('default')
|
|
157
|
+
|
|
158
|
+
# Authenticate
|
|
159
|
+
token = authenticate()
|
|
160
|
+
|
|
161
|
+
# Get data
|
|
162
|
+
licenses = get_licences(os.environ['CSP_ENDPOINT'], token)
|
|
163
|
+
|
|
164
|
+
# Output as JSON
|
|
165
|
+
print(json.dumps(licenses, indent=2))
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## Contributing
|
|
169
|
+
|
|
170
|
+
Issues and pull requests are welcome at [github.com/andreazorzetto/aqua-lib](https://github.com/andreazorzetto/aqua-lib)
|
|
171
|
+
|
|
172
|
+
## License
|
|
173
|
+
|
|
174
|
+
MIT License
|
aquasec-0.1.1/README.md
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# Aqua Library
|
|
2
|
+
|
|
3
|
+
A Python library providing a clean API interface for interacting with Aqua Security platform.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The `aqua-lib` library is extracted from the andreactl tool to provide reusable components for building Aqua Security utilities. It includes modules for authentication, API calls, and configuration management.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pip install aqua-lib
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Features
|
|
16
|
+
|
|
17
|
+
- **Authentication**: Support for API keys and username/password authentication
|
|
18
|
+
- **Configuration Management**: Secure credential storage with profile support
|
|
19
|
+
- **API Modules**: Organized by domain (licenses, enforcers, repositories, etc.)
|
|
20
|
+
- **Utilities**: Common functions for data export and processing
|
|
21
|
+
|
|
22
|
+
## Quick Start
|
|
23
|
+
|
|
24
|
+
```python
|
|
25
|
+
from aqua import authenticate, get_licences, interactive_setup
|
|
26
|
+
|
|
27
|
+
# Setup credentials interactively
|
|
28
|
+
interactive_setup()
|
|
29
|
+
|
|
30
|
+
# Or use environment variables
|
|
31
|
+
import os
|
|
32
|
+
os.environ['AQUA_KEY'] = 'your-api-key'
|
|
33
|
+
os.environ['AQUA_SECRET'] = 'your-api-secret'
|
|
34
|
+
os.environ['CSP_ENDPOINT'] = 'https://xyz.cloud.aquasec.com'
|
|
35
|
+
|
|
36
|
+
# Authenticate
|
|
37
|
+
token = authenticate()
|
|
38
|
+
|
|
39
|
+
# Get license information
|
|
40
|
+
licenses = get_licences(os.environ['CSP_ENDPOINT'], token)
|
|
41
|
+
print(licenses)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Library Structure
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
aqua/
|
|
48
|
+
├── __init__.py # Main exports
|
|
49
|
+
├── auth.py # Authentication functions
|
|
50
|
+
├── config.py # Configuration management
|
|
51
|
+
├── licenses.py # License-related API calls
|
|
52
|
+
├── scopes.py # Application scope functions
|
|
53
|
+
├── enforcers.py # Enforcer-related functions
|
|
54
|
+
├── repositories.py # Repository API calls
|
|
55
|
+
└── common.py # Utility functions
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Configuration Management
|
|
59
|
+
|
|
60
|
+
The library includes a configuration management system that stores credentials securely:
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
from aqua import ConfigManager, load_profile_credentials
|
|
64
|
+
|
|
65
|
+
# Create configuration manager
|
|
66
|
+
config_mgr = ConfigManager()
|
|
67
|
+
|
|
68
|
+
# Save a profile
|
|
69
|
+
config = {
|
|
70
|
+
'auth_method': 'api_keys',
|
|
71
|
+
'api_endpoint': 'https://api.cloudsploit.com',
|
|
72
|
+
'csp_endpoint': 'https://xyz.cloud.aquasec.com',
|
|
73
|
+
'api_role': 'Administrator',
|
|
74
|
+
'api_methods': 'ANY'
|
|
75
|
+
}
|
|
76
|
+
creds = {
|
|
77
|
+
'api_key': 'your-key',
|
|
78
|
+
'api_secret': 'your-secret'
|
|
79
|
+
}
|
|
80
|
+
config_mgr.save_config('production', config)
|
|
81
|
+
config_mgr.encrypt_credentials(creds)
|
|
82
|
+
|
|
83
|
+
# Load profile
|
|
84
|
+
load_profile_credentials('production')
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## API Examples
|
|
88
|
+
|
|
89
|
+
### License Management
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
from aqua import get_licences, get_app_scopes, get_repo_count_by_scope
|
|
93
|
+
|
|
94
|
+
# Get license info
|
|
95
|
+
licenses = get_licences(server, token)
|
|
96
|
+
|
|
97
|
+
# Get application scopes
|
|
98
|
+
scopes = get_app_scopes(server, token)
|
|
99
|
+
|
|
100
|
+
# Get repository count by scope
|
|
101
|
+
repo_counts = get_repo_count_by_scope(server, token, [s['name'] for s in scopes])
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Enforcer Management
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
from aqua import get_enforcer_count, get_enforcer_groups
|
|
108
|
+
|
|
109
|
+
# Get enforcer count
|
|
110
|
+
count = get_enforcer_count(server, token)
|
|
111
|
+
|
|
112
|
+
# Get enforcer groups
|
|
113
|
+
groups = get_enforcer_groups(server, token)
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Building Custom Utilities
|
|
117
|
+
|
|
118
|
+
The library makes it easy to create focused utilities:
|
|
119
|
+
|
|
120
|
+
```python
|
|
121
|
+
#!/usr/bin/env python3
|
|
122
|
+
import json
|
|
123
|
+
from aqua import authenticate, load_profile_credentials, get_licences
|
|
124
|
+
|
|
125
|
+
# Load saved credentials
|
|
126
|
+
load_profile_credentials('default')
|
|
127
|
+
|
|
128
|
+
# Authenticate
|
|
129
|
+
token = authenticate()
|
|
130
|
+
|
|
131
|
+
# Get data
|
|
132
|
+
licenses = get_licences(os.environ['CSP_ENDPOINT'], token)
|
|
133
|
+
|
|
134
|
+
# Output as JSON
|
|
135
|
+
print(json.dumps(licenses, indent=2))
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Contributing
|
|
139
|
+
|
|
140
|
+
Issues and pull requests are welcome at [github.com/andreazorzetto/aqua-lib](https://github.com/andreazorzetto/aqua-lib)
|
|
141
|
+
|
|
142
|
+
## License
|
|
143
|
+
|
|
144
|
+
MIT License
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Andrea Library - API client library for Aqua Security platform
|
|
3
|
+
|
|
4
|
+
This library provides a clean API interface for interacting with Aqua Security's
|
|
5
|
+
platform, extracted from the andreactl tool.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
__version__ = "0.1.0"
|
|
9
|
+
|
|
10
|
+
from .auth import (
|
|
11
|
+
authenticate,
|
|
12
|
+
api_auth,
|
|
13
|
+
user_pass_saas_auth,
|
|
14
|
+
user_pass_onprem_auth,
|
|
15
|
+
extract_token_from_auth
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
from .licenses import (
|
|
19
|
+
api_get_licenses,
|
|
20
|
+
api_get_dta_license,
|
|
21
|
+
api_post_dta_license_utilization,
|
|
22
|
+
get_licences,
|
|
23
|
+
get_repo_count_by_scope,
|
|
24
|
+
get_enforcer_count_by_scope
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
from .scopes import (
|
|
28
|
+
api_get_scopes,
|
|
29
|
+
get_app_scopes
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
from .enforcers import (
|
|
33
|
+
api_get_enforcer_groups,
|
|
34
|
+
get_enforcers_from_group,
|
|
35
|
+
get_enforcer_groups,
|
|
36
|
+
get_enforcer_count
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
from .repositories import (
|
|
40
|
+
api_get_repositories
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
from .common import (
|
|
44
|
+
write_content_to_file,
|
|
45
|
+
write_json_to_file,
|
|
46
|
+
generate_csv_for_license_breakdown
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
from .config import (
|
|
50
|
+
ConfigManager,
|
|
51
|
+
load_profile_credentials,
|
|
52
|
+
test_connection,
|
|
53
|
+
interactive_setup,
|
|
54
|
+
list_profiles
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
__all__ = [
|
|
58
|
+
# Auth
|
|
59
|
+
'authenticate',
|
|
60
|
+
'api_auth',
|
|
61
|
+
'user_pass_saas_auth',
|
|
62
|
+
'user_pass_onprem_auth',
|
|
63
|
+
'extract_token_from_auth',
|
|
64
|
+
|
|
65
|
+
# Licenses
|
|
66
|
+
'api_get_licenses',
|
|
67
|
+
'api_get_dta_license',
|
|
68
|
+
'api_post_dta_license_utilization',
|
|
69
|
+
'get_licences',
|
|
70
|
+
'get_repo_count_by_scope',
|
|
71
|
+
'get_enforcer_count_by_scope',
|
|
72
|
+
|
|
73
|
+
# Scopes
|
|
74
|
+
'api_get_scopes',
|
|
75
|
+
'get_app_scopes',
|
|
76
|
+
|
|
77
|
+
# Enforcers
|
|
78
|
+
'api_get_enforcer_groups',
|
|
79
|
+
'get_enforcers_from_group',
|
|
80
|
+
'get_enforcer_groups',
|
|
81
|
+
'get_enforcer_count',
|
|
82
|
+
|
|
83
|
+
# Repositories
|
|
84
|
+
'api_get_repositories',
|
|
85
|
+
|
|
86
|
+
# Common utilities
|
|
87
|
+
'write_content_to_file',
|
|
88
|
+
'write_json_to_file',
|
|
89
|
+
'generate_csv_for_license_breakdown',
|
|
90
|
+
|
|
91
|
+
# Configuration management
|
|
92
|
+
'ConfigManager',
|
|
93
|
+
'load_profile_credentials',
|
|
94
|
+
'test_connection',
|
|
95
|
+
'interactive_setup',
|
|
96
|
+
'list_profiles'
|
|
97
|
+
]
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Authentication module for Andrea library
|
|
3
|
+
Handles authentication with Aqua Security platform
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import hashlib
|
|
7
|
+
import hmac
|
|
8
|
+
import json
|
|
9
|
+
import requests
|
|
10
|
+
import sys
|
|
11
|
+
import time
|
|
12
|
+
from os import environ
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def authenticate(verbose=False):
|
|
16
|
+
"""
|
|
17
|
+
Main authentication function that detects auth method and returns token
|
|
18
|
+
"""
|
|
19
|
+
api_key = environ.get('AQUA_KEY')
|
|
20
|
+
api_secret = environ.get('AQUA_SECRET')
|
|
21
|
+
api_role = environ.get('AQUA_ROLE')
|
|
22
|
+
user = environ.get('AQUA_USER')
|
|
23
|
+
password = environ.get('AQUA_PASSWORD')
|
|
24
|
+
api_endpoint = environ.get('AQUA_ENDPOINT')
|
|
25
|
+
csp_endpoint = environ.get('CSP_ENDPOINT')
|
|
26
|
+
api_methods = environ.get('AQUA_METHODS')
|
|
27
|
+
|
|
28
|
+
# API Keys SaaS auth
|
|
29
|
+
if api_key and api_secret and api_endpoint and csp_endpoint and api_role and api_methods:
|
|
30
|
+
# get methods list
|
|
31
|
+
methods_list = api_methods.split(',')
|
|
32
|
+
methods_json = json.dumps(methods_list)
|
|
33
|
+
|
|
34
|
+
if verbose:
|
|
35
|
+
print("Auth method: API Keys SaaS")
|
|
36
|
+
|
|
37
|
+
token = api_auth(api_key, api_secret, api_endpoint, api_role, methods_json, verbose)
|
|
38
|
+
|
|
39
|
+
# user/pass SaaS auth
|
|
40
|
+
elif user and password and api_endpoint:
|
|
41
|
+
if verbose:
|
|
42
|
+
print("Auth method: User/Pass SaaS")
|
|
43
|
+
token = user_pass_saas_auth(user, password, api_endpoint)
|
|
44
|
+
|
|
45
|
+
# user/pass on-prem auth
|
|
46
|
+
elif user and password and csp_endpoint and not api_endpoint:
|
|
47
|
+
if verbose:
|
|
48
|
+
print("Auth method: User/Pass on-prem")
|
|
49
|
+
token = user_pass_onprem_auth(user, password, csp_endpoint)
|
|
50
|
+
|
|
51
|
+
# trying to authenticate with user and password
|
|
52
|
+
else:
|
|
53
|
+
print("""\nMissing credentials, cannot proceed.
|
|
54
|
+
|
|
55
|
+
Refer to the docs for info about SaaS API keys auth:
|
|
56
|
+
https://docs.aquasec.com/saas/api-reference/getting-started-with-aqua-platform-apis/api-authentication
|
|
57
|
+
|
|
58
|
+
Example run command:
|
|
59
|
+
> docker run --env-file aqua-saas-prod.env -ti andreazorzetto/andreactl command
|
|
60
|
+
|
|
61
|
+
Example creds file:
|
|
62
|
+
----------------------------------------
|
|
63
|
+
# Required for SaaS API Keys Auth
|
|
64
|
+
AQUA_KEY=xxxxxxxxxxxxxxxxxx
|
|
65
|
+
AQUA_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
66
|
+
AQUA_ROLE=api_admin_role
|
|
67
|
+
AQUA_METHODS=ANY
|
|
68
|
+
AQUA_ENDPOINT='https://eu-1.api.cloudsploit.com'
|
|
69
|
+
|
|
70
|
+
# Required for User/Pass Auth
|
|
71
|
+
#AQUA_USER=email@address.com
|
|
72
|
+
#AQUA_PASSWORD='password'
|
|
73
|
+
|
|
74
|
+
# Required for both Auth methods
|
|
75
|
+
CSP_ENDPOINT='https://xxxxxxxxxx.cloud.aquasec.com'
|
|
76
|
+
----------------------------------------
|
|
77
|
+
|
|
78
|
+
AUTHENTICATION CANCELLED
|
|
79
|
+
""")
|
|
80
|
+
sys.exit(1)
|
|
81
|
+
|
|
82
|
+
return token
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def api_auth(api_key, api_secret, api_endpoint, api_role, api_methods, verbose=False):
|
|
86
|
+
"""
|
|
87
|
+
Authenticate using API keys (SaaS)
|
|
88
|
+
"""
|
|
89
|
+
timestamp = str(int(time.time()))
|
|
90
|
+
api_url = api_endpoint + "/v2/tokens"
|
|
91
|
+
|
|
92
|
+
# Define the body of the POST request
|
|
93
|
+
post_body_str = str(
|
|
94
|
+
'{"validity":240,"allowed_endpoints":' + api_methods + ',"csp_roles":["' + api_role + '"]}').replace(" ", "")
|
|
95
|
+
if verbose:
|
|
96
|
+
print("post_body_string: %s" % post_body_str)
|
|
97
|
+
|
|
98
|
+
# Create the string to sign
|
|
99
|
+
string_to_sign = timestamp + "POST" + "/v2/tokens" + post_body_str
|
|
100
|
+
|
|
101
|
+
# Create HMAC signature
|
|
102
|
+
signature = hmac.new(api_secret.encode(), string_to_sign.encode(), hashlib.sha256).hexdigest()
|
|
103
|
+
|
|
104
|
+
# Issue the signed request to get authentication token
|
|
105
|
+
headers = {
|
|
106
|
+
"Content-Type": "application/json",
|
|
107
|
+
"X-API-Key": api_key,
|
|
108
|
+
"X-Timestamp": timestamp,
|
|
109
|
+
"X-Signature": signature
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
response = requests.post(api_url, headers=headers, data=post_body_str)
|
|
113
|
+
|
|
114
|
+
# Extract status and token from the response
|
|
115
|
+
if response.status_code == 200:
|
|
116
|
+
token = response.json()['data']
|
|
117
|
+
else:
|
|
118
|
+
print("Authentication failed.", response.text)
|
|
119
|
+
sys.exit(1)
|
|
120
|
+
|
|
121
|
+
return token
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def user_pass_saas_auth(user, passwd, api_endpoint):
|
|
125
|
+
"""
|
|
126
|
+
Authenticate using username/password (SaaS)
|
|
127
|
+
"""
|
|
128
|
+
# Set schema for saas auth
|
|
129
|
+
auth_info = {"email": user, "password": passwd}
|
|
130
|
+
|
|
131
|
+
# Do authentication
|
|
132
|
+
api_url = api_endpoint + "/v2/signin"
|
|
133
|
+
res = requests.post(url=api_url, json=auth_info, verify=False)
|
|
134
|
+
|
|
135
|
+
# One of the authentications above succeeded
|
|
136
|
+
if res.status_code == 200:
|
|
137
|
+
token = res.json()["data"]["token"]
|
|
138
|
+
else:
|
|
139
|
+
print("Authentication failed", res.status_code)
|
|
140
|
+
sys.exit(1)
|
|
141
|
+
|
|
142
|
+
return token
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def user_pass_onprem_auth(user, passwd, csp_endpoint):
|
|
146
|
+
"""
|
|
147
|
+
Authenticate using username/password (on-prem)
|
|
148
|
+
"""
|
|
149
|
+
# Set schema for on-prem auth
|
|
150
|
+
auth_info = {"id": user, "password": passwd}
|
|
151
|
+
|
|
152
|
+
# Do authentication
|
|
153
|
+
api_url = csp_endpoint + "/api/v1/login"
|
|
154
|
+
res = requests.post(url=api_url, json=auth_info, verify=False)
|
|
155
|
+
|
|
156
|
+
# One of the authentications above succeeded
|
|
157
|
+
if res.status_code == 200:
|
|
158
|
+
token = res.json()["token"]
|
|
159
|
+
|
|
160
|
+
# Nothing worked. Exit.
|
|
161
|
+
else:
|
|
162
|
+
print("Authentication failed", res.status_code)
|
|
163
|
+
sys.exit(1)
|
|
164
|
+
|
|
165
|
+
return token
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def extract_token_from_auth(res, is_account_saas):
|
|
169
|
+
"""
|
|
170
|
+
Extract token from authentication response
|
|
171
|
+
"""
|
|
172
|
+
if is_account_saas:
|
|
173
|
+
return res.json()["data"]["token"]
|
|
174
|
+
else:
|
|
175
|
+
return res.json()["token"]
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Common utility functions for Andrea library
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import csv
|
|
6
|
+
import json
|
|
7
|
+
from os.path import exists
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def write_content_to_file(file, content):
|
|
11
|
+
"""Write content to file"""
|
|
12
|
+
with open(file, 'w') as f:
|
|
13
|
+
f.write(content)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def write_json_to_file(file, content):
|
|
17
|
+
"""Write JSON content to file, appending if exists"""
|
|
18
|
+
if exists(file):
|
|
19
|
+
with open(file, "a") as file:
|
|
20
|
+
json.dump(content, file)
|
|
21
|
+
file.write('\n')
|
|
22
|
+
else:
|
|
23
|
+
with open(file, "w") as file:
|
|
24
|
+
json.dump(content, file)
|
|
25
|
+
file.write('\n')
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def generate_csv_for_license_breakdown(license_breakdown, filename):
|
|
29
|
+
"""Generate CSV file for license breakdown data"""
|
|
30
|
+
columns = ['scope', 'repos', 'aqua_enforcer', 'kube_enforcer', 'vm_enforcer', 'micro_enforcer', 'nano_enforcer', 'pod_enforcer']
|
|
31
|
+
|
|
32
|
+
with open(filename, mode='w', newline='') as file:
|
|
33
|
+
writer = csv.DictWriter(file, fieldnames=columns)
|
|
34
|
+
writer.writeheader()
|
|
35
|
+
|
|
36
|
+
for key, value in license_breakdown.items():
|
|
37
|
+
row = {
|
|
38
|
+
'scope': value['scope name'],
|
|
39
|
+
'repos': value['repos'],
|
|
40
|
+
'aqua_enforcer': value['agent']['connected'],
|
|
41
|
+
'kube_enforcer': value['kube_enforcer']['connected'],
|
|
42
|
+
'vm_enforcer': value['host_enforcer']['connected'],
|
|
43
|
+
'micro_enforcer': value['micro_enforcer']['connected'],
|
|
44
|
+
'nano_enforcer': value['nano_enforcer']['connected'],
|
|
45
|
+
'pod_enforcer': value['pod_enforcer']['connected']
|
|
46
|
+
}
|
|
47
|
+
writer.writerow(row)
|