Skip to content

Commit

Permalink
Rename SaaS to manual
Browse files Browse the repository at this point in the history
No logic or UI changes here, just renaming variables.
  • Loading branch information
ashuntu committed Dec 11, 2024
1 parent b23e4e0 commit 2b8a3f5
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 36 deletions.
39 changes: 19 additions & 20 deletions gui/packages/ubuntupro/lib/pages/landscape/landscape_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ class LandscapeModel extends ChangeNotifier {

/// The current configuration type, allowing the UI to show the correct form.
LandscapeConfigType get configType => _current;
LandscapeConfigType _current = LandscapeConfigType.saas;
LandscapeConfigType _current = LandscapeConfigType.manual;

// The active configuration form data, a shortcut to reduce some switch statements
// and avoid relying on ducktyping when serializing the config or checking for completeness.
late LandscapeConfig _active = saas;
late LandscapeConfig _active = manual;

/// The configuration form data for the SaaS configuration.
final LandscapeSaasConfig saas = LandscapeSaasConfig();
/// The configuration form data for the manual configuration.
final LandscapeManualConfig manual = LandscapeManualConfig();

// TODO: Remove this condition when Landscape SaaS starts supporting WSL.
bool get isSaaSSupported => kDebugMode;
// TODO: Remove this condition when Landscape manual/SaaS starts supporting WSL.
bool get isManualSupported => kDebugMode;

/// The configuration form data for the custom configuration.
final LandscapeCustomConfig custom = LandscapeCustomConfig();
Expand All @@ -46,36 +46,36 @@ class LandscapeModel extends ChangeNotifier {
if (value == null) return;
_current = value;
switch (configType) {
case LandscapeConfigType.saas:
_active = saas;
case LandscapeConfigType.manual:
_active = manual;
case LandscapeConfigType.custom:
_active = custom;
}

notifyListeners();
}

/// Sets the registration key for the SaaS configurations.
void setSaasRegistrationKey(String? registrationKey) {
assert(_active is LandscapeSaasConfig);
/// Sets the registration key for the manual configurations.
void setManualRegistrationKey(String? registrationKey) {
assert(_active is LandscapeManualConfig);
if (registrationKey == null) return;
saas.registrationKey = registrationKey;
manual.registrationKey = registrationKey;
notifyListeners();
}

/// Sets (and validates) the FQDN for the self-hosted configuration.
void setFqdn(String? fqdn) {
assert(_active is LandscapeSaasConfig);
assert(_active is LandscapeManualConfig);
if (fqdn == null) return;
saas.fqdn = fqdn;
manual.fqdn = fqdn;
notifyListeners();
}

/// Sets (and validates) the SSL key path for the self-hosted configuration.
void setSslKeyPath(String? sslKeyPath) {
assert(_active is LandscapeSaasConfig);
assert(_active is LandscapeManualConfig);
if (sslKeyPath == null) return;
saas.sslKeyPath = sslKeyPath;
manual.sslKeyPath = sslKeyPath;
notifyListeners();
}

Expand All @@ -102,7 +102,7 @@ class LandscapeModel extends ChangeNotifier {
}

/// The different types of Landscape configurations, modelled as an enum to make it easy on the UI side to switch between them.
enum LandscapeConfigType { saas, custom }
enum LandscapeConfigType { manual, custom }

/// The alternative errors we could encounter when validating file paths submitted as part of any subform data.
enum FileError {
Expand All @@ -115,7 +115,6 @@ enum FileError {
invalidFormat,
}

const landscapeSaas = 'landscape.canonical.com';
const validCertExtensions = ['cer', 'crt', 'der', 'pem'];

/// The base class for the closed set of Landscape configuration form types.
Expand All @@ -128,7 +127,7 @@ sealed class LandscapeConfig {
}

/// The SaaS configuration form data: only the FQDN is mandatory.
class LandscapeSaasConfig extends LandscapeConfig {
class LandscapeManualConfig extends LandscapeConfig {
String _fqdn = '';
String get fqdn => _fqdn;
bool _fqdnError = false;
Expand All @@ -142,7 +141,7 @@ class LandscapeSaasConfig extends LandscapeConfig {
FileError _fileError = FileError.none;
FileError get fileError => _fileError;

// FQDN must be a valid URL (without an explicit port) and must not be the Landscape SaaS URL.
// FQDN must be a valid URL (without an explicit port) and must not be the Landscape URL.
bool _validateFQDN(String value) {
final uri = Uri.tryParse(value);
_fqdnError = value.isEmpty || uri == null || uri.hasPort;
Expand Down
16 changes: 8 additions & 8 deletions gui/packages/ubuntupro/lib/pages/landscape/landscape_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class LandscapeConfigForm extends StatelessWidget {
return Column(
children: [
YaruRadioListTile(
value: LandscapeConfigType.saas,
value: LandscapeConfigType.manual,
groupValue: model.configType,
contentPadding: EdgeInsets.zero,
onChanged: model.setConfigType,
Expand All @@ -150,7 +150,7 @@ class LandscapeConfigForm extends StatelessWidget {
}
}

/// The subform for quick-configuring Landscape SaaS.
/// The subform for quick-configuring Landscape Manual.
class _ManualForm extends StatelessWidget {
const _ManualForm(this.model);
final LandscapeModel model;
Expand All @@ -164,29 +164,29 @@ class _ManualForm extends StatelessWidget {
TextField(
decoration: InputDecoration(
label: Text(lang.landscapeFQDNLabel),
errorText: model.saas.fqdnError ? lang.landscapeFQDNError : null,
errorText: model.manual.fqdnError ? lang.landscapeFQDNError : null,
),
onChanged: model.setFqdn,
enabled: model.configType == LandscapeConfigType.saas,
enabled: model.configType == LandscapeConfigType.manual,
),
const SizedBox(height: 8),
TextField(
decoration: InputDecoration(
label: Text(lang.landscapeKeyLabel),
hintText: '163456',
),
onChanged: model.setSaasRegistrationKey,
enabled: model.configType == LandscapeConfigType.saas,
onChanged: model.setManualRegistrationKey,
enabled: model.configType == LandscapeConfigType.manual,
),
const SizedBox(height: 8),
_FilePickerField(
buttonLabel: lang.landscapeFilePicker,
errorText: model.saas.fileError.localize(lang),
errorText: model.manual.fileError.localize(lang),
hint: 'C:\\landscape.pem',
inputlabel: lang.landscapeSSLKeyLabel,
onChanged: model.setSslKeyPath,
allowedExtensions: validCertExtensions,
enabled: model.configType == LandscapeConfigType.saas,
enabled: model.configType == LandscapeConfigType.manual,
),
],
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void main() {
};
for (final MapEntry(key: name, value: tc) in testcases.entries) {
test(name, () {
final c = LandscapeSaasConfig();
final c = LandscapeManualConfig();
c.accountName = tc.account;
expect(c.accountNameError, tc.wantError);
expect(c.isComplete, tc.wantComplete);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ void main() {
expect(notified, isTrue);
notified = false;

model.setConfigType(LandscapeConfigType.saas);
model.setConfigType(LandscapeConfigType.manual);
expect(notified, isTrue);
notified = false;

model.setAccountName('testuser');
expect(notified, isTrue);
notified = false;

model.setSaasRegistrationKey('123');
model.setManualRegistrationKey('123');
expect(notified, isTrue);
notified = false;

Expand All @@ -73,7 +73,7 @@ void main() {

final model = LandscapeModel(client);

model.setConfigType(LandscapeConfigType.saas);
model.setConfigType(LandscapeConfigType.manual);
// Those assertions exist because the methods are not relevant for the current config type.
// Allowing those conditions to proceed could contribute to hide logic errors.
expect(() => model.setCustomConfigPath(customConf), throwsAssertionError);
Expand All @@ -87,13 +87,13 @@ void main() {

model.setConfigType(LandscapeConfigType.selfHosted);
expect(() => model.setAccountName('testuser'), throwsAssertionError);
expect(() => model.setSaasRegistrationKey('123'), throwsAssertionError);
expect(() => model.setManualRegistrationKey('123'), throwsAssertionError);
expect(() => model.setCustomConfigPath(customConf), throwsAssertionError);

model.setConfigType(LandscapeConfigType.custom);
expect(() => model.setSslKeyPath(customConf), throwsAssertionError);
expect(() => model.setAccountName('testuser'), throwsAssertionError);
expect(() => model.setSaasRegistrationKey('123'), throwsAssertionError);
expect(() => model.setManualRegistrationKey('123'), throwsAssertionError);
expect(() => model.setFqdn(testFqdn), throwsAssertionError);
expect(
() => model.setSelfHostedRegistrationKey('123'),
Expand All @@ -113,7 +113,7 @@ void main() {
);
final model = LandscapeModel(client);

model.setConfigType(LandscapeConfigType.saas);
model.setConfigType(LandscapeConfigType.manual);
expect(model.applyConfig, throwsAssertionError);

model.setAccountName('testaccount');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void main() {

testWidgets('continue enabled', (tester) async {
final model = LandscapeModel(MockAgentApiClient());
model.setConfigType(LandscapeConfigType.saas);
model.setConfigType(LandscapeConfigType.manual);
model.setAccountName('testaccount');

final app = buildApp(model);
Expand Down

0 comments on commit 2b8a3f5

Please sign in to comment.