vgs-cli 0.0.1.dev0__py3-none-any.whl

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 (56) hide show
  1. vgs_cli-0.0.1.dev0.data/data/vgscli/calm.yaml +16 -0
  2. vgs_cli-0.0.1.dev0.data/data/vgscli/checkout.yaml +21 -0
  3. vgs_cli-0.0.1.dev0.data/data/vgscli/http-route-template.yaml +61 -0
  4. vgs_cli-0.0.1.dev0.data/data/vgscli/mft-route-template.yaml +10 -0
  5. vgs_cli-0.0.1.dev0.data/data/vgscli/payments-admin.yaml +25 -0
  6. vgs_cli-0.0.1.dev0.data/data/vgscli/service-account-schema.yaml +54 -0
  7. vgs_cli-0.0.1.dev0.data/data/vgscli/sub-account-checkout.yaml +23 -0
  8. vgs_cli-0.0.1.dev0.data/data/vgscli/vault-resources.yaml +710 -0
  9. vgs_cli-0.0.1.dev0.data/data/vgscli/vault-schema.yaml +36 -0
  10. vgs_cli-0.0.1.dev0.data/data/vgscli/vault-template.yaml +12 -0
  11. vgs_cli-0.0.1.dev0.data/data/vgscli/vgs-cli.yaml +17 -0
  12. vgs_cli-0.0.1.dev0.dist-info/METADATA +139 -0
  13. vgs_cli-0.0.1.dev0.dist-info/RECORD +56 -0
  14. vgs_cli-0.0.1.dev0.dist-info/WHEEL +5 -0
  15. vgs_cli-0.0.1.dev0.dist-info/entry_points.txt +2 -0
  16. vgs_cli-0.0.1.dev0.dist-info/licenses/LICENSE +22 -0
  17. vgs_cli-0.0.1.dev0.dist-info/top_level.txt +1 -0
  18. vgscli/__init__.py +0 -0
  19. vgscli/_version.py +32 -0
  20. vgscli/access_logs.py +65 -0
  21. vgscli/audits_api.py +102 -0
  22. vgscli/auth.py +68 -0
  23. vgscli/auth_server.py +131 -0
  24. vgscli/auth_utils.py +24 -0
  25. vgscli/callback_server.py +41 -0
  26. vgscli/cert_manager_api.py +34 -0
  27. vgscli/cli/__init__.py +23 -0
  28. vgscli/cli/commands/__init__.py +3 -0
  29. vgscli/cli/commands/apply.py +307 -0
  30. vgscli/cli/commands/generate.py +134 -0
  31. vgscli/cli/commands/get.py +200 -0
  32. vgscli/cli/types/__init__.py +2 -0
  33. vgscli/cli/types/resource_id.py +39 -0
  34. vgscli/cli/types/variable.py +21 -0
  35. vgscli/cli_utils.py +132 -0
  36. vgscli/click_extensions.py +88 -0
  37. vgscli/config_file.py +58 -0
  38. vgscli/errors.py +263 -0
  39. vgscli/file_token_util.py +30 -0
  40. vgscli/id_generator.py +46 -0
  41. vgscli/keyring_token_util.py +128 -0
  42. vgscli/resource-templates/http-route-template.yaml +61 -0
  43. vgscli/resource-templates/mft-route-template.yaml +10 -0
  44. vgscli/resource-templates/service-account/calm.yaml +16 -0
  45. vgscli/resource-templates/service-account/checkout.yaml +21 -0
  46. vgscli/resource-templates/service-account/payments-admin.yaml +25 -0
  47. vgscli/resource-templates/service-account/sub-account-checkout.yaml +23 -0
  48. vgscli/resource-templates/service-account/vgs-cli.yaml +17 -0
  49. vgscli/resource-templates/vault-template.yaml +12 -0
  50. vgscli/testing.py +48 -0
  51. vgscli/text.py +9 -0
  52. vgscli/token_handler.py +11 -0
  53. vgscli/validation-schemas/service-account-schema.yaml +54 -0
  54. vgscli/validation-schemas/vault-resources.yaml +710 -0
  55. vgscli/validation-schemas/vault-schema.yaml +36 -0
  56. vgscli/vgs.py +249 -0
