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

fix(SecretAccountStore): saving #1309

Draft
wants to merge 3 commits 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
3 changes: 3 additions & 0 deletions src/Services/Accounts/AccountStore.vala
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ public abstract class Tuba.AccountStore : GLib.Object {

public virtual void add (InstanceAccount account) throws GLib.Error {
debug (@"Adding new account: $(account.handle)");
warning (@"While adding, there are $(saved.size) accounts");
saved.add (account);
warning (@"Now, there are $(saved.size) accounts");
changed (saved);
warning (@"About to save $(account.handle)");
save ();
ensure_active_account ();
}
Expand Down
26 changes: 21 additions & 5 deletions src/Services/Accounts/SecretAccountStore.vala
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,19 @@ public class Tuba.SecretAccountStore : AccountStore {
}

public override void save () throws GLib.Error {
warning (@"There are $(saved.size) accounts");
saved.foreach (account => {
warning (@"About to A2S $(account.full_handle)");
account_to_secret (account);
return true;
});
debug (@"Saved $(saved.size) accounts");
warning (@"Saved $(saved.size) accounts");
}

public override void remove (InstanceAccount account) throws GLib.Error {
base.remove (account);

warning (@"Removing $(account.full_handle)");
var attrs = new GLib.HashTable<string,string> (str_hash, str_equal);
attrs["version"] = VERSION;
attrs["login"] = account.handle;
Expand All @@ -121,8 +124,7 @@ public class Tuba.SecretAccountStore : AccountStore {
(obj, async_res) => {
try {
Secret.password_clearv.end (async_res);
}
catch (GLib.Error e) {
} catch (GLib.Error e) {
warning (e.message);
var dlg = app.inform (_("Error"), e.message);
dlg.present (app.main_window);
Expand All @@ -132,6 +134,7 @@ public class Tuba.SecretAccountStore : AccountStore {
}

void account_to_secret (InstanceAccount account) {
warning (@"Begin A2S for $(account.full_handle)");
var attrs = new GLib.HashTable<string,string> (str_hash, str_equal);
attrs["login"] = account.handle;
attrs["version"] = VERSION;
Expand Down Expand Up @@ -210,10 +213,13 @@ public class Tuba.SecretAccountStore : AccountStore {

builder.end_object ();
generator.set_root (builder.get_root ());
warning (@"Finished building json for $(account.full_handle)");

var secret = generator.to_data (null);
// translators: The variable is the backend like "Mastodon"
var label = _("%s Account").printf (account.backend);

warning (@"About to Save keyring for $(account.full_handle)");
Secret.password_storev.begin (
schema,
attrs,
Expand All @@ -225,14 +231,16 @@ public class Tuba.SecretAccountStore : AccountStore {
try {
Secret.password_store.end (async_res);
debug (@"Saved secret for $(account.handle)");
}
catch (GLib.Error e) {
} catch (GLib.Error e) {
warning (e.message);
var dlg = app.inform (_("Error"), e.message);
dlg.present (app.main_window);
}
warning (@"Saved keyring for $(account.full_handle)");
}
);

warning (@"Finished A2S for $(account.full_handle)");
}

InstanceAccount? secret_to_account (Secret.Retrievable item, out bool force_save) {
Expand All @@ -246,9 +254,12 @@ public class Tuba.SecretAccountStore : AccountStore {
var parser = new Json.Parser ();
parser.load_from_data (contents, -1);

warning (@"About to S2A $(item.attributes.get ("login"))");

var root = parser.get_root ();
var root_obj = root.get_object ();

warning (@"$(root_obj.has_member ("backend")) $(root_obj.has_member ("acct")) $(root_obj.has_member ("id")) $(root_obj.has_member ("client-secret")) $(root_obj.has_member ("client-id")) $(root_obj.has_member ("access-token")) $(root_obj.has_member ("uuid"))");
// HACK: Partial makeshift secret validation
// see #742 #701 #114
if (
Expand All @@ -262,7 +273,12 @@ public class Tuba.SecretAccountStore : AccountStore {

// TODO: remove uuid fallback
bool had_uuid = root_obj.has_member ("uuid");

warning ("About to create account");
account = accounts.create_account (root);
warning ("Finished creating account");

warning (@"uuid: $(account.uuid != null)");

// TODO: remove uuid fallback
force_save = !had_uuid && account.uuid != null;
Expand Down