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

chore!: do not expose the TD ID via AugmentedForms #209

Draft
wants to merge 1 commit 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
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
Loading