@@ -0,0 +1,36 @@
1
+ ---
2
+ "$schema": http://json-schema.org/draft-07/schema#
3
+ type: object
4
+ properties:
5
+ apiVersion:
6
+ type: string
7
+ enum:
8
+ - 1.0.0
9
+ kind:
10
+ type: string
11
+ enum:
12
+ - Vault
13
+ data:
14
+ type: object
15
+ properties:
16
+ name:
17
+ type: string
18
+ minLength: 3
19
+ maxLength: 50
20
+ environment:
21
+ type: string
22
+ enum:
23
+ - SANDBOX
24
+ - LIVE
25
+ organizationId:
26
+ type: string
27
+ pattern: ^AC[A-Za-z0-9]{22}$
28
+ required:
29
+ - name
30
+ - environment
31
+ additionalProperties: false
32
+ required:
33
+ - apiVersion
34
+ - kind
35
+ - data
36
+ additionalProperties: false
vgscli/vgs.py ADDED
@@ -0,0 +1,249 @@
1
+ import os
2
+ from typing import Optional
3
+
4
+ import click
5
+ from click_plugins import with_plugins
6
+ from simple_rest_client.exceptions import ClientError
7
+ from vgs.sdk.serializers import format_logs, wrap_records
8
+ from vgs.sdk.utils import resolve_env
9
+
10
+ from vgscli import auth
11
+ from vgscli._version import check_for_updates, version
12
+ from vgscli.access_logs import fetch_logs, prepare_filter
13
+ from vgscli.audits_api import OperationLogsQueryConfig
14
+ from vgscli.audits_api import create_api as create_audits_api
15
+ from vgscli.auth import client_credentials_login, handshake, token_util
16
+ from vgscli.cli.commands import apply, generate, get
17
+ from vgscli.cli_utils import iter_entry_points
18
+ from vgscli.click_extensions import Config, DateTimeDuration
19
+ from vgscli.config_file import configuration_option
20
+ from vgscli.errors import ServiceClientDeletionError, handle_errors
21
+
22
+
23
+ @with_plugins(iter_entry_points("vgs.plugins"))
24
+ @click.group()
25
+ @click.option("--debug", "-d", is_flag=True, help="Enables debug mode.", default=False)
26
+ @click.option("--environment", "-e", help="VGS environment.", hidden=True)
27
+ @click.version_option(message="%(version)s", version=version())
28
+ @click.pass_context
29
+ def cli(ctx, debug, environment):
30
+ """
31
+ Command Line Tool for programmatic configurations on VGS.
32
+ """
33
+ ctx.debug = debug
34
+
35
+ env = resolve_env(environment)
36
+ ctx.obj = Config(debug, env)
37
+
38
+ client_id = os.environ.get("VGS_CLIENT_ID")
39
+ client_secret = os.environ.get("VGS_CLIENT_SECRET")
40
+
41
+ if client_id and client_secret:
42
+ client_credentials_login(ctx, client_id, client_secret, env)
43
+
44
+
45
+ cli.add_command(get)
46
+ cli.add_command(apply)
47
+ cli.add_command(generate)
48
+
49
+
50
+ @with_plugins(iter_entry_points("vgs.delete.plugins"))
51
+ @cli.group()
52
+ def delete():
53
+ """
54
+ Delete VGS resource.
55
+ """
56
+ pass
57
+
58
+
59
+ @with_plugins(iter_entry_points("vgs.logs.plugins"))
60
+ @cli.group()
61
+ def logs():
62
+ """
63
+ Prints VGS logs.
64
+
65
+ \b\bExamples:
66
+
67
+ # Show all access logs for a vault\t\t\t\t\t\t
68
+ vgs logs access -V <VAULT_ID>
69
+
70
+ # Show all operation logs for request\t\t\t\t\t\t
71
+ vgs logs operations -V <VAULT_ID> -R <REQUEST_ID>
72
+ """
73
+ pass
74
+
75
+
76
+ def validate_tail(ctx, param, value):
77
+ try:
78
+ if value > 0:
79
+ return value
80
+ elif value != -1:
81
+ raise ValueError
82
+ except ValueError:
83
+ raise click.BadParameter("need to be positive value, larger than 0")
84
+
85
+
86
+ @logs.command("access", short_help="Get access logs")
87
+ @click.option(
88
+ "--output",
89
+ "-o",
90
+ help="Output format",
91
+ type=click.Choice(["json", "yaml"]),
92
+ default="yaml",
93
+ show_default=True,
94
+ )
95
+ # @click.option('--follow', '-f', help='Specify to stream logs as they appear on the VGS dashboard.', is_flag=True, default=False)
96
+ @click.option(
97
+ "--since",
98
+ help="Only show logs newer than a relative duration like 30s, 5m, or 3h or after a specific RFC 3339 date.",
99
+ type=DateTimeDuration(formats=["%Y-%m-%dT%H:%M:%S"]),
100
+ )
101
+ @click.option(
102
+ "--tail",
103
+ help="Number of log records to show. Defaults to all logs if unspecified.",
104
+ default=-1,
105
+ callback=validate_tail,
106
+ )
107
+ @click.option(
108
+ "--until",
109
+ help="Only show logs older than a relative duration like 30s, 5m, or 3h or before a specific RFC 3339 date.",
110
+ type=DateTimeDuration(formats=["%Y-%m-%dT%H:%M:%S"]),
111
+ )
112
+ @click.option("--vault", "-V", help="Vault ID", required=True)
113
+ @click.option(
114
+ "--proxy",
115
+ "-P",
116
+ help="Show access logs for a specific proxy",
117
+ type=click.Choice(["http", "sftp", "iso8583"]),
118
+ )
119
+ @click.pass_context
120
+ def access(ctx, vault, proxy, **kwargs):
121
+ """
122
+ Get access logs
123
+
124
+ \b\bExamples:
125
+
126
+ # Show access logs available for a vault\t\t\t\t\t\t
127
+ vgs logs access -V <VAULT_ID>
128
+
129
+ # Show access logs in the last hour\t\t\t\t\t\t
130
+ vgs logs access -V <VAULT_ID> --since=1h
131
+
132
+ # Show access logs after a specific date\t\t\t\t\t\t
133
+ vgs logs access -V <VAULT_ID> --since=2020-08-18T11:40:45
134
+
135
+ # Show only the most recent 25 log records\t\t\t\t\t\t
136
+ vgs logs access -V <VAULT_ID> --tail=25
137
+ """
138
+ handshake(ctx, ctx.obj.env)
139
+
140
+ audits_api = create_audits_api(
141
+ ctx, vault, ctx.obj.env, token_util.get_access_token()
142
+ )
143
+
144
+ filters = prepare_filter(
145
+ {
146
+ "tenant_id": vault,
147
+ "protocol": proxy,
148
+ "from": kwargs.get("since"),
149
+ "to": kwargs.get("until"),
150
+ }
151
+ )
152
+
153
+ for res in fetch_logs(audits_api, filters, kwargs.get("tail")):
154
+ click.echo(format_logs(wrap_records(res), kwargs.get("output")))
155
+
156
+ # while kwargs['follow']:
157
+ # res = fetch_logs(audits_api, filters, kwargs.get('tail'))
158
+ # click.echo(format_logs(res, kwargs.get('output')))
159
+ # time.sleep(3)
160
+
161
+
162
+ @logs.command("operations", short_help="Get operations logs")
163
+ @click.option(
164
+ "--output",
165
+ "-o",
166
+ help="Output format",
167
+ type=click.Choice(["json", "yaml"]),
168
+ default="yaml",
169
+ show_default=True,
170
+ )
171
+ @click.option("--vault", "-V", help="Vault ID", required=True)
172
+ @click.option("--request", "-R", help="VGS Request ID", required=True)
173
+ @click.pass_context
174
+ def operations_logs(ctx, vault, request, **kwargs):
175
+ """
176
+ Get operations logs
177
+
178
+ \b\bExamples:
179
+
180
+ # Return operation logs for a request\t\t\t\t\t\t
181
+ vgs logs operations -V <VAULT_ID> -R <REQUEST_ID>
182
+
183
+ # Return operations logs for a request in JSON format\t\t\t\t\t\t
184
+ vgs logs operations -V <VAULT_ID> -R <REQUEST_ID> -o json
185
+ """
186
+ handshake(ctx, ctx.obj.env)
187
+
188
+ audits_api = create_audits_api(
189
+ ctx, vault, ctx.obj.env, token_util.get_access_token()
190
+ )
191
+ config = OperationLogsQueryConfig(vault, trace_id=request)
192
+
193
+ logs = fetch_operations_logs(audits_api, config.to_query_params())
194
+ click.echo(format_logs(wrap_records(logs), kwargs.get("output")))
195
+
196
+
197
+ def fetch_operations_logs(api, params):
198
+ return api.operations_logs.list(params=params).body["data"]
199
+
200
+
201
+ @delete.command("service-account")
202
+ @click.option("--organization", "-O", help="Organization ID", required=True)
203
+ @click.argument("client_id", type=click.STRING)
204
+ @click.pass_context
205
+ @handle_errors()
206
+ def delete_service_account(ctx, organization, client_id):
207
+ """
208
+ Delete service account client from the organization.
209
+ """
210
+ from vgscli.cli import create_account_mgmt_api
211
+
212
+ account_mgmt = create_account_mgmt_api(ctx)
213
+ try:
214
+ account_mgmt.service_accounts.delete(organization, client_id)
215
+ except ClientError as e:
216
+ raise ServiceClientDeletionError(e)
217
+
218
+
219
+ @cli.command()
220
+ @click.option(
221
+ "--browser/--no-browser",
222
+ "open_browser",
223
+ default=True,
224
+ help="Open the default browser automatically.",
225
+ show_default=True,
226
+ )
227
+ @click.option("--idp", help="Log in with a custom Identity Provider.")
228
+ @click.pass_context
229
+ @configuration_option(section="login")
230
+ def login(ctx, idp: Optional[str], open_browser: bool):
231
+ """
232
+ Login to VGS via browser.
233
+ """
234
+ check_for_updates()
235
+
236
+ auth.login(ctx, ctx.obj.env, idp=idp, open_browser=open_browser)
237
+
238
+
239
+ @cli.command()
240
+ @click.pass_context
241
+ def logout(ctx):
242
+ """
243
+ Logout from VGS.
244
+ """
245
+ auth.logout(ctx, ctx.obj.env)
246
+
247
+
248
+ if __name__ == "__main__":
249
+ cli()