Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions oks_cli/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ def _create_cluster(project_name, cluster_config, output):
@click.option('--cp-multi-az', '-m', is_flag=True, help="Enable control plane multi AZ")
@click.option('--dry-run', is_flag=True, help="Client dry-run, only print the object that would be sent, without sending it")
@click.option('--output', '-o', type=click.Choice(["json", "yaml"]), help="Specify output format, by default is json")
@click.option('--filename', '-f', type=click.File("r"), help="Path to file to use to create the cluster ")
@click.option('--filename', '-f', type=click.File("rb"), help="Path to file to use to create the cluster ")
@click.option('--profile', help="Configuration profile to use", shell_complete=profile_completer)
@click.option('--set', 'set_fields', multiple=True, help="Set arbitrary nested fields, e.g. auth.oidc.issuer-url=value")
@click.pass_context
Expand Down Expand Up @@ -479,7 +479,7 @@ def cluster_create_command(ctx, project_name, cluster_name, description, admin,
@click.option('--control-plane', shell_complete=shell_completions, help="Controlplane plan")
@click.option('--dry-run', is_flag=True, help="Client dry-run, only print the object that would be sent, without sending it")
@click.option('--output', '-o', type=click.Choice(["json", "yaml"]), help="Specify output format, by default is json")
@click.option('--filename', '-f', type=click.File("r"), help="Path to file to use to update the cluster ")
@click.option('--filename', '-f', type=click.File("rb"), help="Path to file to use to update the cluster ")
@click.option('--profile', help="Configuration profile to use", shell_complete=profile_completer)
@click.option('--set', 'set_fields', multiple=True, help="Set arbitrary nested fields, e.g. auth.oidc.issuer-url=value")
@click.pass_context
Expand Down Expand Up @@ -822,7 +822,7 @@ def nodepool_list(ctx):
@click.option('--zone', '-z', multiple=True, help="Provide zone(s)")
@click.option('--output', '-o', type=click.Choice(["json", "yaml"]), help="Specify output format, by default is json")
@click.option('--dry-run', is_flag=True, help="Run without any action")
@click.option('--filename', '-f', type=click.File("r"), help="Path to file to use to create the Nodepool")
@click.option('--filename', '-f', type=click.File("rb"), help="Path to file to use to create the Nodepool")
@click.pass_context
def setup_worker_pool(ctx, nodepool_name, count, vmtype, zone, output, dry_run, filename):
"""Create a new nodepool in the cluster, optionally from a file or parameters."""
Expand Down
2 changes: 1 addition & 1 deletion oks_cli/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def project_list(ctx, project_name, deleted, plain, msword, uuid, watch, output,
@click.option('--disable-api-termination', type=click.BOOL, help="Disable delete action by API")
@click.option('--dry-run', is_flag=True, help="Client dry-run, only print the object that would be sent, without sending it")
@click.option('--output', '-o', type=click.Choice(["json", "yaml", "silent"]), help="Specify output format, by default is json")
@click.option('--filename', '-f', type=click.File("r"), help="Path to file to use to create the project")
@click.option('--filename', '-f', type=click.File("rb"), help="Path to file to use to create the project")
@click.option('--profile', help="Configuration profile to use", shell_complete=profile_completer)
@click.option('--set', 'set_fields', multiple=True, help="Set arbitrary nested fields, e.g. auth.oidc.issuer-url=value")
@click.pass_context
Expand Down
10 changes: 10 additions & 0 deletions oks_cli/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import click
import codecs
import os
import subprocess
import logging
Expand Down Expand Up @@ -753,6 +754,15 @@ def remove_jwt_token(token_type):

def detect_and_parse_input(input_data):
"""Parse input as JSON or YAML; raise error if invalid."""
if isinstance(input_data, bytes):
try:
if input_data.startswith((codecs.BOM_UTF16_LE, codecs.BOM_UTF16_BE)):
input_data = input_data.decode("utf-16")
else:
input_data = input_data.decode("utf-8-sig")
except UnicodeDecodeError:
raise click.BadParameter("Input file is neither valid JSON nor YAML.")

try:
return json.loads(input_data)
except json.JSONDecodeError:
Expand Down
Loading