blob: 4eaa34225613b1a80a3a467f1a3119c0e1b46be5 [file] [log] [blame]
adheli.tavares7abe36c2022-02-02 14:53:10 +00001#!/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
21import os
22import argparse
23
24if __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.gill26424502022-03-15 11:56:01 +000033 protocol = 'https://' if https_enabled == "true" else 'http://'
adheli.tavares7abe36c2022-02-02 14:53:10 +000034
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.gill26424502022-03-15 11:56:01 +000048 new_content = new_content.replace("{{PROTOCOL}}", protocol)
adheli.tavares7abe36c2022-02-02 14:53:10 +000049 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)