2
0
mirror of https://github.com/VinylDNS/vinyldns synced 2025-08-22 18:17:07 +00:00
vinyldns/utils/admin/update-support-user.py
Emerle, Ryan a075c3c35e Updates
- Move away from using multiple images for "quickstart" and instead use a single "integration" image which provides all of the dependencies

- Update `docker-up-vinyldns.sh` to support the new `integration` image
- Update `remove-vinyl-containers.sh` to more cleanly.. clean up
- Update `verify.sh` to more reliably run `sbt` targets
- Update `build/docker/api/application.conf` to allow for overrides and default to the `vinyldns-integration` image
- Update `build/docker/portal/application.conf` to allow overrides and use `vinyldns-integration` image
  - Update `build/docker/portal/Dockerfile` to use `vinyldns/build:base-build-portal` to reduce need to download dependencies over and over
- Update `api/assembly` sbt target to output to `assembly` rather than some deeply nested folder in `**/target`
- Update documentation to reflect changes

- Move `docker/` directory to `quickstart/` to reduce confusion with the `build/docker` directory
- Move `bin/` to `utils/` since the files are binaries

- Add `.dockerignore` to root
2021-10-20 09:07:19 -04:00

53 lines
1.8 KiB
Python

#!/usr/bin/env python
import mysql.connector
import VinylDNSProto_pb2
import sys
import os
# arguments
user_name = sys.argv[1]
make_support = sys.argv[2][0].upper()=='T' if len(sys.argv) >= 2 else None
# environment variables to connect to database
db_user = os.environ.get('DB_USER')
db_pass = os.environ.get('DB_PASS')
db_host = os.environ.get('DB_HOST')
db_name = os.environ.get('DB_NAME')
db_port = os.environ.get('DB_PORT')
cnx = mysql.connector.connect(user=db_user, password=db_pass, host=db_host, database=db_name, port=db_port)
query = "SELECT data FROM user where user_name = %(user_name)s"
update = "UPDATE user SET data = %(pb)s WHERE user_name = %(user_name)s"
cursor = cnx.cursor(dictionary=True)
try:
cursor.execute(query, { 'user_name': user_name })
user = VinylDNSProto_pb2.User()
for row in cursor:
user_raw = row['data']
user = VinylDNSProto_pb2.User()
if isinstance(user_raw, str):
print("Type of user data is string {}".format(user_raw))
user.ParseFromString(base64.encodebytes(user_raw.encode()))
else:
print("Type of user data is bytes")
user.ParseFromString(user_raw)
print("FOUND USER NAME {}, IS SUPPORT = {}".format(user.userName, user.isSupport))
if user.userName is None or len(user.userName) == 0:
sys.exit("User {0} not found; cannot continue.".format(user_name))
if make_support is not None:
print("Updating {}, Support = {}".format(user_name, make_support))
user.isSupport = make_support
cursor.execute(update, { 'pb': user.SerializeToString(), 'user_name': user_name })
cnx.commit()
else:
print("Skipping making support as no make support value provided")
finally:
cursor.close()
cnx.close()