Skip to content

Commit

Permalink
chore!: do not expose the TD ID via AugmentedForms
Browse files Browse the repository at this point in the history
  • Loading branch information
JKRhb committed Jan 12, 2025
1 parent b656efe commit dc73eac
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 20 deletions.
17 changes: 11 additions & 6 deletions example/complex_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,23 @@ const thingDescriptionJson = {
},
};

final Map<String, BasicCredentials> basicCredentials = {
"urn:test": const BasicCredentials("username", "password"),
final Map<Uri, BasicCredentials> basicCredentials = {
Uri.parse("https://httpbin.org"):
const BasicCredentials("username", "password"),
};

Future<BasicCredentials?> basicCredentialsCallback(
Uri uri,
AugmentedForm? form, [
AugmentedForm? form,
BasicCredentials? invalidCredentials,
]) async {
final id = form?.tdIdentifier;
) async {
final href = Uri(
scheme: uri.scheme,
host: uri.host,
port: uri.port,
);

return basicCredentials[id];
return basicCredentials[href];
}

Future<void> main() async {
Expand Down
12 changes: 8 additions & 4 deletions example/http_basic_authentication.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ const thingDescriptionJson = {

const basicCredentials = BasicCredentials("username", "password");

final Map<String, BasicCredentials> basicCredentialsMap = {
"urn:test": basicCredentials,
final Map<Uri, BasicCredentials> basicCredentialsMap = {
Uri.parse("https://httpbin.org"): basicCredentials,
};

Future<BasicCredentials?> basicCredentialsCallback(
Expand All @@ -50,9 +50,13 @@ Future<BasicCredentials?> basicCredentialsCallback(
return basicCredentials;
}

final id = form.tdIdentifier;
final href = Uri(
scheme: uri.scheme,
host: uri.host,
port: uri.port,
);

return basicCredentialsMap[id];
return basicCredentialsMap[href];
}

/// Illustrates the usage of both the basic and the automatic security scheme,
Expand Down
15 changes: 11 additions & 4 deletions example/mqtt_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,25 @@ const thingDescriptionJson = {
},
};

final Map<String, BasicCredentials> basicCredentials = {
"urn:test": const BasicCredentials("rw", "readwrite"),
final Map<Uri, BasicCredentials> basicCredentials = {
Uri.parse("mqtt://test.mosquitto.org:1884"): const BasicCredentials(
"rw",
"readwrite",
),
};

Future<BasicCredentials?> basicCredentialsCallback(
Uri uri,
AugmentedForm? form, [
BasicCredentials? invalidCredentials,
]) async {
final id = form?.tdIdentifier;
final href = Uri(
scheme: uri.scheme,
host: uri.host,
port: uri.port,
);

return basicCredentials[id];
return basicCredentials[href];
}

Future<void> main(List<String> args) async {
Expand Down
3 changes: 1 addition & 2 deletions lib/src/binding_mqtt/mqtt_extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ extension MqttFormExtension on AugmentedForm {
if (qosValue != null) {
throw FormatException(
"Encountered unknown QoS value $qosValue. "
"in form with href $href of Thing Description with Identifier "
"$tdIdentifier.",
"in form with resolved href $resolvedHref.",
);
}

Expand Down
3 changes: 0 additions & 3 deletions lib/src/core/implementation/augmented_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ final class AugmentedForm implements Form {

final Map<String, Object>? _userProvidedUriVariables;

/// The identifier of the [_thingDescription] associated with this form.
String get tdIdentifier => _thingDescription.identifier;

@override
Map<String, dynamic> get additionalFields => _form.additionalFields;

Expand Down
1 change: 0 additions & 1 deletion test/core/augmented_form_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ void main() {
expect(augmentedForm.href, Uri.parse(href));
expect(augmentedForm.security, ["nosec_sc"]);
expect(augmentedForm.securityDefinitions.first, isA<NoSecurityScheme>());
expect(augmentedForm.tdIdentifier, id);
expect(
augmentedForm.additionalResponses?.first.contentType,
"application/json",
Expand Down

0 comments on commit dc73eac

Please sign in to comment.