New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Audit Logging] Logger and factory APIs in C-Core and C++. #32750
Conversation
@ctiller @markdroth PTAL. Is this what you had in your mind yesterday? |
include/grpc/grpc_audit_logging.h
Outdated
namespace experimental { | ||
|
||
// The base struct for audit context. | ||
typedef struct CoreAuditContext { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class AuditContext {
-- no need for a typedef
bool authorized() const; | ||
|
||
private: | ||
const grpc_core::experimental::CoreAuditContext* core_context_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd make this a reference
|
||
// The base class for audit logger implementations. | ||
// Users are expected to inherit this class and implement the Log() function. | ||
class AuditLogger : public grpc_core::experimental::CoreAuditLogger { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need inheritance here: this should be its own type.
// Users should inherit this class and implement those declared virtual | ||
// funcitons. | ||
class AuditLoggerFactory | ||
: public grpc_core::experimental::CoreAuditLoggerFactory { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No inheritance here.
include/grpc/grpc_audit_logging.h
Outdated
// This base class for audit logger implementations. | ||
class CoreAuditLogger { | ||
public: | ||
virtual void CoreLog(const CoreAuditContext& audit_context) = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should just be Log(...), and we'll have an instance that has a unique_ptr<grpc::AuditLogger> log_
that we call log_->Log(...)
on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So it means this class defined in C-Core can have a dependence on the C++ class, right? I initially was about to do this but wasn't sure if it's fine to have such a reversed dependency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh. is the following flow correct?
// C-Core
class AuditLogger {
public:
virtual void Log() = 0;
};
// C++
class AuditLogger {
public:
virtual void Log() = 0;
};
class AuditLoggerFactory {
public:
virtual std::unique_ptr<AuditLogger> CreateAuditLogger() = 0;
std::unique_ptr<CoreLogger> CreateCoreLogger() {
return std::make_unique<CoreLogger>(CreateAuditLogger());
}
};
// non-public API
class CoreLogger : public grpc_core::AuditLogger {
public:
CoreLogger(std::unique_ptr<AuditLogger> logger) : logger_(logger) {}
void Log() { logger_->Log(); }
private:
std::unique_ptr<AuditLogger> logger_;
};
Automated fix for refs/heads/audit-log-api
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great!
Audit logging APIs for both built-in loggers and third-party logger implementations. C++ uses using decls referring to C-Core APIs. --------- Co-authored-by: rockspore <rockspore@users.noreply.github.com>
Audit logging APIs for both built-in loggers and third-party logger implementations. C++ uses using decls referring to C-Core APIs. --------- Co-authored-by: rockspore <rockspore@users.noreply.github.com>
Audit logging APIs for both built-in loggers and third-party logger implementations. C++ uses using decls referring to C-Core APIs. --------- Co-authored-by: rockspore <rockspore@users.noreply.github.com>
Audit logging APIs for both built-in loggers and third-party logger implementations.
C-Core and C++ have independent base classes of loggers and factories for users to implement.