Skip to content

Commit

Permalink
Add ability to specify port (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
mackenly authored Oct 11, 2024
1 parent f3966c6 commit 86b36c8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,16 @@ Enter the project's directory, then install the required packages by running:
pip install -r requirements.txt
```

While in the directory of the project, run ` python server.py` to start the server. Pass in as parameters the IP address `--ip` of the ATEM switcher and a simple passphrase `--passphrase` for high level authentication.
While in the directory of the project, run ` python server.py` to start the server. Pass in as parameters the IP address `--ip` of the ATEM switcher, optionally a simple passphrase `--passphrase` for high level authentication, and optionally the port `--port` to run the server on (defaults to `5555`).

The passphrase is optional. If you do not include a passphrase, one will not be required. If you do use a passphrase, make sure to pass it in with your requests in the Authorization header (see below for an example).

The port is also optional. If you do not include a port, the server will run on port `5555`. If running via Docker, you can also map the port to a different port on the host machine using docker.


```bash
python server.py --ip 127.0.0.1 --passphrase Password1`
````
python server.py --ip 127.0.0.1 --passphrase Password1 --port 5555
```

> [!WARNING]
> Passing sensitive data in the command line will result in the passphrase being in plaintext in command line history logs such as in `.bash_history`, other Linux/Mac shell histories, or `$env:APPDATA\Microsoft\Windows\PowerShell\PSReadLine` in Windows. This probably doesn't matter for most users, but if you're concerned about it, you can use the following methods to pass in sensitive data:
Expand Down
9 changes: 8 additions & 1 deletion server.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,14 @@ def main():
parser = argparse.ArgumentParser()
parser.add_argument('--ip', help='switcher IP address')
parser.add_argument('--passphrase', help='passphrase to compare requests to', type=str, default='')
parser.add_argument('--port', help='port to start server on', type=int, default=5555)
args = parser.parse_args()

# set global variables
global passphrase, ip
passphrase = os.environ.get('PASSPHRASE', args.passphrase)
ip = os.environ.get('SERVER_IP', args.ip)
preferred_port = os.environ.get('PORT', args.port)

# if no ip is provided, exit
if ip is None:
Expand All @@ -123,6 +125,11 @@ def main():
log.info("No passphrase provided, using no passphrase")
passphrase = ''

if preferred_port is None:
# if the default port is not
log.info("No port provided, using default port 5555")
preferred_port = 5555

log.info("Initializing switcher")
switcher.setLogLevel(logging.INFO) # Set switcher verbosity (try DEBUG to see more)
switcher.connect(ip)
Expand All @@ -135,7 +142,7 @@ def main():
# this is the object which take port
# number and the server-name
# for running the server
port = ThreadingHTTPServer(('', 5555), GFG)
port = ThreadingHTTPServer(('', preferred_port), GFG)

# this is used for running our
# server as long as we wish
Expand Down

0 comments on commit 86b36c8

Please sign in to comment.