diff --git a/.secrets.baseline b/.secrets.baseline index b256d881d..394061815 100644 --- a/.secrets.baseline +++ b/.secrets.baseline @@ -3,7 +3,7 @@ "files": "^.secrets.baseline$", "lines": null }, - "generated_at": "2024-10-07T21:05:06Z", + "generated_at": "2025-02-14T20:05:29Z", "plugins_used": [ { "name": "AWSKeyDetector" @@ -574,7 +574,7 @@ "hashed_secret": "a4c805a62a0387010cd172cfed6f6772eb92a5d6", "is_secret": false, "is_verified": false, - "line_number": 32, + "line_number": 31, "type": "Secret Keyword", "verified_result": null } @@ -584,7 +584,7 @@ "hashed_secret": "f7a9e24777ec23212c54d7a350bc5bea5477fdbb", "is_secret": false, "is_verified": false, - "line_number": 1088, + "line_number": 1077, "type": "Secret Keyword", "verified_result": null } @@ -604,7 +604,7 @@ "hashed_secret": "8de91b1f4c8ca32302ae101da16fb88fb127582a", "is_secret": false, "is_verified": false, - "line_number": 165, + "line_number": 168, "type": "Secret Keyword", "verified_result": null }, @@ -612,7 +612,7 @@ "hashed_secret": "2da422d13be8072a8dcae1e46b36add9cb2372fa", "is_secret": false, "is_verified": false, - "line_number": 190, + "line_number": 193, "type": "Secret Keyword", "verified_result": null } @@ -640,7 +640,7 @@ "hashed_secret": "2c0ceacd445f15ebc02315e18fb3ed8ec73a61a0", "is_secret": false, "is_verified": false, - "line_number": 544, + "line_number": 545, "type": "Hex High Entropy String", "verified_result": null }, @@ -648,7 +648,7 @@ "hashed_secret": "f08bf4f915242a2700e861e4e073ab45dc745e92", "is_secret": false, "is_verified": false, - "line_number": 551, + "line_number": 552, "type": "Hex High Entropy String", "verified_result": null }, @@ -656,7 +656,7 @@ "hashed_secret": "806f21b4bc195ffd5749f295b83909d66a56ff38", "is_secret": false, "is_verified": false, - "line_number": 583, + "line_number": 584, "type": "Hex High Entropy String", "verified_result": null }, @@ -664,7 +664,7 @@ "hashed_secret": "1c89f7ca3440fe5db16e3b0ffe414d11845331d9", "is_secret": false, "is_verified": false, - "line_number": 589, + "line_number": 590, "type": "Hex High Entropy String", "verified_result": null }, @@ -672,7 +672,7 @@ "hashed_secret": "bc553d847e40dd6f3f63638f16f57b28ce1425cc", "is_secret": false, "is_verified": false, - "line_number": 596, + "line_number": 597, "type": "Hex High Entropy String", "verified_result": null } @@ -700,7 +700,7 @@ "hashed_secret": "8af1f8146d96a3cd862281442d0d6c5cb6f8f9e5", "is_secret": false, "is_verified": false, - "line_number": 176, + "line_number": 181, "type": "Hex High Entropy String", "verified_result": null } @@ -720,7 +720,7 @@ "hashed_secret": "9878e362285eb314cfdbaa8ee8c300c285856810", "is_secret": false, "is_verified": false, - "line_number": 324, + "line_number": 313, "type": "Secret Keyword", "verified_result": null } @@ -748,7 +748,7 @@ "hashed_secret": "f08c5dc4980df3c1237e88b872a2429dac6be328", "is_secret": false, "is_verified": false, - "line_number": 310, + "line_number": 297, "type": "Secret Keyword", "verified_result": null }, @@ -756,7 +756,7 @@ "hashed_secret": "7e6a3680012346b94b54731e13d8a9ffa3790645", "is_secret": false, "is_verified": false, - "line_number": 396, + "line_number": 383, "type": "Secret Keyword", "verified_result": null } diff --git a/SoftLayer/CLI/cdn/cdn.py b/SoftLayer/CLI/cdn/cdn.py new file mode 100644 index 000000000..7237a126a --- /dev/null +++ b/SoftLayer/CLI/cdn/cdn.py @@ -0,0 +1,11 @@ +"""https://cloud.ibm.com/docs/CDN?topic=CDN-cdn-deprecation""" +# :license: MIT, see LICENSE for more details. + +import click + +import SoftLayer + + +@click.command(cls=SoftLayer.CLI.command.SLCommand, deprecated=True) +def cli(): + """https://cloud.ibm.com/docs/CDN?topic=CDN-cdn-deprecation""" diff --git a/SoftLayer/CLI/cdn/create.py b/SoftLayer/CLI/cdn/create.py deleted file mode 100644 index c23d91e51..000000000 --- a/SoftLayer/CLI/cdn/create.py +++ /dev/null @@ -1,56 +0,0 @@ -"""Create a CDN domain mapping.""" -# :license: MIT, see LICENSE for more details. - -import click - -import SoftLayer -from SoftLayer.CLI import environment -from SoftLayer.CLI import exceptions -from SoftLayer.CLI import formatting - - -@click.command(cls=SoftLayer.CLI.command.SLCommand, ) -@click.option('--hostname', required=True, help="To route requests to your website, enter the hostname for your" - "website, for example, www.example.com or app.example.com.") -@click.option('--origin', required=True, help="Your server IP address or hostname.") -@click.option('--origin-type', default="server", type=click.Choice(['server', 'storage']), show_default=True, - help="The origin type. Note: If OriginType is storage then OriginHost is take as Endpoint") -@click.option('--http', help="Http port") -@click.option('--https', help="Https port") -@click.option('--bucket-name', help="Bucket name") -@click.option('--cname', help="Enter a globally unique subdomain. The full URL becomes the CNAME we use to configure" - " your DNS. If no value is entered, we will generate a CNAME for you.") -@click.option('--header', help="The edge server uses the host header in the HTTP header to communicate with the" - " Origin host. It defaults to Hostname.") -@click.option('--path', help="Give a path relative to the domain provided, which can be used to reach this Origin." - " For example, 'articles/video' => 'www.example.com/articles/video") -@click.option('--ssl', default="dvSan", type=click.Choice(['dvSan', 'wilcard']), help="A DV SAN Certificate allows" - " HTTPS traffic over your personal domain, but it requires a domain validation to prove ownership." - " A wildcard certificate allows HTTPS traffic only when using the CNAME given.") -@environment.pass_env -def cli(env, hostname, origin, origin_type, http, https, bucket_name, cname, header, path, ssl): - """Create a CDN domain mapping.""" - if not http and not https: - raise exceptions.CLIAbort('Is needed http or https options') - - manager = SoftLayer.CDNManager(env.client) - cdn = manager.create_cdn(hostname, origin, origin_type, http, https, bucket_name, cname, header, path, ssl) - - table = formatting.Table(['Name', 'Value']) - table.add_row(['CDN Unique ID', cdn.get('uniqueId')]) - if bucket_name: - table.add_row(['Bucket Name', cdn.get('bucketName')]) - table.add_row(['Hostname', cdn.get('domain')]) - table.add_row(['Header', cdn.get('header')]) - table.add_row(['IBM CNAME', cdn.get('cname')]) - table.add_row(['Akamai CNAME', cdn.get('akamaiCname')]) - table.add_row(['Origin Host', cdn.get('originHost')]) - table.add_row(['Origin Type', cdn.get('originType')]) - table.add_row(['Protocol', cdn.get('protocol')]) - table.add_row(['Http Port', cdn.get('httpPort')]) - table.add_row(['Https Port', cdn.get('httpsPort')]) - table.add_row(['Certificate Type', cdn.get('certificateType')]) - table.add_row(['Provider', cdn.get('vendorName')]) - table.add_row(['Path', cdn.get('path')]) - - env.fout(table) diff --git a/SoftLayer/CLI/cdn/delete.py b/SoftLayer/CLI/cdn/delete.py deleted file mode 100644 index 0dd2e91d6..000000000 --- a/SoftLayer/CLI/cdn/delete.py +++ /dev/null @@ -1,21 +0,0 @@ -"""Delete a CDN domain mapping.""" -# :license: MIT, see LICENSE for more details. - -import click - -import SoftLayer -from SoftLayer.CLI import environment - - -@click.command(cls=SoftLayer.CLI.command.SLCommand, ) -@click.argument('unique_id') -@environment.pass_env -def cli(env, unique_id): - """Delete a CDN domain mapping.""" - - manager = SoftLayer.CDNManager(env.client) - - cdn = manager.delete_cdn(unique_id) - - if cdn: - env.fout(f"Cdn with uniqueId: {unique_id} was deleted.") diff --git a/SoftLayer/CLI/cdn/detail.py b/SoftLayer/CLI/cdn/detail.py deleted file mode 100644 index 973b1acc5..000000000 --- a/SoftLayer/CLI/cdn/detail.py +++ /dev/null @@ -1,46 +0,0 @@ -"""Detail a CDN Account.""" -# :license: MIT, see LICENSE for more details. - -import click - -import SoftLayer -from SoftLayer.CLI import environment -from SoftLayer.CLI import formatting - - -@click.command(cls=SoftLayer.CLI.command.SLCommand, ) -@click.argument('unique_id') -@click.option('--history', - default=30, type=click.IntRange(1, 89), - help='Bandwidth, Hits, Ratio counted over history number of days ago. 89 is the maximum. ') -@environment.pass_env -def cli(env, unique_id, history): - """Detail a CDN Account.""" - - manager = SoftLayer.CDNManager(env.client) - - cdn_mapping = manager.get_cdn(unique_id) - cdn_metrics = manager.get_usage_metrics(unique_id, history=history) - - # usage metrics - total_bandwidth = "%s GB" % cdn_metrics['totals'][0] - total_hits = cdn_metrics['totals'][1] - hit_ratio = "%s %%" % cdn_metrics['totals'][2] - - table = formatting.KeyValueTable(['name', 'value']) - table.align['name'] = 'r' - table.align['value'] = 'l' - - table.add_row(['unique_id', cdn_mapping['uniqueId']]) - table.add_row(['hostname', cdn_mapping['domain']]) - table.add_row(['protocol', cdn_mapping['protocol']]) - table.add_row(['origin', cdn_mapping['originHost']]) - table.add_row(['origin_type', cdn_mapping['originType']]) - table.add_row(['path', cdn_mapping['path']]) - table.add_row(['provider', cdn_mapping['vendorName']]) - table.add_row(['status', cdn_mapping['status']]) - table.add_row(['total_bandwidth', total_bandwidth]) - table.add_row(['total_hits', total_hits]) - table.add_row(['hit_ratio', hit_ratio]) - - env.fout(table) diff --git a/SoftLayer/CLI/cdn/edit.py b/SoftLayer/CLI/cdn/edit.py deleted file mode 100644 index df4f17947..000000000 --- a/SoftLayer/CLI/cdn/edit.py +++ /dev/null @@ -1,93 +0,0 @@ -"""Edit a CDN Account.""" -# :license: MIT, see LICENSE for more details. - -import click - -import SoftLayer -from SoftLayer.CLI import environment -from SoftLayer.CLI import formatting -from SoftLayer.CLI import helpers - - -@click.command(cls=SoftLayer.CLI.command.SLCommand, ) -@click.argument('identifier') -@click.option('--header', '-H', - type=click.STRING, - help="Host header." - ) -@click.option('--http-port', '-t', - type=click.INT, - help="HTTP port." - ) -@click.option('--https-port', '-s', - type=click.INT, - help="HTTPS port." - ) -@click.option('--origin', '-o', - type=click.STRING, - help="Origin server address." - ) -@click.option('--respect-headers', '-r', - type=click.Choice(['1', '0']), - help="Respect headers. The value 1 is On and 0 is Off." - ) -@click.option('--cache', '-c', type=str, - help="Cache key optimization. These are the valid options to choose: 'include-all', 'ignore-all', " - "'include-specified', 'ignore-specified'. If you select 'include-specified' or 'ignore-specified' " - "please add to option --cache-description.\n" - " e.g --cache=include-specified --cache-description=description." - ) -@click.option('--cache-description', '-C', type=str, - help="In cache option, if you select 'include-specified' or 'ignore-specified', " - "please add a description too using this option.\n" - "e.g --cache include-specified --cache-description description." - ) -@click.option('--performance-configuration', '-p', - type=click.Choice(['General web delivery', 'Large file optimization', 'Video on demand optimization']), - help="Optimize for, General web delivery', 'Large file optimization', 'Video on demand optimization', " - "the Dynamic content acceleration option is not added because this has a special configuration." - ) -@environment.pass_env -def cli(env, identifier, header, http_port, https_port, origin, respect_headers, cache, - cache_description, performance_configuration): - """Edit a CDN Account. - - Note: You can use the hostname or uniqueId as IDENTIFIER. - """ - - manager = SoftLayer.CDNManager(env.client) - cdn_id = helpers.resolve_id(manager.resolve_ids, identifier, 'CDN') - - cache_result = {} - if cache or cache_description: - if len(cache) > 1: - cache_result['cacheKeyQueryRule'] = cache - else: - cache_result['cacheKeyQueryRule'] = cache[0] - - cdn_result = manager.edit(cdn_id, header=header, http_port=http_port, https_port=https_port, origin=origin, - respect_headers=respect_headers, cache=cache_result, cache_description=cache_description, - performance_configuration=performance_configuration) - - table = formatting.KeyValueTable(['name', 'value']) - table.align['name'] = 'r' - table.align['value'] = 'l' - - for cdn in cdn_result: - table.add_row(['Create Date', cdn.get('createDate')]) - table.add_row(['Header', cdn.get('header')]) - if cdn.get('httpPort'): - table.add_row(['Http Port', cdn.get('httpPort')]) - if cdn.get('httpsPort'): - table.add_row(['Https Port', cdn.get('httpsPort')]) - table.add_row(['Origin Type', cdn.get('originType')]) - table.add_row(['Performance Configuration', cdn.get('performanceConfiguration')]) - table.add_row(['Protocol', cdn.get('protocol')]) - table.add_row(['Respect Headers', cdn.get('respectHeaders')]) - table.add_row(['Unique Id', cdn.get('uniqueId')]) - table.add_row(['Vendor Name', cdn.get('vendorName')]) - table.add_row(['Cache key optimization', cdn.get('cacheKeyQueryRule')]) - table.add_row(['cname', cdn.get('cname')]) - table.add_row(['Origin server address', cdn.get('originHost')]) - - env.fout(table) diff --git a/SoftLayer/CLI/cdn/list.py b/SoftLayer/CLI/cdn/list.py deleted file mode 100644 index fb269994f..000000000 --- a/SoftLayer/CLI/cdn/list.py +++ /dev/null @@ -1,44 +0,0 @@ -"""List CDN Accounts.""" -# :license: MIT, see LICENSE for more details. - -import click - -import SoftLayer -from SoftLayer.CLI import environment -from SoftLayer.CLI import formatting - - -@click.command(cls=SoftLayer.CLI.command.SLCommand, ) -@click.option('--sortby', - help='Column to sort by', - type=click.Choice(['unique_id', - 'domain', - 'origin', - 'vendor', - 'cname', - 'status'])) -@environment.pass_env -def cli(env, sortby): - """List all CDN accounts.""" - - manager = SoftLayer.CDNManager(env.client) - accounts = manager.list_cdn() - - table = formatting.Table(['unique_id', - 'domain', - 'origin', - 'vendor', - 'cname', - 'status']) - for account in accounts: - table.add_row([ - account['uniqueId'], - account['domain'], - account['originHost'], - account['vendorName'], - account['cname'], - account['status'] - ]) - - table.sortby = sortby - env.fout(table) diff --git a/SoftLayer/CLI/cdn/origin_add.py b/SoftLayer/CLI/cdn/origin_add.py deleted file mode 100644 index 7a77b0260..000000000 --- a/SoftLayer/CLI/cdn/origin_add.py +++ /dev/null @@ -1,106 +0,0 @@ -"""Create an origin pull mapping.""" -# :license: MIT, see LICENSE for more details. - -import click - -import SoftLayer -from SoftLayer.CLI import environment -from SoftLayer.CLI import exceptions -from SoftLayer.CLI import formatting - - -@click.command(cls=SoftLayer.CLI.command.SLCommand, ) -@click.argument('unique_id') -@click.argument('origin') -@click.argument('path') -@click.option('--origin-type', '-t', - type=click.Choice(['server', 'storage']), - help='The origin type.', - default='server', - show_default=True) -@click.option('--header', '-H', - type=click.STRING, - help='The host header to communicate with the origin.') -@click.option('--bucket-name', '-b', - type=click.STRING, - help="The name of the available resource [required if --origin-type=storage]") -@click.option('--http-port', '-p', - type=click.INT, - help="The http port number. [http or https is required]") -@click.option('--https-port', '-s', - type=click.INT, - help="The https port number. [http or https is required]" - ) -@click.option('--protocol', '-P', - type=click.STRING, - help="The protocol used by the origin.", - default='http', - show_default=True) -@click.option('--optimize-for', '-o', - type=click.Choice(['web', 'video', 'file', 'dynamic']), - help="Performance configuration", - default='web', - show_default=True) -@click.option('--dynamic-path', '-d', - help="The path that Akamai edge servers periodically fetch the test object from." - "example = /detection-test-object.html") -@click.option('--compression', '-i', - help="Enable or disable compression of JPEG images for requests over certain network conditions.", - default='true', - show_default=True) -@click.option('--prefetching', '-g', - help="Enable or disable the embedded object prefetching feature.", - default='true', - show_default=True) -@click.option('--extensions', '-e', - type=click.STRING, - help="File extensions that can be stored in the CDN, example: 'jpg, png, pdf'") -@click.option('--cache-query', '-c', - type=click.STRING, - help="Cache query rules with the following formats:\n" - "'ignore-all', 'include: ', 'ignore: '", - default="include-all", - show_default=True) -@environment.pass_env -def cli(env, unique_id, origin, path, origin_type, header, - bucket_name, http_port, https_port, protocol, optimize_for, - dynamic_path, compression, prefetching, - extensions, cache_query): - """Create an origin path for an existing CDN mapping. - - For more information see the following documentation: \n - https://cloud.ibm.com/docs/infrastructure/CDN?topic=CDN-manage-your-cdn#adding-origin-path-details - """ - - manager = SoftLayer.CDNManager(env.client) - - if origin_type == 'storage' and not bucket_name: - raise exceptions.ArgumentError('[-b | --bucket-name] is required when [-t | --origin-type] is "storage"') - - result = manager.add_origin(unique_id, origin, path, dynamic_path, origin_type=origin_type, - header=header, http_port=http_port, https_port=https_port, protocol=protocol, - bucket_name=bucket_name, file_extensions=extensions, - optimize_for=optimize_for, - compression=compression, prefetching=prefetching, - cache_query=cache_query) - - table = formatting.Table(['Item', 'Value']) - table.align['Item'] = 'r' - table.align['Value'] = 'r' - - table.add_row(['CDN Unique ID', result['mappingUniqueId']]) - - if origin_type == 'storage': - table.add_row(['Bucket Name', result['bucketName']]) - - table.add_row(['Origin', result['origin']]) - table.add_row(['Origin Type', result['originType']]) - table.add_row(['Header', result['header']]) - table.add_row(['Path', result['path']]) - table.add_row(['Http Port', result['httpPort']]) - table.add_row(['Https Port', result['httpsPort']]) - table.add_row(['Cache Key Rule', result['cacheKeyQueryRule']]) - table.add_row(['Configuration', result['performanceConfiguration']]) - table.add_row(['Status', result['status']]) - - env.fout(table) diff --git a/SoftLayer/CLI/cdn/origin_list.py b/SoftLayer/CLI/cdn/origin_list.py deleted file mode 100644 index f2dc03082..000000000 --- a/SoftLayer/CLI/cdn/origin_list.py +++ /dev/null @@ -1,28 +0,0 @@ -"""List origin pull mappings.""" -# :license: MIT, see LICENSE for more details. - -import click - -import SoftLayer -from SoftLayer.CLI import environment -from SoftLayer.CLI import formatting - - -@click.command(cls=SoftLayer.CLI.command.SLCommand, ) -@click.argument('unique_id') -@environment.pass_env -def cli(env, unique_id): - """List origin path for an existing CDN mapping.""" - - manager = SoftLayer.CDNManager(env.client) - origins = manager.get_origins(unique_id) - - table = formatting.Table(['Path', 'Origin', 'HTTP Port', 'Status']) - - for origin in origins: - table.add_row([origin['path'], - origin['origin'], - origin['httpPort'], - origin['status']]) - - env.fout(table) diff --git a/SoftLayer/CLI/cdn/origin_remove.py b/SoftLayer/CLI/cdn/origin_remove.py deleted file mode 100644 index a7767b419..000000000 --- a/SoftLayer/CLI/cdn/origin_remove.py +++ /dev/null @@ -1,20 +0,0 @@ -"""Remove an origin pull mapping.""" -# :license: MIT, see LICENSE for more details. - -import click - -import SoftLayer -from SoftLayer.CLI import environment - - -@click.command(cls=SoftLayer.CLI.command.SLCommand, ) -@click.argument('unique_id') -@click.argument('origin_path') -@environment.pass_env -def cli(env, unique_id, origin_path): - """Removes an origin path for an existing CDN mapping.""" - - manager = SoftLayer.CDNManager(env.client) - manager.remove_origin(unique_id, origin_path) - - click.secho("Origin with path %s has been deleted" % origin_path, fg='green') diff --git a/SoftLayer/CLI/cdn/purge.py b/SoftLayer/CLI/cdn/purge.py deleted file mode 100644 index 97bf88319..000000000 --- a/SoftLayer/CLI/cdn/purge.py +++ /dev/null @@ -1,40 +0,0 @@ -"""Purge cached files from all edge nodes.""" -# :license: MIT, see LICENSE for more details. -import datetime - -import click - -import SoftLayer -from SoftLayer.CLI import environment -from SoftLayer.CLI import formatting - - -@click.command(cls=SoftLayer.CLI.command.SLCommand, ) -@click.argument('unique_id') -@click.argument('path') -@environment.pass_env -def cli(env, unique_id, path): - """Creates a purge record and also initiates the purge call. - - Example: - slcli cdn purge 9779455 /article/file.txt - - For more information see the following documentation: \n - https://cloud.ibm.com/docs/infrastructure/CDN?topic=CDN-manage-your-cdn#purging-cached-content - """ - - manager = SoftLayer.CDNManager(env.client) - result = manager.purge_content(unique_id, path) - - table = formatting.Table(['Date', 'Path', 'Saved', 'Status']) - - for data in result: - date = datetime.datetime.fromtimestamp(int(data['date'])) - table.add_row([ - date, - data['path'], - data['saved'], - data['status'] - ]) - - env.fout(table) diff --git a/SoftLayer/CLI/command.py b/SoftLayer/CLI/command.py index 70f5adbc9..b4cbd768c 100644 --- a/SoftLayer/CLI/command.py +++ b/SoftLayer/CLI/command.py @@ -31,6 +31,7 @@ class OptionHighlighter(RegexHighlighter): r"(?PExample::)", r"(?P(file|https|http|ws|wss)://[-0-9a-zA-Z$_+!`(),.?/;:&=%#~]*)" r"(?P^[A-Z]+$)", + r"(?P\(Deprecated\) .*$)" ] diff --git a/SoftLayer/CLI/routes.py b/SoftLayer/CLI/routes.py index 705b2cac6..c2d517e2d 100644 --- a/SoftLayer/CLI/routes.py +++ b/SoftLayer/CLI/routes.py @@ -75,15 +75,15 @@ ('dedicatedhost:list-guests', 'SoftLayer.CLI.dedicatedhost.list_guests:cli'), ('cdn', 'SoftLayer.CLI.cdn'), - ('cdn:detail', 'SoftLayer.CLI.cdn.detail:cli'), - ('cdn:edit', 'SoftLayer.CLI.cdn.edit:cli'), - ('cdn:list', 'SoftLayer.CLI.cdn.list:cli'), - ('cdn:origin-add', 'SoftLayer.CLI.cdn.origin_add:cli'), - ('cdn:origin-list', 'SoftLayer.CLI.cdn.origin_list:cli'), - ('cdn:origin-remove', 'SoftLayer.CLI.cdn.origin_remove:cli'), - ('cdn:purge', 'SoftLayer.CLI.cdn.purge:cli'), - ('cdn:delete', 'SoftLayer.CLI.cdn.delete:cli'), - ('cdn:create', 'SoftLayer.CLI.cdn.create:cli'), + ('cdn:detail', 'SoftLayer.CLI.cdn.cdn:cli'), + ('cdn:edit', 'SoftLayer.CLI.cdn.cdn:cli'), + ('cdn:list', 'SoftLayer.CLI.cdn.cdn:cli'), + ('cdn:origin-add', 'SoftLayer.CLI.cdn.cdn:cli'), + ('cdn:origin-list', 'SoftLayer.CLI.cdn.cdn:cli'), + ('cdn:origin-remove', 'SoftLayer.CLI.cdn.cdn:cli'), + ('cdn:purge', 'SoftLayer.CLI.cdn.cdn:cli'), + ('cdn:delete', 'SoftLayer.CLI.cdn.cdn:cli'), + ('cdn:create', 'SoftLayer.CLI.cdn.cdn:cli'), ('config', 'SoftLayer.CLI.config'), ('config:setup', 'SoftLayer.CLI.config.setup:cli'), diff --git a/SoftLayer/managers/__init__.py b/SoftLayer/managers/__init__.py index 214e1ce62..8a6c8c095 100644 --- a/SoftLayer/managers/__init__.py +++ b/SoftLayer/managers/__init__.py @@ -10,7 +10,6 @@ from SoftLayer.managers.account import AccountManager from SoftLayer.managers.bandwidth import BandwidthManager from SoftLayer.managers.block import BlockStorageManager -from SoftLayer.managers.cdn import CDNManager from SoftLayer.managers.dedicated_host import DedicatedHostManager from SoftLayer.managers.dns import DNSManager from SoftLayer.managers.event_log import EventLogManager @@ -40,7 +39,6 @@ 'BandwidthManager', 'BlockStorageManager', 'CapacityManager', - 'CDNManager', 'DedicatedHostManager', 'DNSManager', 'EventLogManager', diff --git a/SoftLayer/managers/cdn.py b/SoftLayer/managers/cdn.py deleted file mode 100644 index 0f3a26f02..000000000 --- a/SoftLayer/managers/cdn.py +++ /dev/null @@ -1,355 +0,0 @@ -""" - SoftLayer.cdn - ~~~~~~~~~~~~~ - CDN Manager/helpers - - :license: MIT, see LICENSE for more details. -""" -import SoftLayer -from SoftLayer import utils - - -# pylint: disable=too-many-lines,too-many-instance-attributes - - -class CDNManager(utils.IdentifierMixin, object): - """Manage Content Delivery Networks in the account. - - See product information here: - https://www.ibm.com/cloud/cdn - https://cloud.ibm.com/docs/infrastructure/CDN?topic=CDN-about-content-delivery-networks-cdn- - - :param SoftLayer.API.BaseClient client: the client instance - """ - - def __init__(self, client): - self.client = client - self._start_date = None - self._end_date = None - self.cdn_configuration = self.client['Network_CdnMarketplace_Configuration_Mapping'] - self.cdn_path = self.client['SoftLayer_Network_CdnMarketplace_Configuration_Mapping_Path'] - self.cdn_metrics = self.client['Network_CdnMarketplace_Metrics'] - self.cdn_purge = self.client['SoftLayer_Network_CdnMarketplace_Configuration_Cache_Purge'] - self.resolvers = [self._get_ids_from_hostname] - - def list_cdn(self, **kwargs): - """Lists Content Delivery Networks for the active user. - - :param dict \\*\\*kwargs: header-level options (mask, limit, etc.) - :returns: The list of CDN objects in the account - """ - - return self.cdn_configuration.listDomainMappings(**kwargs) - - def get_cdn(self, unique_id, **kwargs): - """Retrieves the information about the CDN account object. - - :param str unique_id: The unique ID associated with the CDN. - :param dict \\*\\*kwargs: header-level option (mask) - :returns: The CDN object - """ - - cdn_list = self.cdn_configuration.listDomainMappingByUniqueId(unique_id, **kwargs) - - # The method listDomainMappingByUniqueId() returns an array but there is only 1 object - return cdn_list[0] - - def get_origins(self, unique_id, **kwargs): - """Retrieves list of origin pull mappings for a specified CDN account. - - :param str unique_id: The unique ID associated with the CDN. - :param dict \\*\\*kwargs: header-level options (mask, limit, etc.) - :returns: The list of origin paths in the CDN object. - """ - - return self.cdn_path.listOriginPath(unique_id, **kwargs) - - def add_origin(self, unique_id, origin, path, dynamic_path, origin_type="server", header=None, - http_port=80, https_port=None, protocol='http', bucket_name=None, file_extensions=None, - optimize_for="web", compression=None, prefetching=None, - cache_query="include all"): - """Creates an origin path for an existing CDN. - - :param str unique_id: The unique ID associated with the CDN. - :param str path: relative path to the domain provided, e.g. "/articles/video" - :param str dynamic_path: The path that Akamai edge servers periodically fetch the test object from. - example = /detection-test-object.html - :param str origin: ip address or hostname if origin_type=server, API endpoint for - your S3 object storage if origin_type=storage - :param str origin_type: it can be 'server' or 'storage' types. - :param str header: the edge server uses the host header to communicate with the origin. - It defaults to hostname. (optional) - :param int http_port: the http port number (default: 80) - :param int https_port: the https port number - :param str protocol: the protocol of the origin (default: HTTP) - :param str bucket_name: name of the available resource - :param str file_extensions: file extensions that can be stored in the CDN, e.g. "jpg,png" - :param str optimize_for: performance configuration, available options: web, video, and file where: - - - 'web' = 'General web delivery' - - 'video' = 'Video on demand optimization' - - 'file' = 'Large file optimization' - - 'dynamic' = 'Dynamic content acceleration' - :param bool compression: Enable or disable compression of JPEG images for requests over - certain network conditions. - :param bool prefetching: Enable or disable the embedded object prefetching feature. - :param str cache_query: rules with the following formats: 'include-all', 'ignore-all', - 'include: space separated query-names', - 'ignore: space separated query-names'.' - :return: a CDN origin path object - """ - types = {'server': 'HOST_SERVER', 'storage': 'OBJECT_STORAGE'} - performance_config = { - 'web': 'General web delivery', - 'video': 'Video on demand optimization', - 'file': 'Large file optimization', - "dynamic": "Dynamic content acceleration" - } - - new_origin = { - 'uniqueId': unique_id, - 'path': path, - 'origin': origin, - 'originType': types.get(origin_type), - 'httpPort': http_port, - 'httpsPort': https_port, - 'protocol': protocol.upper(), - 'performanceConfiguration': performance_config.get(optimize_for), - 'cacheKeyQueryRule': cache_query, - } - - if optimize_for == 'dynamic': - new_origin['dynamicContentAcceleration'] = { - 'detectionPath': "/" + str(dynamic_path), - 'prefetchEnabled': bool(prefetching), - 'mobileImageCompressionEnabled': bool(compression) - } - - if header: - new_origin['header'] = header - - if types.get(origin_type) == 'OBJECT_STORAGE': - if bucket_name: - new_origin['bucketName'] = bucket_name - - if file_extensions: - new_origin['fileExtension'] = file_extensions - - origin = self.cdn_path.createOriginPath(new_origin) - - # The method createOriginPath() returns an array but there is only 1 object - return origin[0] - - def remove_origin(self, unique_id, path): - """Removes an origin pull mapping with the given origin pull ID. - - :param str unique_id: The unique ID associated with the CDN. - :param str path: The origin path to delete. - :returns: A string value - """ - - return self.cdn_path.deleteOriginPath(unique_id, path) - - def purge_content(self, unique_id, path): - """Purges a URL or path from the CDN. - - :param str unique_id: The unique ID associated with the CDN. - :param str path: A string of url or path that should be purged. - :returns: A Container_Network_CdnMarketplace_Configuration_Cache_Purge array object - """ - return self.cdn_purge.createPurge(unique_id, path) - - def get_usage_metrics(self, unique_id, history=30, frequency="aggregate"): - """Retrieves the cdn usage metrics. - - It uses the 'days' argument if start_date and end_date are None. - - :param int unique_id: The CDN uniqueId from which the usage metrics will be obtained. - :param int history: Last N days, default days is 30. - :param str frequency: It can be day, week, month and aggregate. The default is "aggregate". - :returns: A Container_Network_CdnMarketplace_Metrics object - """ - - _start = utils.days_to_datetime(history) - _end = utils.days_to_datetime(0) - - self._start_date = utils.timestamp(_start) - self._end_date = utils.timestamp(_end) - - usage = self.cdn_metrics.getMappingUsageMetrics(unique_id, self._start_date, self._end_date, frequency) - - # The method getMappingUsageMetrics() returns an array but there is only 1 object - return usage[0] - - @property - def start_data(self): - """Retrieve the cdn usage metric start date.""" - return self._start_date - - @property - def end_date(self): - """Retrieve the cdn usage metric end date.""" - return self._end_date - - def edit(self, identifier, header=None, http_port=None, https_port=None, origin=None, - respect_headers=None, cache=None, cache_description=None, performance_configuration=None): - """Edit the cdn object. - - :param string identifier: The CDN identifier. - :param header: The cdn Host header. - :param http_port: The cdn HTTP port. - :param https_port: The cdn HTTPS port. - :param origin: The cdn Origin server address. - :param respect_headers: The cdn Respect headers. - :param cache: The cdn Cache key optimization. - :param performance_configuration: The cdn performance configuration. - - :returns: SoftLayer_Container_Network_CdnMarketplace_Configuration_Mapping[]. - """ - cdn_instance_detail = self.get_cdn(str(identifier)) - - config = { - 'uniqueId': cdn_instance_detail.get('uniqueId'), - 'originType': cdn_instance_detail.get('originType'), - 'protocol': cdn_instance_detail.get('protocol'), - 'path': cdn_instance_detail.get('path'), - 'vendorName': cdn_instance_detail.get('vendorName'), - 'cname': cdn_instance_detail.get('cname'), - 'domain': cdn_instance_detail.get('domain'), - 'origin': cdn_instance_detail.get('originHost'), - 'header': cdn_instance_detail.get('header') - } - if cdn_instance_detail.get('httpPort'): - config['httpPort'] = cdn_instance_detail.get('httpPort') - - if cdn_instance_detail.get('httpsPort'): - config['httpsPort'] = cdn_instance_detail.get('httpsPort') - - if header: - config['header'] = header - - if http_port: - config['httpPort'] = http_port - - if https_port: - config['httpsPort'] = https_port - - if origin: - config['origin'] = origin - - if respect_headers: - config['respectHeaders'] = respect_headers - - if cache or cache_description: - if 'include-specified' in cache['cacheKeyQueryRule']: - cache_key_rule = self.get_cache_key_query_rule('include', cache_description) - config['cacheKeyQueryRule'] = cache_key_rule - elif 'ignore-specified' in cache['cacheKeyQueryRule']: - cache_key_rule = self.get_cache_key_query_rule('ignore', cache_description) - config['cacheKeyQueryRule'] = cache_key_rule - else: - config['cacheKeyQueryRule'] = cache['cacheKeyQueryRule'] - - if performance_configuration: - config['performanceConfiguration'] = performance_configuration - - return self.cdn_configuration.updateDomainMapping(config) - - def _get_ids_from_hostname(self, hostname): - """Get the cdn object detail. - - :param string hostname: The CDN identifier. - :returns: SoftLayer_Container_Network_CdnMarketplace_Configuration_Mapping[]. - """ - result = [] - cdn_list = self.cdn_configuration.listDomainMappings() - for cdn in cdn_list: - if cdn.get('domain', '').lower() == hostname.lower(): - result.append(cdn.get('uniqueId')) - break - - return result - - @staticmethod - def get_cache_key_query_rule(cache_type, cache_description): - """Get the cdn object detail. - - :param string cache_type: Cache type. - :param cache: Cache description. - - :return: string value. - """ - if cache_description is None: - raise SoftLayer.SoftLayerError('Please add a description to be able to update the' - ' cache.') - cache_result = '%s: %s' % (cache_type, cache_description) - - return cache_result - - def delete_cdn(self, unique_id): - """Delete CDN domain mapping for a particular customer. - - :param str unique_id: The unique ID associated with the CDN. - :returns: The cdn that is being deleted. - """ - - return self.cdn_configuration.deleteDomainMapping(unique_id) - - def create_cdn(self, hostname=None, origin=None, origin_type=None, http=None, https=None, bucket_name=None, - cname=None, header=None, path=None, ssl=None): - """Create CDN domain mapping for a particular customer. - - :param str hostname: The unique ID associated with the CDN. - :param str origin: ip address or hostname if origin_type=server, API endpoint for - your S3 object storage if origin_type=storage - :param str origin_type: it can be 'server' or 'storage' types. - :param int http: http port - :param int https: https port - :param str bucket_name: name of the available resource - :param str cname: globally unique subdomain - :param str header: the edge server uses the host header to communicate with the origin. - It defaults to hostname. (optional) - :param str path: relative path to the domain provided, e.g. "/articles/video" - :param str ssl: ssl certificate - :returns: The cdn that is being created. - """ - types = {'server': 'HOST_SERVER', 'storage': 'OBJECT_STORAGE'} - ssl_certificate = {'wilcard': 'WILDCARD_CERT', 'dvSan': 'SHARED_SAN_CERT'} - - new_origin = { - 'domain': hostname, - 'origin': origin, - 'originType': types.get(origin_type), - 'vendorName': 'akamai', - } - - protocol = '' - if http: - protocol = 'HTTP' - new_origin['httpPort'] = http - if https: - protocol = 'HTTPS' - new_origin['httpsPort'] = https - new_origin['certificateType'] = ssl_certificate.get(ssl) - if http and https: - protocol = 'HTTP_AND_HTTPS' - - new_origin['protocol'] = protocol - - if types.get(origin_type) == 'OBJECT_STORAGE': - new_origin['bucketName'] = bucket_name - new_origin['header'] = header - - if cname: - new_origin['cname'] = cname + '.cdn.appdomain.cloud' - - if header: - new_origin['header'] = header - - if path: - new_origin['path'] = '/' + path - - origin = self.cdn_configuration.createDomainMapping(new_origin) - - # The method createOriginPath() returns an array but there is only 1 object - return origin[0] diff --git a/SoftLayer/utils.py b/SoftLayer/utils.py index 4e1cb8636..5258234dd 100644 --- a/SoftLayer/utils.py +++ b/SoftLayer/utils.py @@ -521,6 +521,7 @@ def console_color_themes(theme): "option_choices": "gold3", "example_block": "underline deep_pink3", "url": "underline blue", + "deprecated": "underline red", }) ) return Console(theme=Theme( @@ -540,6 +541,7 @@ def console_color_themes(theme): "option_choices": "gold3", "example_block": "underline light_coral", "url": "underline blue", + "deprecated": "underline red", }) ) diff --git a/docs/cli/cdn.rst b/docs/cli/cdn.rst index de9e7c6f7..945e49e07 100644 --- a/docs/cli/cdn.rst +++ b/docs/cli/cdn.rst @@ -4,38 +4,47 @@ Interacting with CDN ===================== -.. click:: SoftLayer.CLI.cdn.detail:cli +.. click:: SoftLayer.CLI.cdn.cdn:cli + :prog: cdn list + :show-nested: + DEPRECATED https://cloud.ibm.com/docs/CDN?topic=CDN-cdn-deprecation + +.. click:: SoftLayer.CLI.cdn.cdn:cli :prog: cdn detail :show-nested: + DEPRECATED https://cloud.ibm.com/docs/CDN?topic=CDN-cdn-deprecation -.. click:: SoftLayer.CLI.cdn.list:cli - :prog: cdn list +.. click:: SoftLayer.CLI.cdn.cdn:cli + :prog: cdn edit :show-nested: + DEPRECATED https://cloud.ibm.com/docs/CDN?topic=CDN-cdn-deprecation -.. click:: SoftLayer.CLI.cdn.origin_add:cli +.. click:: SoftLayer.CLI.cdn.cdn:cli :prog: cdn origin-add :show-nested: + DEPRECATED https://cloud.ibm.com/docs/CDN?topic=CDN-cdn-deprecation -.. click:: SoftLayer.CLI.cdn.origin_list:cli +.. click:: SoftLayer.CLI.cdn.cdn:cli :prog: cdn origin-list :show-nested: + DEPRECATED https://cloud.ibm.com/docs/CDN?topic=CDN-cdn-deprecation -.. click:: SoftLayer.CLI.cdn.origin_remove:cli +.. click:: SoftLayer.CLI.cdn.cdn:cli :prog: cdn origin-remove :show-nested: + DEPRECATED https://cloud.ibm.com/docs/CDN?topic=CDN-cdn-deprecation -.. click:: SoftLayer.CLI.cdn.purge:cli +.. click:: SoftLayer.CLI.cdn.cdn:cli :prog: cdn purge :show-nested: + DEPRECATED https://cloud.ibm.com/docs/CDN?topic=CDN-cdn-deprecation -.. click:: SoftLayer.CLI.cdn.edit:cli - :prog: cdn edit - :show-nested: - -.. click:: SoftLayer.CLI.cdn.delete:cli +.. click:: SoftLayer.CLI.cdn.cdn:cli :prog: cdn delete :show-nested: + DEPRECATED https://cloud.ibm.com/docs/CDN?topic=CDN-cdn-deprecation -.. click:: SoftLayer.CLI.cdn.create:cli +.. click:: SoftLayer.CLI.cdn.cdn:cli :prog: cdn create - :show-nested: \ No newline at end of file + :show-nested: + DEPRECATED https://cloud.ibm.com/docs/CDN?topic=CDN-cdn-deprecation \ No newline at end of file diff --git a/tests/CLI/modules/cdn_tests.py b/tests/CLI/modules/cdn_tests.py deleted file mode 100644 index f10bafe7b..000000000 --- a/tests/CLI/modules/cdn_tests.py +++ /dev/null @@ -1,186 +0,0 @@ -""" - SoftLayer.tests.CLI.modules.cdn_tests - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - :license: MIT, see LICENSE for more details. -""" -import datetime -import json -from unittest import mock as mock - -from SoftLayer.CLI import exceptions -from SoftLayer import testing - - -class CdnTests(testing.TestCase): - - def test_list_accounts(self): - result = self.run_command(['cdn', 'list']) - - self.assert_no_fail(result) - self.assertEqual(json.loads(result.output), - [{'cname': 'cdnakauuiet7s6u6.cdnedge.bluemix.net', - 'domain': 'test.example.com', - 'origin': '1.1.1.1', - 'status': 'CNAME_CONFIGURATION', - 'unique_id': '11223344', - 'vendor': 'akamai'}] - ) - - @mock.patch('SoftLayer.utils.days_to_datetime') - def test_detail_account(self, mock_now): - mock_now.return_value = datetime.datetime(2020, 1, 1) - result = self.run_command(['cdn', 'detail', '--history=30', '1245']) - - self.assert_no_fail(result) - api_results = json.loads(result.output) - self.assertEqual(api_results['hit_ratio'], '2.0 %') - self.assertEqual(api_results['total_bandwidth'], '1.0 GB') - self.assertEqual(api_results['total_hits'], 3) - self.assertEqual(api_results['hostname'], 'test.example.com') - self.assertEqual(api_results['protocol'], 'HTTP') - - def test_purge_content(self): - result = self.run_command(['cdn', 'purge', '1234', - '/article/file.txt']) - - self.assert_no_fail(result) - - def test_list_origins(self): - result = self.run_command(['cdn', 'origin-list', '1234']) - - self.assert_no_fail(result) - self.assertEqual(json.loads(result.output), [{'HTTP Port': 80, - 'Origin': '10.10.10.1', - 'Path': '/example', - 'Status': 'RUNNING'}, - {'HTTP Port': 80, - 'Origin': '10.10.10.1', - 'Path': '/example1', - 'Status': 'RUNNING'}]) - - def test_add_origin_server(self): - result = self.run_command( - ['cdn', 'origin-add', '-t', 'server', '-H=test.example.com', '-p', 80, '-o', 'web', '-c=include-all', - '1234', '10.10.10.1', '/example/videos2']) - - self.assert_no_fail(result) - - def test_add_origin_server_dynamic(self): - result = self.run_command( - ['cdn', 'origin-add', '-t', 'server', '-H=test.example.com', '-s', 81, '-o', 'dynamic', '-c=include-all', - '-P', 'HTTPS', '-d', 'abc.html', '-g', True, '-i', True, '1234', '10.10.10.1', '/example/videos2', ]) - - self.assert_no_fail(result) - - def test_add_origin_storage(self): - result = self.run_command(['cdn', 'origin-add', '-t', 'storage', '-b=test-bucket', '-H=test.example.com', - '-p', 80, '-o', 'web', '-c=include-all', '1234', '10.10.10.1', '/example/videos2']) - - self.assert_no_fail(result) - - def test_add_origin_storage_dynamic(self): - result = self.run_command(['cdn', 'origin-add', '-t', 'storage', '-b=test-bucket', '-H=test.example.com', - '-s', 81, '-o', 'dynamic', '-c=include-all', '1234', '10.10.10.1', - '/example/videos2', '-g', True, '-i', True]) - - self.assert_no_fail(result) - - def test_add_origin_without_storage(self): - result = self.run_command(['cdn', 'origin-add', '-t', 'storage', '-H=test.example.com', '-p', 80, - '-P', 'HTTPS', '-o', 'web', '-c=include-all', - '1234', '10.10.10.1', '/example/videos2']) - - self.assertEqual(result.exit_code, 2) - self.assertIsInstance(result.exception, exceptions.ArgumentError) - - def test_add_origin_storage_with_file_extensions(self): - result = self.run_command( - ['cdn', 'origin-add', '-t', 'storage', '-b=test-bucket', '-e', 'jpg', '-H=test.example.com', '-p', 80, - '-o', 'web', '-c=include-all', '1234', '10.10.10.1', '/example/videos2']) - - self.assert_no_fail(result) - - def test_add_origin_storage_with_file_extensions_dynamic(self): - result = self.run_command( - ['cdn', 'origin-add', '-t', 'storage', '-b=test-bucket', '-e', 'jpg', '-H=test.example.com', '-s', 81, - '-P', 'HTTPS', '-o', 'dynamic', '-d', 'abc.html', '-g', True, '-i', True, - '-c=include-all', '1234', '10.10.10.1', '/example/videos2', - ]) - - self.assert_no_fail(result) - - def test_remove_origin(self): - result = self.run_command(['cdn', 'origin-remove', '1234', - '/example1']) - - self.assert_no_fail(result) - self.assertEqual(result.output, "Origin with path /example1 has been deleted\n") - - def test_edit_header(self): - result = self.run_command(['cdn', 'edit', 'test.example.com', '--header=www.test.com']) - self.assert_no_fail(result) - header_result = json.loads(result.output) - self.assertEqual('www.test.com', header_result['Header']) - - def test_edit_http_port(self): - result = self.run_command(['cdn', 'edit', 'test.example.com', '--http-port=83']) - self.assert_no_fail(result) - header_result = json.loads(result.output) - self.assertEqual(83, header_result['Http Port']) - - def test_edit_respect_headers(self): - result = self.run_command(['cdn', 'edit', 'test.example.com', '--respect-headers=1']) - self.assert_no_fail(result) - header_result = json.loads(result.output) - self.assertEqual(True, header_result['Respect Headers']) - - def test_edit_cache(self): - result = self.run_command(['cdn', 'edit', 'test.example.com', '--cache', 'include-specified', - '--cache', 'test']) - self.assert_no_fail(result) - header_result = json.loads(result.output) - self.assertEqual('include: test', header_result['Cache key optimization']) - - def test_edit_cache_by_uniqueId(self): - result = self.run_command(['cdn', 'edit', '11223344', '--cache', 'include-specified', '--cache', 'test']) - self.assert_no_fail(result) - header_result = json.loads(result.output) - self.assertEqual('include: test', header_result['Cache key optimization']) - - def test_delete_cdn(self): - result = self.run_command(['cdn', 'delete', '123456']) - self.assert_no_fail(result) - self.assertIn("Cdn with uniqueId: 123456 was deleted.", result.output) - - def test_create_cdn(self): - result = self.run_command(['cdn', 'create', '--hostname', 'www.example.com', - '--origin', '123.123.123.123', '--http', '80']) - self.assert_no_fail(result) - self.assertIn("CDN Unique ID", result.output) - self.assertIn("354034879028850", result.output) - self.assertIn("Hostname", result.output) - self.assertIn("test.com", result.output) - self.assertIn("header", result.output) - self.assertIn("header.test.com", result.output) - self.assertIn("Http Port", result.output) - self.assertIn("80", result.output) - self.assertIn("Path", result.output) - self.assertIn("/*", result.output) - - def test_create_cdn_without_hostname(self): - result = self.run_command(['cdn', 'create']) - self.assertEqual(2, result.exit_code) - print(result.output) - self.assertIn("Error: Missing option '--hostname'.", result.output) - - def test_create_cdn_without_origin(self): - result = self.run_command(['cdn', 'create', '--hostname', 'www.example.com']) - self.assertEqual(2, result.exit_code) - print(result.output) - self.assertIn("Error: Missing option '--origin'.", result.output) - - def test_create_cdn_without_http_or_https(self): - result = self.run_command(['cdn', 'create', '--hostname', 'www.example.com', '--origin', '123.123.123.123']) - self.assertEqual(2, result.exit_code) - self.assertIn("Is needed http or https options", result.exception.message) diff --git a/tests/functional_tests.py b/tests/functional_tests.py index dc67e29f1..c6f6b71b6 100644 --- a/tests/functional_tests.py +++ b/tests/functional_tests.py @@ -8,7 +8,6 @@ import SoftLayer from SoftLayer import testing -from SoftLayer import transports class FunctionalTest(testing.TestCase): @@ -34,23 +33,6 @@ def test_failed_auth(self): SoftLayer.SoftLayerAPIError, client['SoftLayer_User_Customer'].getPortalLoginToken) - def test_no_hostname(self): - try: - request = transports.Request() - request.service = 'SoftLayer_Account' - request.method = 'getObject' - request.id = 1234 - - # This test will fail if 'notvalidsoftlayer.com' becomes a thing - transport = transports.XmlRpcTransport( - endpoint_url='http://notvalidsoftlayer.com', - ) - transport(request) - except SoftLayer.TransportError as ex: - self.assertEqual(ex.faultCode, 0) - else: - self.fail('Transport Error Exception Not Raised') - class AuthedUser(FunctionalTest): def test_service_does_not_exist(self): diff --git a/tests/managers/cdn_tests.py b/tests/managers/cdn_tests.py deleted file mode 100644 index 71dcf737d..000000000 --- a/tests/managers/cdn_tests.py +++ /dev/null @@ -1,187 +0,0 @@ -""" - SoftLayer.tests.managers.cdn_tests - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - :license: MIT, see LICENSE for more details. -""" -import datetime -from unittest import mock as mock - -from SoftLayer import fixtures -from SoftLayer.managers import cdn -from SoftLayer import testing - - -class CDNTests(testing.TestCase): - - def set_up(self): - self.cdn_client = cdn.CDNManager(self.client) - - def test_list_accounts(self): - self.cdn_client.list_cdn() - self.assert_called_with('SoftLayer_Network_CdnMarketplace_Configuration_Mapping', - 'listDomainMappings') - - def test_detail_cdn(self): - self.cdn_client.get_cdn("12345") - - args = ("12345",) - self.assert_called_with('SoftLayer_Network_CdnMarketplace_Configuration_Mapping', - 'listDomainMappingByUniqueId', - args=args) - - @mock.patch('SoftLayer.utils.days_to_datetime') - def test_detail_usage_metric(self, mock_now): - mock_now.return_value = datetime.datetime(2020, 1, 1) - self.cdn_client.get_usage_metrics(12345, history=30, frequency="aggregate") - - args = (12345, - self.cdn_client.start_data, - self.cdn_client.end_date, - "aggregate") - self.assert_called_with('SoftLayer_Network_CdnMarketplace_Metrics', - 'getMappingUsageMetrics', - args=args) - - # Does this still work in 2038 ? https://github.com/softlayer/softlayer-python/issues/1764 for context - @mock.patch('SoftLayer.utils.days_to_datetime') - def test_detail_usage_metric_future(self, mock_now): - mock_now.return_value = datetime.datetime(2040, 1, 1) - self.assertRaises( - OverflowError, - self.cdn_client.get_usage_metrics, 12345, history=30, frequency="aggregate" - ) - - def test_get_origins(self): - self.cdn_client.get_origins("12345") - self.assert_called_with('SoftLayer_Network_CdnMarketplace_Configuration_Mapping_Path', - 'listOriginPath') - - def test_add_origin(self): - self.cdn_client.add_origin("12345", "10.10.10.1", "/example/videos", dynamic_path="abc.html", - origin_type="server", header="test.example.com", https_port=81, - protocol='https', optimize_for="dynamic", compression=True, - prefetching=True, cache_query="include all") - - args = ({ - 'uniqueId': "12345", - 'origin': '10.10.10.1', - 'path': '/example/videos', - 'originType': 'HOST_SERVER', - 'header': 'test.example.com', - 'httpPort': 80, - 'httpsPort': 81, - 'protocol': 'HTTPS', - 'performanceConfiguration': 'Dynamic content acceleration', - 'cacheKeyQueryRule': "include all", - 'dynamicContentAcceleration': { - 'detectionPath': "/abc.html", - 'prefetchEnabled': True, - 'mobileImageCompressionEnabled': True - } - },) - self.assert_called_with('SoftLayer_Network_CdnMarketplace_Configuration_Mapping_Path', - 'createOriginPath', - args=args) - - def test_add_origin_with_bucket_and_file_extension(self): - self.cdn_client.add_origin("12345", "10.10.10.1", "/example/videos", dynamic_path="abc.html", - origin_type="server", header="test.example.com", https_port=81, - protocol='https', optimize_for="dynamic", compression=True, - prefetching=True, cache_query="include all") - - args = ({ - 'uniqueId': "12345", - 'origin': '10.10.10.1', - 'path': '/example/videos', - 'originType': 'HOST_SERVER', - 'header': 'test.example.com', - 'httpPort': 80, - 'httpsPort': 81, - 'protocol': 'HTTPS', - 'performanceConfiguration': 'Dynamic content acceleration', - 'cacheKeyQueryRule': "include all", - 'dynamicContentAcceleration': { - 'detectionPath': "/abc.html", - 'prefetchEnabled': True, - 'mobileImageCompressionEnabled': True - } - },) - self.assert_called_with('SoftLayer_Network_CdnMarketplace_Configuration_Mapping_Path', - 'createOriginPath', - args=args) - - def test_remove_origin(self): - self.cdn_client.remove_origin("12345", "/example1") - - args = ("12345", - "/example1") - self.assert_called_with('SoftLayer_Network_CdnMarketplace_Configuration_Mapping_Path', - 'deleteOriginPath', - args=args) - - def test_purge_content(self): - self.cdn_client.purge_content("12345", "/example1") - - args = ("12345", - "/example1") - self.assert_called_with('SoftLayer_Network_CdnMarketplace_Configuration_Cache_Purge', - 'createPurge', - args=args) - - def test_cdn_edit(self): - identifier = '11223344' - header = 'www.test.com' - result = self.cdn_client.edit(identifier, header=header) - - self.assertEqual(fixtures.SoftLayer_Network_CdnMarketplace_Configuration_Mapping. - updateDomainMapping, result) - - self.assert_called_with( - 'SoftLayer_Network_CdnMarketplace_Configuration_Mapping', - 'updateDomainMapping', - args=({ - 'uniqueId': '11223344', - 'originType': 'HOST_SERVER', - 'protocol': 'HTTP', - 'path': '/', - 'vendorName': 'akamai', - 'cname': 'cdnakauuiet7s6u6.cdnedge.bluemix.net', - 'domain': 'test.example.com', - 'httpPort': 80, - 'header': 'www.test.com', - 'origin': '1.1.1.1' - },) - ) - - def test_cdn_instance_by_hostname(self): - hostname = 'test.example.com' - result = self.cdn_client._get_ids_from_hostname(hostname) - expected_result = fixtures.SoftLayer_Network_CdnMarketplace_Configuration_Mapping.listDomainMappings - self.assertEqual(expected_result[0]['uniqueId'], result[0]) - self.assert_called_with( - 'SoftLayer_Network_CdnMarketplace_Configuration_Mapping', - 'listDomainMappings',) - - def test_delete_cdn(self): - uniqueId = "123465" - self.cdn_client.delete_cdn(uniqueId) - - args = (uniqueId,) - - self.assert_called_with('SoftLayer_Network_CdnMarketplace_Configuration_Mapping', - 'deleteDomainMapping', - args=args) - - def test_create_cdn(self): - hostname = "test.com" - origin = "123.123.123.123" - origin_type = "server" - http = 80 - newCdn = ({"domain": hostname, "origin": origin, "originType": "HOST_SERVER", - "vendorName": "akamai", "httpPort": http, "protocol": "HTTP"},) - self.cdn_client.create_cdn(hostname, origin, origin_type, http) - - self.assert_called_with('SoftLayer_Network_CdnMarketplace_Configuration_Mapping', - 'createDomainMapping', - args=newCdn) diff --git a/tests/transports/rest_tests.py b/tests/transports/rest_tests.py index 20186e95f..c54d28a0f 100644 --- a/tests/transports/rest_tests.py +++ b/tests/transports/rest_tests.py @@ -7,7 +7,6 @@ import json import requests from unittest import mock as mock -import warnings import SoftLayer from SoftLayer import testing @@ -100,16 +99,6 @@ def test_json_error(self, request): req.method = 'Resource' self.assertRaises(SoftLayer.SoftLayerAPIError, self.transport, req) - def test_proxy_without_protocol(self): - req = transports.Request() - req.service = 'SoftLayer_Service' - req.method = 'Resource' - req.proxy = 'localhost:3128' - try: - self.assertRaises(SoftLayer.TransportError, self.transport, req) - except AssertionError: - warnings.warn("AssertionError raised instead of a SoftLayer.TransportError error") - @mock.patch('SoftLayer.transports.rest.requests.Session.request') def test_valid_proxy(self, request): request().text = '{}' diff --git a/tests/transports/xmlrpc_tests.py b/tests/transports/xmlrpc_tests.py index 051e13822..718a51ca2 100644 --- a/tests/transports/xmlrpc_tests.py +++ b/tests/transports/xmlrpc_tests.py @@ -6,7 +6,6 @@ """ import io from unittest import mock as mock -import warnings import pytest import requests @@ -83,18 +82,6 @@ def test_call(self, request): self.assertIsInstance(resp, transports.SoftLayerListResult) self.assertEqual(resp.total_count, 10) - def test_proxy_without_protocol(self): - req = transports.Request() - req.service = 'SoftLayer_Service' - req.method = 'Resource' - req.proxy = 'localhost:3128' - - try: - self.assertRaises(SoftLayer.TransportError, self.transport, req) - except AssertionError: - warnings.warn("Incorrect Exception raised. Expected a " - "SoftLayer.TransportError error") - @mock.patch('SoftLayer.transports.xmlrpc.requests.Session.request') def test_valid_proxy(self, request): request.return_value = self.response