Skip to content

Commit

Permalink
Merge pull request #106 from UST-QuAntiL/fix/confidential-log
Browse files Browse the repository at this point in the history
Fix/confidential log
  • Loading branch information
infacc authored Oct 9, 2023
2 parents fca7efc + 9fd7704 commit 92f2911
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 18 deletions.
15 changes: 15 additions & 0 deletions qhana_plugin_runner/util/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,18 @@ def get_logger(app: Flask, name: str) -> Logger:
"""Utitlity method to get a specific logger that is a child logger of the app.logger."""
logger_name = f"{app.import_name}.{name}"
return getLogger(logger_name)


def redact_log_data(data: dict, private_fields: tuple = ("ibmq_token", "db_password")):
"""Returns a copy of the data without confidential/private information.
Args:
data: The data to be copied.
Returns:
A copy of the data without confidential/private information.
"""
log_data = data.copy()
for field in private_fields:
if field in log_data:
log_data[field] = "****"
return log_data
2 changes: 1 addition & 1 deletion stable_plugins/quantum_ml/max_cut/max_cut/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class InputParametersSchema(FrontendFormBaseSchema):
metadata={
"label": "IBMQ Token",
"description": "IBMQ Token",
"input_type": "text",
"input_type": "password",
},
)
visualize = ma.fields.Boolean(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class HybridAutoencoderPennylaneRequestSchema(FrontendFormBaseSchema):
metadata={
"label": "IBMQ Token",
"description": "Token for IBMQ.",
"input_type": "text",
"input_type": "password",
},
)
custom_backend = ma.fields.String(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ class QNNParametersSchema(FrontendFormBaseSchema):
metadata={
"label": "IBMQ Token",
"description": "Token for IBMQ.",
"input_type": "text",
"input_type": "password",
},
)
custom_backend = ma.fields.String(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class InputParametersSchema(FrontendFormBaseSchema):
metadata={
"label": "IBMQ Token",
"description": "Token for IBMQ.",
"input_type": "text",
"input_type": "password",
},
)
custom_backend = ma.fields.String(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class InputParametersSchema(FrontendFormBaseSchema):
metadata={
"label": "IBMQ Token",
"description": "Token for IBMQ.",
"input_type": "text",
"input_type": "password",
},
)
custom_backend = ma.fields.String(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@

from marshmallow import post_load
import marshmallow as ma
from celery.utils.log import get_task_logger
from qhana_plugin_runner.api import EnumField
from qhana_plugin_runner.api.util import (
FrontendFormBaseSchema,
MaBaseSchema,
FileUrl,
)
from celery.utils.log import get_task_logger
from qhana_plugin_runner.util.logging import redact_log_data
from .backend.quantum_backends import QuantumBackends
from .backend.kernels.kernel import KernelEnum, EntanglementPatternEnum

Expand Down Expand Up @@ -183,7 +183,7 @@ class InputParametersSchema(FrontendFormBaseSchema):
metadata={
"label": "IBMQ Token",
"description": "Token for IBMQ.",
"input_type": "text",
"input_type": "password",
},
)
custom_backend = ma.fields.String(
Expand All @@ -198,6 +198,5 @@ class InputParametersSchema(FrontendFormBaseSchema):

@post_load
def make_input_params(self, data, **kwargs) -> InputParameters:
TASK_LOGGER.info("test")
TASK_LOGGER.info(f"data: {data}")
TASK_LOGGER.info(f"data: {redact_log_data(data)}")
return InputParameters(**data)
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class InputParametersSchema(FrontendFormBaseSchema):
metadata={
"label": "IBMQ Token",
"description": "Token for IBMQ.",
"input_type": "text",
"input_type": "password",
},
)
custom_backend = ma.fields.String(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@

from marshmallow import post_load
import marshmallow as ma
from celery.utils.log import get_task_logger
from qhana_plugin_runner.api import EnumField
from qhana_plugin_runner.api.util import (
FrontendFormBaseSchema,
MaBaseSchema,
FileUrl,
)
from celery.utils.log import get_task_logger
from qhana_plugin_runner.util.logging import redact_log_data
from .backend.qiskit_backends import QiskitBackends
from .backend.kernel import KernelEnum, EntanglementPatternEnum

Expand Down Expand Up @@ -184,7 +184,7 @@ class InputParametersSchema(FrontendFormBaseSchema):
metadata={
"label": "IBMQ Token",
"description": "Token for IBMQ.",
"input_type": "text",
"input_type": "password",
},
)
custom_backend = ma.fields.String(
Expand All @@ -199,6 +199,5 @@ class InputParametersSchema(FrontendFormBaseSchema):

@post_load
def make_input_params(self, data, **kwargs) -> InputParameters:
TASK_LOGGER.info("test")
TASK_LOGGER.info(f"data: {data}")
TASK_LOGGER.info(f"data: {redact_log_data(data)}")
return InputParameters(**data)
2 changes: 1 addition & 1 deletion stable_plugins/quantum_ml/qiskit_ml/svm/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ class InputParametersSchema(FrontendFormBaseSchema):
metadata={
"label": "IBMQ Token",
"description": "Token for IBMQ.",
"input_type": "text",
"input_type": "password",
},
)
custom_backend = ma.fields.String(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ class InputParametersSchema(FrontendFormBaseSchema):
metadata={
"label": "IBMQ Token",
"description": "Token for IBMQ.",
"input_type": "text",
"input_type": "password",
},
)
custom_backend = ma.fields.String(
Expand Down

0 comments on commit 92f2911

Please sign in to comment.