mik-laj commented on a change in pull request #4530: [AIRFLOW-3282] Implement Azure Kubernetes Service Operator URL: https://github.com/apache/airflow/pull/4530#discussion_r249239186
########## File path: airflow/contrib/utils/aks_utils.py ########## @@ -0,0 +1,92 @@ +# -*- coding: utf-8 -*- +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import sys +import json +import re +from cryptography.hazmat.backends import default_backend +from cryptography.hazmat.primitives.asymmetric import rsa +from cryptography.hazmat.primitives import serialization + +from knack.log import get_logger +logger = get_logger(__name__) + + +def is_valid_ssh_rsa_public_key(openssh_pubkey): + # http://stackoverflow.com/questions/2494450/ssh-rsa-public-key-validation-using-a-regular-expression + # A "good enough" check is to see if the key starts with the correct header. + import struct + try: + from base64 import decodebytes as base64_decode + except ImportError: + # deprecated and redirected to decodebytes in Python 3 + from base64 import decodestring as base64_decode + + parts = openssh_pubkey.split() + if len(parts) < 2: + return False + key_type = parts[0] + key_string = parts[1] + + data = base64_decode(key_string.encode()) # pylint:disable=deprecated-method + int_len = 4 + str_len = struct.unpack('>I', data[:int_len])[0] # this should return 7 + return data[int_len:int_len + str_len] == key_type.encode() + + +def get_public_key(self): + key = rsa.generate_private_key(backend=default_backend(), public_exponent=65537, key_size=2048) + return key.public_key().public_bytes(serialization.Encoding.OpenSSH, + serialization.PublicFormat.OpenSSH).decode('utf-8') + + +def load_json(self, file_path): + try: + with open(file_path) as configFile: + configData = json.load(configFile) + except FileNotFoundError: + print("Error: Expecting azurermconfig.json in current folder") + sys.exit() Review comment: This is not a good solution. Probably, when an error occurs, the program will be closed without reporting an error. If an error has occurred then you should throw an exception. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services