adheli.tavares | 7abe36c | 2022-02-02 14:53:10 +0000 | [diff] [blame] | 1 | #!/usr/bin/python3 |
| 2 | # |
| 3 | # ============LICENSE_START==================================================== |
| 4 | # Copyright (C) 2022 Nordix Foundation. |
| 5 | # ============================================================================= |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | # you may not use this file except in compliance with the License. |
| 8 | # You may obtain a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | # See the License for the specific language governing permissions and |
| 16 | # limitations under the License. |
| 17 | # |
| 18 | # SPDX-License-Identifier: Apache-2.0 |
| 19 | # ============LICENSE_END====================================================== |
| 20 | |
| 21 | import os |
| 22 | import argparse |
| 23 | |
| 24 | if __name__ == '__main__': |
| 25 | parser = argparse.ArgumentParser(description='Process configuration files for https/ssl ' |
| 26 | 'disabling.') |
| 27 | parser.add_argument('--https', default="true", |
| 28 | help='enable or disable https/ssl connection. ' |
| 29 | 'use https=true or https=false') |
| 30 | |
| 31 | https_enabled = parser.parse_args().https |
| 32 | message_router_port = '3905' if https_enabled == "true" else '3904' |
saul.gill | 2642450 | 2022-03-15 11:56:01 +0000 | [diff] [blame] | 33 | protocol = 'https://' if https_enabled == "true" else 'http://' |
adheli.tavares | 7abe36c | 2022-02-02 14:53:10 +0000 | [diff] [blame] | 34 | |
| 35 | current_dir = os.getcwd() |
| 36 | config_dir = current_dir + "/config/" |
| 37 | |
| 38 | files = [] |
| 39 | for (dirpath, dirnames, filenames) in os.walk(config_dir): |
| 40 | for filename in filenames: |
| 41 | files.append(os.path.join(dirpath, filename)) |
| 42 | |
| 43 | for file in files: |
| 44 | try: |
| 45 | with open(file, 'r+') as f: |
| 46 | content = f.read() |
| 47 | new_content = content.replace("{{HTTPS_ENABLED}}", https_enabled) |
saul.gill | 2642450 | 2022-03-15 11:56:01 +0000 | [diff] [blame] | 48 | new_content = new_content.replace("{{PROTOCOL}}", protocol) |
adheli.tavares | 7abe36c | 2022-02-02 14:53:10 +0000 | [diff] [blame] | 49 | new_content = new_content.replace("{{MESSAGE_ROUTER_PORT}}", message_router_port) |
| 50 | |
| 51 | if new_content != content: |
| 52 | f.seek(0) |
| 53 | f.truncate() |
| 54 | f.write(new_content) |
| 55 | print("File {0} updated!".format(file)) |
| 56 | except UnicodeDecodeError: |
| 57 | print("File didn't open: ", file) |
| 58 | |
| 59 | exit(0) |