def _get_credentials_from_tvm(tvm_endpoint, tvm_username, tvm_password): retry = 3 while True: response = requests.get( "https://%s/v1/getcredentials" % tvm_endpoint, headers={ "User-Agent": "Mendix Buildpack {} (for Mendix {})".format( util.get_buildpack_version(), runtime.get_runtime_version(), ) }, auth=(tvm_username, tvm_password), ) if response.ok: break elif not response.ok and retry == 0: logging.error("Failed to get IAM credential from TVM") raise Exception( "failed to get IAM credential from TVM for tvm_user %s" % tvm_username) else: retry = retry - 1 time.sleep(5) logging.error( "Failed to get IAM credential from TVM (HTTP {}), Retrying... {}" .format(response.status_code, retry)) logging.error("Number of retries left = {}".format(retry)) result = response.json() if "AccessKeyId" not in result: raise Exception( "failed to get IAM credential from TVM for tvm_user %s (missing AccessKeyId)" % tvm_username) if "SecretAccessKey" not in result: raise Exception( "failed to get IAM credential from TVM for tvm_user %s (missing SecretAccessKey)" % tvm_username) return result["AccessKeyId"], result["SecretAccessKey"]
if __name__ == "__main__": app_is_restarting = False m2ee = None nginx_process = None databroker_processes = databroker.Databroker() logging.basicConfig( level=util.get_buildpack_loglevel(), stream=sys.stdout, format="%(levelname)s: %(message)s", ) logging.info( "Mendix Cloud Foundry Buildpack %s [%s] starting...", util.get_buildpack_version(), util.get_current_buildpack_commit(), ) try: if os.getenv("CF_INSTANCE_INDEX") is None: logging.warning( "CF_INSTANCE_INDEX environment variable not found. Assuming " "responsibility for scheduled events execution and database " "synchronization commands.") runtime.pre_process_m2ee_yaml() runtime.activate_license() m2ee = runtime.set_up_m2ee_client(util.get_vcap_data()) java_version = runtime.get_java_version(