Skip to content

Commit cc69c5b

Browse files
authored
Merge pull request #93 from eclipse-thingweb/immutable-credentials
feat!: make credentials classes immutable
2 parents 320421a + 670d96a commit cc69c5b

12 files changed

+30
-21
lines changed

example/complex_example.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ const thingDescriptionJson = {
7474
};
7575

7676
final Map<String, BasicCredentials> basicCredentials = {
77-
"urn:test": BasicCredentials("username", "password"),
77+
"urn:test": const BasicCredentials("username", "password"),
7878
};
7979

8080
Future<BasicCredentials?> basicCredentialsCallback(

example/http_basic_authentication.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const thingDescriptionJson = {
3434
},
3535
};
3636

37-
final basicCredentials = BasicCredentials("username", "password");
37+
const basicCredentials = BasicCredentials("username", "password");
3838

3939
final Map<String, BasicCredentials> basicCredentialsMap = {
4040
"urn:test": basicCredentials,

example/mqtt_example.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const thingDescriptionJson = {
4545
};
4646

4747
final Map<String, BasicCredentials> basicCredentials = {
48-
"urn:test": BasicCredentials("rw", "readwrite"),
48+
"urn:test": const BasicCredentials("rw", "readwrite"),
4949
};
5050

5151
Future<BasicCredentials?> basicCredentialsCallback(

lib/src/core/credentials/ace_credentials.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import "credentials.dart";
1212
/// [Credentials] used for the [AceSecurityScheme].
1313
final class AceCredentials extends Credentials {
1414
/// Constructor.
15-
AceCredentials(this.accessToken);
15+
const AceCredentials(this.accessToken);
1616

1717
/// The access token associated with these [AceCredentials] in serialized
1818
/// form.

lib/src/core/credentials/apikey_credentials.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import "credentials.dart";
1111
/// [Credentials] used for the [ApiKeySecurityScheme].
1212
final class ApiKeyCredentials extends Credentials {
1313
/// Constructor.
14-
ApiKeyCredentials(this.apiKey);
14+
const ApiKeyCredentials(this.apiKey);
1515

1616
/// The [apiKey] associated with these [ApiKeyCredentials].
17-
String apiKey;
17+
final String apiKey;
1818
}

lib/src/core/credentials/basic_credentials.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ import "credentials.dart";
1313
/// Provides an unencrypted [username] and [password] combination.
1414
final class BasicCredentials extends Credentials {
1515
/// Constructor.
16-
BasicCredentials(this.username, this.password);
16+
const BasicCredentials(this.username, this.password);
1717

1818
/// The [username] associated with these [BasicCredentials].
19-
String username;
19+
final String username;
2020

2121
/// The [password] associated with these [BasicCredentials].
22-
String password;
22+
final String password;
2323
}

lib/src/core/credentials/bearer_credentials.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import "credentials.dart";
1111
/// [Credentials] used for the [BearerSecurityScheme].
1212
final class BearerCredentials extends Credentials {
1313
/// Constructor.
14-
BearerCredentials(this.token);
14+
const BearerCredentials(this.token);
1515

1616
/// The [token] associated with these [BearerCredentials].
17-
String token;
17+
final String token;
1818
}

lib/src/core/credentials/credentials.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,11 @@
44
//
55
// SPDX-License-Identifier: BSD-3-Clause
66

7+
import "package:meta/meta.dart";
8+
79
/// Base class used for defining credentials for Thing Interactions.
8-
abstract base class Credentials {}
10+
@immutable
11+
abstract base class Credentials {
12+
/// Default constructor for credentials objects.
13+
const Credentials();
14+
}

lib/src/core/credentials/digest_credentials.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import "credentials.dart";
1010
/// [Credentials] used for the [DigestSecurityScheme].
1111
final class DigestCredentials extends Credentials {
1212
/// Constructor.
13-
DigestCredentials(this.username, this.password);
13+
const DigestCredentials(this.username, this.password);
1414

1515
/// The [username] associated with these [DigestCredentials].
16-
String username;
16+
final String username;
1717

1818
/// The [password] associated with these [DigestCredentials].
19-
String password;
19+
final String password;
2020
}

lib/src/core/credentials/oauth2_credentials.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@ import "credentials.dart";
1010
/// [Credentials] used for the [OAuth2SecurityScheme].
1111
final class OAuth2Credentials extends Credentials {
1212
/// Constructor.
13-
OAuth2Credentials([this.secret]);
13+
const OAuth2Credentials({
14+
this.secret,
15+
this.credentialsJson,
16+
});
1417

1518
/// The optional secret for these [OAuth2Credentials].
16-
String? secret;
19+
final String? secret;
1720

1821
/// A JSON string representation of OAuth2 credentials.
1922
///
2023
/// Used to store obtained credentials from an authorization server.
21-
String? credentialsJson;
24+
final String? credentialsJson;
2225
}

0 commit comments

Comments
 (0)