Skip to content
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

Privacy Concern Event wrapper #1310

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions wrappers/obj-c/ODWPrivacyConcernMetadataProvider.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
//
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

/*!
@brief Represents a metadata provider for privacy concern events.
*/
@interface ODWPrivacyConcernMetadataProvider : NSObject

/*!
@brief Get the database name.
@param record The record for which to retrieve the database name.
@return A string representing the database name.
*/
- (NSString *)getDatabaseNameForRecord:(id)record;

/*!
@brief Get the server name.
@param record The record for which to retrieve the server name.
@return A string representing the server name.
*/
- (NSString *)getServerNameForRecord:(id)record;

/*!
@brief Get the event locator name.
@param record The record for which to retrieve the event locator name.
@return A string representing the event locator name.
*/
- (NSString *)getEventLocatorNameForRecord:(id)record;

/*!
@brief Get the event locator value.
@param record The record for which to retrieve the event locator value.
@return A string representing the event locator value.
*/
- (NSString *)getEventLocatorValueForRecord:(id)record;

/*!
@brief Get the override for the privacy guard event time.
@param record The record for which to retrieve the event time override.
@return An integer representing the event time override.
*/
- (int64_t)getPrivacyGuardEventTimeOverrideForRecord:(id)record;

/*!
@brief Check if the record should be ignored.
@param record The record to check.
@return A boolean indicating whether the record should be ignored.
*/
- (BOOL)getShouldIgnoreOverrideForRecord:(id)record;

/*!
@brief Get the associated tenant.
@param record The record for which to retrieve the associated tenant.
@return A string representing the associated tenant.
*/
- (NSString *)getAssociatedTenantForRecord:(id)record;

/*!
@brief Get the environment.
@param record The record for which to retrieve the environment.
@return A string representing the environment.
*/
- (NSString *)getEnvironmentForRecord:(id)record;

/*!
@brief Get the metadata.
@param record The record for which to retrieve the metadata.
@return A string representing the metadata.
*/
- (NSString *)getMetadataForRecord:(id)record;

@end

NS_ASSUME_NONNULL_END
51 changes: 51 additions & 0 deletions wrappers/obj-c/ODWPrivacyConcernMetadataProvider.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

//
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
//

#import <Foundation/Foundation.h>
#import "ODWPrivacyConcernMetadataProvider.h"

/*!
@brief Represents a metadata provider for privacy concern events.
*/
@implementation ODWPrivacyConcernMetadataProvider : NSObject

- (NSString *)getDatabaseNameForRecord:(id)record {
return @""; // Default implementation
}

- (NSString *)getServerNameForRecord:(id)record {
return @""; // Default implementation
}

- (NSString *)getEventLocatorNameForRecord:(id)record {
return @"BaseType"; // Default implementation
}

- (NSString *)getEventLocatorValueForRecord:(id)record {
return [record baseType]; // Example assuming `record` has a `baseType` property
}

- (int64_t)getPrivacyGuardEventTimeOverrideForRecord:(id)record {
return [record time]; // Example assuming `record` has a `time` property
}

- (BOOL)getShouldIgnoreOverrideForRecord:(id)record {
return NO; // Default implementation
}

- (NSString *)getAssociatedTenantForRecord:(id)record {
return [record iKey]; // Example assuming `record` has an `iKey` property
}

- (NSString *)getEnvironmentForRecord:(id)record {
return @""; // Default implementation
}

- (NSString *)getMetadataForRecord:(id)record {
return @""; // Default implementation
}

