Skip to content

Commit

Permalink
refactor: removed noports-specific DeviceInfo class; renamed this p…
Browse files Browse the repository at this point in the history
…ackage's `CoreDeviceInfo` class to `CoreServiceInfo` and renamed some instance variables also (device -> service)
  • Loading branch information
gkc committed Dec 9, 2024
1 parent 7fbc5e8 commit b1e736e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 93 deletions.
8 changes: 4 additions & 4 deletions packages/at_policy/lib/src/policy/impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ class PolicyServiceImpl with AtClientBindings implements PolicyService {

final event = PolicyLogEvent(
timestamp: DateTime.now().millisecondsSinceEpoch,
deviceAtsign: fromAtSign,
serviceAtsign: fromAtSign,
policyAtsign: atClient.getCurrentAtSign(),
devicename: policyRequest.serviceName,
deviceGroupName: policyRequest.serviceGroupName,
serviceName: policyRequest.serviceName,
serviceGroupName: policyRequest.serviceGroupName,
clientAtsign: policyRequest.clientAtsign,
eventType: PolicyLogEventType.requestFromDevice,
eventType: PolicyLogEventType.request,
eventDetails: {'intents': policyRequest.intents},
message: '',
);
Expand Down
62 changes: 15 additions & 47 deletions packages/at_policy/lib/src/policy/models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,73 +108,41 @@ class PolicyResponse {
String toString() => jsonPrettyPrinter.convert(toJson());
}

abstract class CoreDeviceInfo {
abstract class CoreServiceInfo {
final int timestamp;
final String deviceAtsign;
final String serviceAtsign;
final String? policyAtsign;
final String devicename;
final String deviceGroupName;
final String serviceName;
final String serviceGroupName;

CoreDeviceInfo({
CoreServiceInfo({
required this.timestamp,
required this.deviceAtsign,
required this.serviceAtsign,
required this.policyAtsign,
required this.devicename,
required this.deviceGroupName,
});
}

@JsonSerializable(explicitToJson: true)
class DeviceInfo extends CoreDeviceInfo {
final List<String> managerAtsigns;
final String version;
final String corePackageVersion;
final Map<String, dynamic> supportedFeatures;
final List<String> allowedServices; // aka permitOpens
String? status;

DeviceInfo({
required super.timestamp,
required super.deviceAtsign,
required super.policyAtsign,
required super.devicename,
required super.deviceGroupName,
required this.managerAtsigns,
required this.version,
required this.corePackageVersion,
required this.supportedFeatures,
required this.allowedServices,
this.status,
required this.serviceName,
required this.serviceGroupName,
});

Map<String, dynamic> toJson() => _$DeviceInfoToJson(this);

static DeviceInfo fromJson(Map<String, dynamic> json) =>
_$DeviceInfoFromJson(json);

@override
String toString() => jsonPrettyPrinter.convert(toJson());
}

enum PolicyLogEventType {
requestFromDevice,
responseToDevice,
deviceDecision,
request,
response,
decision,
}

@JsonSerializable(explicitToJson: true)
class PolicyLogEvent extends CoreDeviceInfo {
class PolicyLogEvent extends CoreServiceInfo {
final String clientAtsign;
final PolicyLogEventType eventType;
final String? message;
final Map<String, dynamic> eventDetails;

PolicyLogEvent({
required super.timestamp,
required super.deviceAtsign,
required super.serviceAtsign,
required super.policyAtsign,
required super.devicename,
required super.deviceGroupName,
required super.serviceName,
required super.serviceGroupName,
required this.clientAtsign,
required this.eventType,
required this.eventDetails,
Expand Down
51 changes: 9 additions & 42 deletions packages/at_policy/lib/src/policy/models.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b1e736e

Please sign in to comment.