Skip to content

lib/api: Add /rest/config endpoint (fixes #6540) - #7001

Merged
imsodin merged 8 commits into
syncthing:mainfrom
imsodin:api/config
Oct 22, 2020
Merged

imsodin merged 8 commits into
syncthing:mainfrom
imsodin:api/config

Conversation

@imsodin

@imsodin imsodin commented Sep 23, 2020

Copy link
Copy Markdown
Member

In this PR I add new rest endpoints at /rest/config to allow for partial config reading/changes. I mostly follow what was proposed in #6540, with the exception that I don't support setting individual options like e.g. /rest/config/options/maxsendkbps. To do that you do a PATCH request on /rest/config/options with just the options you want to modify in the body. Individual folders and devices can be modified (or deleted) using e.g. /rest/config/folders/*folderid*. It's manual, as in if we add new elements to config.Configuration, this needs updating (as in register new endpoint and add some boilerplate) - I am fine with taking care of that.

I added tests for all methods, but by no means exhaustively covering all endpoints.

This will require documentation updates, I'll do that after the first round of (high-level) review.

Fixes #6540

@AudriusButkevicius

Copy link
Copy Markdown
Member

I think this is beating a dead horse. We should move to grpc for that and use grpc-web to generate rest side of that.

@calmh

calmh commented Sep 23, 2020

Copy link
Copy Markdown
Member

Would that help though? I mean, just sprinkling grpc over something won't make us magically handle partial update requests and stuff like that, right, it's really just a matter of the wire protocol which seems orthogonal to this issue?

@AudriusButkevicius

AudriusButkevicius commented Sep 23, 2020 •

Copy link
Copy Markdown
Member

The right way to fix this to address the tramping issue is the way k8s does it.

Resources (aka config) has a generation number, as you post it back, you keep the generation number so the backend can verify if you'll tramp something or not, and refuse your post.

Going to absurd levels of endpoints just makes this worse as you'll have people calling endpoints many times to change many settings, causing continuous restarts and strain on everything that happens to use the config.

I guess we could have more granular per folder per device grpc endpoints, and thats what I started working on, but not to absurd level where every config option has its own endpoint.

@AudriusButkevicius

Copy link
Copy Markdown
Member

I understand that you want something now, but I also see this as a great opportunity to build out the grpc utopia I came up with as part of this work, so I'd rather the effort was spent there oppose to beating a dead horse.

@AudriusButkevicius

AudriusButkevicius commented Sep 23, 2020 •

Copy link
Copy Markdown
Member

I guess tldr, my stance is: don't think we should have endpoints per setting, we can have endpoints per entity, but that should be in grpc as I think of that as the future, and we should address tramping by generation numbers, oppose to silly granular endpoints.

There is a thing called fieldmask in proto which we could use to support patch behaviour and still not have tramping, if we don't like generation numbers.

@imsodin

imsodin commented Sep 23, 2020

Copy link
Copy Markdown
Member Author

In my view config tramping/racyness is unrelated to this. This is only about convenience: Instead of handling/serializing a huge structure you get to handle just the thing you need to. Doing lots of config changes in quick succession is just as problematic with a single endpoint as with many endpoints.

And I get the point about the grpc-utopia. And I don't mean to go against that with this PR and I really don't think it does. I did not go directly with grpc, because just familiarizing myself with it takes time, not even thinking about polishing all the nits and grits to the point that it's usable. Extending the existing api is little effort with in my opinion clearly better UX.

@AudriusButkevicius

Copy link
Copy Markdown
Member

So if its not the tramping we want to address, why do we need this?

Seems like a high price to pay for some convenience? So whats the usecase where this is a "fly or die" feature?

@imsodin

imsodin commented Sep 23, 2020

Copy link
Copy Markdown
Member Author

High price being the additional code?

The use-case is: There's a huge cluster with a few orchestrated central nodes, where changes to devices (new ones, folder sharing) happen frequently. Meaning the config of those central nodes is huge. Thus it's nice not to have to juggle/serialize/... a huge blob every time a change happens.

Not sure about how "fly or die"-ish this really is, but it feels like a sensible thing to want. And I yet fail to see the huge drawbacks/costs associated with this change that would outweigh the benefits, even if you consider the benefits to be small.

@AudriusButkevicius

AudriusButkevicius commented Sep 23, 2020 •

Copy link
Copy Markdown
Member

Thus it's nice not to have to juggle/serialize/... a huge blob every time a change happens.

I mean it's equally as nice not to have additional code/complexity that just handles something that is just "nice" but not really necessary.

Especially when that code lands on a pile of mud, ... which we'd like to untangle... so adding any additional code there makes the untangling in the future harder, as I/we can't guarantee that what you are adding now will be available in the new thing.

And then we'll have that one user who will go "but, but, but, my workflow, it's all ruined".

Hence my point, these enhancements sound great, but they should be start of the new thing, so we know it's not going away when we've hit the utopia, and that one user is happy that we're not on the starting path of deprecating something that has been implemented just a month ago.

Because yes, at some point we will want to kill the old api, so knowing it's going to die, and building non-mandatory (as in - there is no other way to do this) features seems like a waste of effort.

@imsodin

imsodin commented Sep 23, 2020

Copy link
Copy Markdown
Member Author

I mean it's equally as nice not to have additional code/complexity that just handles something that is just "nice" but not really necessary.

Sure, improvement vs maintainability is always a trade-off. However in my obviously biased view, this doesn't introduce much complexity: It takes existing functionality on the entire config (take a request body, unmarshaling it on top of a struct and then committing that struct to config) and applies that to parts of the config. If we want to change the way we process/change configs, you'll have to change it for the existing functionality already. And that's going to be the hard thing. Once that's done, I don't see how using the same mechanism on subsections of the config increases complexity.

Especially when that code lands on a pile of mud, ... which we'd like to untangle... so adding any additional code there makes the untangling in the future harder, as I/we can't guarantee that what you are adding now will be available in the new thing.

Is it really a question whether any new api will have the same monolith config get/post endpoint as the only way to control all of Syncthing instead of more granular control? In my mind that was one major requirement for anything new.

Also I don't agree on the pile of mud: If anything is muddy, it's lib/config and how we do changes and put them into effect. I change nothing about how that works (the changes to config.Wrapper only makes what is already there more consistent). I don't see us untangling/changing the current rest api, only eventually retire it. With emphasis on eventually: I don't think it makes sense at this point to prevent any improvement in the current api, just because there's an api with a better technology starting to emerge.

@AudriusButkevicius

Copy link
Copy Markdown
Member

The mud in the api comes not from the fact it's monolith or not monolith, it comes from the fact that there is no way to generate an api client, for any language, you always have to roll one by hand.

The fact that the API is poorly structured/monolith is the least of my worries.

When I mean untangling, I mean shipping v2 api with equivalent functionality of v1, hence growing v1 api surface will have an impact on what v2 will have to look like, which is what I want to avoid.

As I said I think this could be a great opportunity to start work on v2, because we're adding these endpoints because of pain with v1, and the remedy to the pain could be in v2.

I understand you not wanting to work on v2 as it's new waters, but this feels like cutting corners just to get something shipped, as at some point someone will have to come back to this and redo it in v2, spending the effort twice, rather than once. But sure, you do you, even if we disagree.

I guess I can put a skeleton down for v2 we can build on, if this is your biggest concern doing it in v2.

@imsodin

imsodin commented Sep 23, 2020

Copy link
Copy Markdown
Member Author

One thing upfront: You are totally right that this is about getting something shipped. The v2 api might remedy everything, but I do not consider it something that will happen soon (as in within this year), neither would I want it to. We should be able to have the time to think about it and make good decisions. It's definitely not that I don't want to work on v2 at all. I was under the impression that you were considering or already doing such work, thus indeed didn't plan on starting myself, but if you want to talk about coordinating such an effort - lets do that.

In my understanding of your comments there's two main points: This increases the scope of any v2 api and it's effort spent in vain that would be better invested in v2.

As to effort to reach feature parity in v2: I probably didn't fully grok what v2 entails. The way I understood it, it's a solution that allows to generate api clients in various languages plus a better wire format. And that it still requires code in Go in Syncthing to interface between the generated API and our internals (config, model, whatever). If that were true, I again maintain that it isn't inherently harder to create a sensible solution to modify the entire config object vs parts of it. If there's a solution for the entire thing, I am confident I can create something for the parts (and I am willing to do so).

Effort spent in vain is somewhat moot on my side, it has happened, and now it's about whether there's someone willing to spend the effort to review it. I also don't think this PR is that much effort.

@AudriusButkevicius

Copy link
Copy Markdown
Member

So I did put a few bricks down on v2, but again, the amount of work I put in opensource is a anti-correlated with the amount of interesting stuff I get to do at work, and how much of a craving I have for my middle aged person video gaming addiction.

I guess if there was urgency, I could step it up, but I am not sure there is.

Anyways, even if I am sad that we keep building an ever growing tower of dung, especially when the argument for making a bigger dung pile is that something is "nice" oppose to something is "necessary" or "impossible" to do in the current api, the work is already done, so I guess I just have to close my eyes, and allow the shit to keep flowing.

@calmh

calmh commented Sep 23, 2020 •

Copy link
Copy Markdown
Member

I'm not at all as sold on grpc and stuff as you Audrius and all this talk of "mud" and "piling on dung" and "absurd amounts" and whatnot is really grating and frankly bullshit in my view. There's nothing wrong with a simple REST API to GET and POST JSON objects. Sure, you need to hand craft your client, but come on, it's not precisely rocket science and we and the world have been doing it for ages.

However, at some point when the config grows it's rather annoying to have to treat it in its entirety all the time. We have concessions to this in the pause/resume endpoints that were initially "get your whole config, set a boolean, post the entire thing back again". Being able to patch the config in parts makes perfect sense to me, and even if we were to allow endpoints to dig down into each individual little value that would be essentially one endpoint with data in the path, not an "absurd amount of endpoints".

I've yet to see anything to indicate that the grpc+rest-gateway utopia improves any of this in a way that matters so I'm not sure why it would be a blocker to wait for it?

I'm also not getting if you're saying the current API is somehow crap and should be frozen for further changes and then thrown out in its entirety. If you are, this is something I disagree significantly with.

(I haven't even glanced at the actual PR yet but this seems a significant discussion to have at a higher level regardless of the specifics here.)

@AudriusButkevicius

AudriusButkevicius commented Sep 23, 2020 •

Copy link
Copy Markdown
Member

Yes, I am saying the current API is crap, it's crap on a few different planes:

  1. You have to hand-roll clients. Sorry to drop your baby on the floor, but what's the point of an api if it's close to impossible to consume. You have to spend hours creating classes that map 1 to 1 to the go code, and then PRAY you haven't missed or misstyped something, pray that we don't add something new that is crucial to set, or otherwise we might suddenly cause syncthing to bulldoze your data, like it was a case in android app, where we didn't update the java classes, and upon saving the config via the app, unset some setting which did some form of boo-boo. If that is not a definition of shit API, I am not sure what is...

  2. The API is monolithic

I am not saying we should now freeze this API and never add anything to it again because of that.
We will add new features that will need new endpoints POST /rest/folder/gosuperfast, and that's fine, as long as there is no alternative way of doing that.

I am however against adding new "comfort features", because they are "nice to have".

This PR tries to address point two, which is a valid pain point, and yes, we should have more granular endpoints, but by adding this comfort feature we are making v1 api more bearable, which will deincentivize people to migrate to v2, where bearability was supposed to be a great selling point.

I would have preferred for this change to have been a start of v2, where the bearability/comfort features like that are tought through and available, making an incentive to start an early (even if partial) migration for consumers.

The GRPC stuff will look exactly like your rest stuff now, less monolithic, more granular, but with a sensible openapi spec that people can generate a client from, so the whole "post objects via curl is cool" argument is moot.

I guess we're not all waving the same flag here, so I guess I am surprised that my go to proto changes made it through, if we're still strong believers in the success of the existing api.

Anyways, this is going nowhere, the work is already done, democracy wins, I'll shut up.

@calmh

calmh commented Sep 24, 2020

Copy link
Copy Markdown
Member

I think I'm genuinely not really understanding the problems and solutions the same way you do. This might be because I don't use grpc and friends enough. My understanding:

  1. Handrolling the config classes on the client is bad. When we add an attribute it gets lost in the roundtrip. (I fully agree with you here.)
  2. We now have the config description in protobuf. So you don't need to hand roll the classes any more, you can generate them from the protobuf schemas and use JSON serialization. Sweet, point 1 is essentially solved. You seem to be beating a dead horse here.
  3. Not re-generating the client classes based on our protobuf schemas for every release means you risk losing new attributes in the roundtrip.
  4. Using grpc or whatever changes nothing about point 3, because the proto-binary serialization is essentially the same as the JSON one in this respect.

Using grpc gives you a schema definition of the endpoints in addition to the data, but really, implementing the endpoint as a pair of GET/POST methods with a well defined schema seems like quite a small part of using any new endpoint we might introduce.

So I get you think the current API is shit, and I disagree and would rather not wake up every morning to hearing it. Even so, by all means suggest an actual improvement but saying it should remain shit to make your future changes more palatable is, again, bullshit in my view.

@calmh

calmh commented Sep 24, 2020

Copy link
Copy Markdown
Member

One more point about API consumability and grpc etc. In my experience few API users are "serious" enough to warrant the schemas and generated classes etc. Off the top of my head I can think of three (android, trayzor, gtk). In the wild API consumers I see all the time are things like

  • powershell script that polls the completion endpoint and alarms when it's < 100%
  • bash + curl to grab /connections and count them, feeding into a time series system
  • bash + curl to check for local modifications and post to the revert endpoint

I fully expect this sort of integration vastly outnumbers the "big" ones, and we'll never hear about most of them.

Our API is totally well consumable for this purpose, except for things like config changes that become cumbersome because it's a complex structure to get, modify, post back when not even using a real programming language. Making it simpler to do those kinds of changes will make life easier for a bunch of garden variety mini integrations. Adding grpc schemas etc won't do anything positive at all for these integrators...

@AudriusButkevicius

AudriusButkevicius commented Sep 24, 2020 •

Copy link
Copy Markdown
Member

We now have the config description in protobuf. So you don't need to hand roll the classes any more, you can generate them from the protobuf schemas and use JSON serialization. Sweet, point 1 is essentially solved. You seem to be beating a dead horse here.

Except that it's not. We don't use proto to json serialization, we use go struct with it's magical tags to json serialization, so even if we have proto contracts, nobody can actually use them, not until we have a new API that actually uses them.

Not re-generating the client classes based on our protobuf schemas for every release means you risk losing new attributes in the roundtrip.
Using grpc or whatever changes nothing about point 3, because the proto-binary serialization is essentially the same as the JSON one in this respect.

That's not true, atleast in my head and my vision, as the idea is that we'd have patch support using proto's FieldMask.
The grpc web stuff actually generates the field mask for you, so if you post {"name": "foo"} for a device via rest, it's able to just merge in that once field on the existing device struct without tramping stuff.

Also, binary proto (and maybe even json, I have not checked) supports carrying/preserving unknown fields, so even if the client doesn't understand that field, it's not actually lost on a round trip.

Using grpc gives you a schema definition of the endpoints in addition to the data, but really, implementing the endpoint as a pair of GET/POST methods with a well defined schema seems like quite a small part of using any new endpoint we might introduce.

Again, maybe I am spoiled by what I have at work, but I never ever had to do that. I never ever had to write any code by hand to access any API. The client code, including the code that knows what endpoints are available and what parameters they take and what not is always provided to me by the generated client. I guess having to craft the URL and know which struct to post is not rocket science, but there is definately a gap in discoverability, and it's pretty frequent that people forget that they need to pass a few query params to get things to work. Or simply can't find the method they are looking for. So sure, it's usable, but far from providing a great developer/user/consumer experience.

One more point about API consumability and grpc etc. In my experience few API users are "serious" enough to warrant the schemas and generated classes etc.

I think you are wrong here, because if that was the case, nobody would have bothered to spend their time on:

https://github.com/JodusNodus/node-syncthing
https://www.npmjs.com/package/syncthing-node
https://github.com/blakev/python-syncthing
https://github.com/retgoat/syncthing-ruby
https://github.com/tokkenno/syncthing-dotnet
https://github.com/cskwrd/FlyTops.Syncthing
https://github.com/jaycefayne/syncthing-rs
https://github.com/jetho/syncthing-hs
https://github.com/burnnat/syncthing.dart
https://share.zabbix.com/cat-app/zabbix-syncthing

I don't work in the syncthing consulting business, so I can't say what people actually use and what they don't but I suspect what you see is also not the full picture, because I assume these things exist because someone needed them, and if they exist, there are probably people using them, you just haven't had an opportunity to work with users of these.

Someone spent time doing the work because of the choices that we're made a while ago on how we expose an API.
I am saying the choice is bad, and these libraries should not need to exist, or not in their current form where people hand craft urls (which if I am reading you correctly is ok in your books, but not in mine I guess).

I fully expect this sort of integration vastly outnumbers the "big" ones, and we'll never hear about most of them.

Sure, I agree, but that's not because people think curl + sed is the rock and roll, it's because we provide nothing better.
If there was a cli easily available, they would use that, but it's not easily available.

Nobody interacts with aws/k8s/github/sentry with curl and sed. They either have clis or sensible client libraries.

Even so, by all means suggest an actual improvement but saying it should remain shit to make your future changes more palatable is, again, bullshit in my view.

Things should not stay shit, we should improve things, but we should make the improvements in the thing we believe will be the future, not in the thing we believe we will want to start deprecating.

But as I said before, I am not sure if we're rocking the same flag here, as I feel like I am the only one here who thinks that hand crafting urls and curl + sed is not rock and roll at all.

@AudriusButkevicius AudriusButkevicius left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I tried to review this, but got dizzy trying to maintain a mental stack of which branches of the handler which http method hits.

Anyways, we're not using this, so YOLO.

Comment thread lib/api/confighandler.go Outdated

// Legacy
c.HandleFunc("/rest/system/config", c.handleConfig)
c.HandleFunc("/rest/system/config/insync", c.handleConfigInsync)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this needs to be here and in addConfigHandler?

Comment thread lib/api/confighandler.go Outdated
if r.Method == http.MethodGet {
sendJSON(w, c.cfg.RawCopy())
return
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if there couldn't be some abstraction that makes this easier to read

type HttpHandler struct {
   Get http.Handler
   Post
   Patch
}

then you do

something like

m.HandleFunc("devices", fromHandler(HttpHandler{
    Get: withExtractFolderId(func(foo bar) { logic })
   Post: withExtractFolderId(func(bar, nuff) { logic })
})

func withExtractFolderIf(delegate func(folder, w, r)) func(w, r) {
    return func(w, r) {
         fid := extractFolderId(r)
         delegate(fid, w, r)
    }
))

any function pointer that's not set returns method not allowed.

Now there is a bunch of if method == get: sentJson(); return

Or I mean, there are frameworks for route and method handling, just use a framework instead of reinventing the wheel, of stripping paths to extract folder ids etc.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't fully get to something just like you propose, but I tried to go into that direction - is readability any better? And used a framework, which is need indeed, I usually am just vary to add a dependency for a tiny usage like this.

Comment thread lib/api/confighandler.go Outdated
c.GET(legacyPath, handler)
}

func (c *configHandler) registerFolders(path string) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would make more sense if the path constants were declared/constructed in these methods, the only reason they are done outside is because of the base path, which can either become a prop of the handler, or be passed in.

This is to be able to understand whether /folder/:id or /folders is used for this method.

Comment thread lib/api/confighandler.go Resolved
@imsodin

imsodin commented Sep 28, 2020

Copy link
Copy Markdown
Member Author

Saw some debug leftovers to clean-up, sorry for the review dismiss.

And as we now have github.com/julienschmidt/httprouter, we might as well use that for the other endpoints as well. Then there's no more need for the getPostHandler and addConfigHandler detours anymore: imsodin@0a6fdb1
What do you think?

@calmh calmh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just first look, will need to take closer look at the actual put/post/patch/delete stuff since I'm currently on an awkward device, but I promise to not take too long to do so

Comment thread lib/api/api.go Resolved
Comment thread lib/api/api.go Resolved
Comment thread lib/api/confighandler.go Resolved
Comment thread lib/api/confighandler.go Resolved
@calmh

calmh commented Oct 9, 2020

Copy link
Copy Markdown
Member

Did you consider a more general reflect- or JSON-based approach to the sub-operations? That is, instead of specifically handling folders and devices and stuff, instead trying to take the path from the request as an object path inside the config and applying the relevant DELETE/PATCH/PUT on that location with the object directly? It could be that you did and this would be horrible and cumbersome, or it could be the that it isn't and fulfils the requirement in a smaller way...

@imsodin

imsodin commented Oct 9, 2020

Copy link
Copy Markdown
Member Author

I considered a generic implementation with reflect, but considered the complexity (and the increased chance of buggyness coming with that) not worth the benefit. It couldn't be fully generic, there would have to be special casing for accessing items by a key/id (e.g. .../folder/id). And json and go names would need translation. Restricting rest paths to top-level config elements and folders/devices by id seems like a good compromise between granularity and implementation simplicity.

@imsodin

imsodin commented Oct 9, 2020

Copy link
Copy Markdown
Member Author

I am now using httprouter.Router for the existing rest endpoints as well and thus moved the registering such that all rest paths are in the "long list" (including the legacy/deprecated ones).

Comment thread lib/api/confighandler.go Resolved
Comment thread lib/api/confighandler.go Resolved
Comment thread lib/api/confighandler.go Resolved
Comment thread lib/api/confighandler.go Resolved
Comment thread lib/api/confighandler.go Resolved
Comment thread lib/api/confighandler.go Outdated
Comment on lines +273 to +276
func (c *configMuxBuilder) adjustGUI(w http.ResponseWriter, r *http.Request, newGUI config.GUIConfiguration) {
c.mut.Lock()
defer c.mut.Unlock()
oldGUI := c.cfg.GUI()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the thing with newGUI/oldGUI here is confusing given that newGUI is in fact oldGUI and we're grabbing a new oldGUI just to have a cache of the password? Better to just grab the password before unmarshal and pass that explicitly to checkGUIPassword (who doesn't really need to full config structs)?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tiny thing remains and I still think it matters. :) (Just in case you missed it since everything else looks fine)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then I don't get it. I now pass passwords directly to checkGUIPasswords and query the wrapper directly for password in config right now (active, old) and pass the unmarshalled password as the new password.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I was for some reason looking at an old version, but I have a suggestion for the new version as well, hang on

Comment thread lib/api/confighandler.go
Comment on lines +320 to +329
err := unmarshalTo(r.Body, &gui)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
if gui.Password, err = checkGUIPassword(c.cfg.GUI().Password, gui.Password); err != nil {
l.Warnln("bcrypting password:", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
err := unmarshalTo(r.Body, &gui)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
if gui.Password, err = checkGUIPassword(c.cfg.GUI().Password, gui.Password); err != nil {
l.Warnln("bcrypting password:", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
oldPassword := gui.Password
err := unmarshalTo(r.Body, &gui)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
if gui.Password, err = checkGUIPassword(oldPassword, gui.Password); err != nil {
l.Warnln("bcrypting password:", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh it doesn't do the diff nicely, but what I means was just to cache the password in oldPassword instead of calling on cfg.GUI() once more

@calmh calmh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM I think?

@imsodin
imsodin merged commit f0f60ba into syncthing:main Oct 22, 2020
@imsodin
imsodin deleted the api/config branch October 22, 2020 17:54
@calmh calmh added this to the v1.12.0 milestone Oct 22, 2020
imsodin added a commit to imsodin/syncthing that referenced this pull request Oct 23, 2020
imsodin added a commit to imsodin/syncthing that referenced this pull request Nov 1, 2020
imsodin added a commit to imsodin/syncthing that referenced this pull request Nov 6, 2020
calmh pushed a commit that referenced this pull request Nov 6, 2020
calmh added a commit to calmh/syncthing that referenced this pull request Nov 9, 2020
* main:
  lib/folder: Clear pull errors when nothing is needed anymore (syncthing#7093)
  lib/api: Fix debug endpoints (ref syncthing#7001) (syncthing#7092)
  gui, man, authors: Update docs, translations, and contributors
  lib/config: Sanity checks on MaxConcurrentWrites (ref syncthing#7064) (syncthing#7069)
  lib/ur: Fix panics in failure-reporting (fixes syncthing#7090) (syncthing#7091)
  lib/ur: Fix panics in failure-reporting (fixes syncthing#7090) (syncthing#7091)
  build: Update dependencies (syncthing#7088)
  lib: Remove USE_BADGER experiment (syncthing#7089)
  build: Update notify (fixes syncthing#7063) (syncthing#7080)
  lib/api: Fix /rest/config path and add methods to cors (ref syncthing#7001) (syncthing#7081)
  lib/api: Allow OPTIONS method in CORS preflight request handling (ref syncthing#7017) (syncthing#7079)
  gui: Fix another undefined variable access (fixes syncthing#7077) (syncthing#7078)
  lib/config: Check for "msdos" when detecting FAT FS in Android (syncthing#7072)
  gui, man, authors: Update docs, translations, and contributors
calmh added a commit to calmh/syncthing that referenced this pull request Nov 11, 2020
* main: (42 commits)
  gui: Initialise sharing when accepting new device (fixes syncthing#7113) (syncthing#7114)
  gui: Initialise sharing when accepting new device (fixes syncthing#7113) (syncthing#7114)
  lib/model: Prevent test deadlock (syncthing#7110)
  lib/api, lib/db: Add file debug endpoint (syncthing#7095)
  gui: Add advance config port mapping to gui (fixes syncthing#4824) (syncthing#7017)
  lib/tlsutil: Add O and OU to generated certificates (fixes syncthing#7108) (syncthing#7109)
  all: Add untrusted folders behind feature flag (ref syncthing#62) (syncthing#7055)
  build: Update notify (fixes syncthing#5360) (syncthing#7106)
  lib/model: Fix locking when resending cluster-configs (syncthing#7107)
  gui: Remove superfluous translate in previous (ref syncthing#7102)
  gui: Add warning when JavaScript is disabled in Web browser (fixes syncthing#7099) (syncthing#7102)
  lib/model: Add done chan to track folder-lifetime (fixes syncthing#6664) (syncthing#7094)
  lib/model: Send indexes for newly shared folder (fixes syncthing#7098) (syncthing#7100)
  lib/folder: Clear pull errors when nothing is needed anymore (syncthing#7093)
  lib/api: Fix debug endpoints (ref syncthing#7001) (syncthing#7092)
  gui, man, authors: Update docs, translations, and contributors
  lib/config: Sanity checks on MaxConcurrentWrites (ref syncthing#7064) (syncthing#7069)
  lib/ur: Fix panics in failure-reporting (fixes syncthing#7090) (syncthing#7091)
  lib/ur: Fix panics in failure-reporting (fixes syncthing#7090) (syncthing#7091)
  build: Update dependencies (syncthing#7088)
  ...
@st-review st-review added the frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion label Oct 23, 2021
@syncthing syncthing locked and limited conversation to collaborators Oct 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Config PATCH/PUT/DELETE API

4 participants