@end
4 changes: 4 additions & 0 deletions wrappers/obj-c/ODWPrivacyGuard.mm
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ +(void)initializePrivacyGuard:(ILogger *)logger withODWPrivacyGuardInitConfig:(O
{
config.SemanticContextNotificationEventName = [[initConfigObject semanticContextNotificationEventName] UTF8String];
}
if ([initConfigObject metadataProvider] != nill)
{
config.metadataProvider = [[]]
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

config.metadataProvider should be config.MetadataProvider defined here. However, current implementation does not assign metadata provider to underlying data structure in PG C++. This is because in PG C++, Metadata provider is defined as
const std::shared_ptr<PrivacyConcernMetadataProvider> MetadataProvider;, so you will need to convert your ODWPrivacyConcernMetadataProvider to this type. Unfortunately, there is no direct conversion between Obj-C and C++ class implementations. One way I found to achieve this is to use composition. In this link, it talks about how to do this.

I think this is what you need
`
// h file
@interface ODWPrivacyConcernMetadataProvider: NSObject
{
@public
PrivacyConcernMetadataProvider *cppObject;
}

  • (NSString *)getDatabaseNameForRecord:(id)record;
  • // rest of interface functions

@EnD

// mm file
@implementation MyCPPWrapper

  • (NSString *)getDatabaseNameForRecord:(id)record;
    {
    if (cppObject)
    cppObject->GetDatabaseName(id);
    }

@EnD
`

if ([initConfigObject summaryEventName] != nil)
{
config.SummaryEventName = [[initConfigObject summaryEventName] UTF8String];
Expand Down
6 changes: 6 additions & 0 deletions wrappers/obj-c/ODWPrivacyGuardInitConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//
#include "objc_begin.h"
#import "ODWCommonDataContext.h"
#import "ODWPrivacyConcernMetatadataProvider.h"

NS_ASSUME_NONNULL_BEGIN
/*!
Expand All @@ -24,6 +25,11 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property(readwrite, copy, nonatomic) NSString* semanticContextNotificationEventName;

/*!
nahidfgh marked this conversation as resolved.
Show resolved Hide resolved
@brief (OPTIONAL) Privacy Concern Event metadata provider to use with privacyguard.
*/
@property(readwrite, copy, nonatomic) ODWPrivacyConcernMetadataProvider* metadataProvider;

/*!
@brief (OPTIONAL) Custom event name to use when logging summary events. Default value is `PrivacyGuardSummary`.
*/
Expand Down
1 change: 1 addition & 0 deletions wrappers/swift/Headers/ObjCModule-Bridging-Header.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#import "../../obj-c/ODWLogConfiguration.h"
#import "../../obj-c/ODWLogger.h"
#import "../../obj-c/ODWLogManager.h"
#import "../../obj-c/ODWPrivacyConcernMetadataProvider.h"
#import "../../obj-c/ODWPrivacyGuard.h"
#import "../../obj-c/ODWPrivacyGuardInitConfig.h"
#import "../../obj-c/ODWSemanticContext.h"
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
//

import ObjCModule

/// Wrapper over ODWPrivacyConcernMetadataProvider class.
public final class PrivacyConcernMetadataProvider {

/// ObjC variable which is wrapped by Swift.
var odwPrivacyConcernMetadataProvider: ODWPrivacyConcernMetadataProvider

/// Constructor initialized with ObjC wrapped object.
init(odwPrivacyConcernMetadataProvider: ODWPrivacyConcernMetadataProvider) {
self.odwPrivacyConcernMetadataProvider = odwPrivacyConcernMetadataProvider
}

/// Default constructor.
public init() {
odwPrivacyConcernMetadataProvider = ODWPrivacyConcernMetadataProvider()
}

/// Get the database name for the provided record.
public func getDatabaseName(for record: Any) -> String {
return odwPrivacyConcernMetadataProvider.getDatabaseNameForRecord(record)
}

/// Get the server name for the provided record.
public func getServerName(for record: Any) -> String {
return odwPrivacyConcernMetadataProvider.getServerNameForRecord(record)
}

/// Get the event locator name for the provided record.
public func getEventLocatorName(for record: Any) -> String {
return odwPrivacyConcernMetadataProvider.getEventLocatorNameForRecord(record)
}

/// Get the event locator value for the provided record.
public func getEventLocatorValue(for record: Any) -> String {
return odwPrivacyConcernMetadataProvider.getEventLocatorValueForRecord(record)
}

/// Get the override for the privacy guard event time for the provided record.
public func getPrivacyGuardEventTimeOverride(for record: Any) -> Int64 {
return odwPrivacyConcernMetadataProvider.getPrivacyGuardEventTimeOverrideForRecord(record)
}

/// Check if the record should be ignored.
public func getShouldIgnoreOverride(for record: Any) -> Bool {
return odwPrivacyConcernMetadataProvider.getShouldIgnoreOverrideForRecord(record)
}

/// Get the associated tenant for the provided record.
public func getAssociatedTenant(for record: Any) -> String {
return odwPrivacyConcernMetadataProvider.getAssociatedTenantForRecord(record)
}

/// Get the environment for the provided record.
public func getEnvironment(for record: Any) -> String {
return odwPrivacyConcernMetadataProvider.getEnvironmentForRecord(record)
}

/// Get the metadata for the provided record.
public func getMetadata(for record: Any) -> String {
return odwPrivacyConcernMetadataProvider.getMetadataForRecord(record)
}
}
15 changes: 14 additions & 1 deletion wrappers/swift/Sources/OneDSSwift/PrivacyGuardInitConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import ObjCModule
public final class PrivacyGuardInitConfig {
let odwPrivacyGuardInitConfig: ODWPrivacyGuardInitConfig
private var commonDataContext: CommonDataContext

private var privacyConcernMetadataProvider: PrivacyConcernMetadataProvider
/// Data Context to use with the Privacy Guard.
public var dataContext: CommonDataContext {
get {
Expand All @@ -20,6 +20,17 @@ public final class PrivacyGuardInitConfig {
}
}

/// Metadata provider to use with Privacy Guard.
public var metadataProvider: PrivacyConcernMetadataProvider {
get {
return metadataProvider
}
set {
metadataProvider = newValue
odwPrivacyGuardInitConfig.metadataProvider = privacyConcernMetadataProvider.odwPrivacyConcernMetadataProvider
}
}

/// (OPTIONAL) Custom event name to use when logging privacy concerns. Default value is `PrivacyConcern`.
public var notificationEventName: String {
get {
Expand Down Expand Up @@ -84,6 +95,8 @@ public final class PrivacyGuardInitConfig {
public init() {
odwPrivacyGuardInitConfig = ODWPrivacyGuardInitConfig()
odwPrivacyGuardInitConfig.dataContext = ODWCommonDataContext()
odwPrivacyGuardInitConfig.metadataProvider = ODWPrivacyConcernMetadataProvider()
metadataProvider = PrivacyConcernMetadataProvider(odwPrivacyConcernMetadataProvider: odwPrivacyGuardInitConfig.metadataProvider)
commonDataContext = CommonDataContext(odwCommonDataContext: odwPrivacyGuardInitConfig.dataContext)
}

Expand Down
Loading