Join Jeremy Chone for a live-stream session dedicated to Rust programming, software development, and practical engineering discussions. This session provides an opportunity to explore Rust development through a live interactive format, with discussions around programming concepts, implementation techniques, and real-world software engineering challenges. Whether you are learning Rust, building backend applications, or exploring modern systems programming, this livestream offers an opportunity to follow an experienced developer's approach to solving programming problems and sharing technical knowledge. Tune in for practical insights, developer discussions, and an engaging exploration of the Rust ecosystem. What you'll explore:
Practical Rust programming and development.
Live software engineering discussions.
Rust development techniques and best practices.
Real-world programming challenges.
Developer knowledge sharing and technical insights.
Exploring modern software development workflows.
Keywords: Jeremy Chone, Rust Programming, Rust Live Stream, Live Coding, Software Engineering, Rust Development, Backend Development, Programming Community.
Episode 41 completed. Send me Episode 42.
Audio and video play straight from the show's own hosting. PodSubs stores and serves no media.
Transcript
From the show. Tap a time to play from there.
Speaker 1Okay, so we should be live. I'm going to set up my stuff there and we're going to wait a little bit. So today the topic is going to be about Rust web app. So that is what it was requested. I mean, when I did a little poll here, this is a membership only video. live stream. So I've started
Speaker 1to live stream things in ad hoc fashion. So to get better at live stream. Hey, Roberto. Nice to see you. And so, hey, Mouchli. So, yeah, so today we are going to, hey, you are the three top guys here. So thanks a lot for joining. And today we are going to follow, I'm going to follow the polls that I've done. So we're going to do a Rust web app. And also what I've done this week is I've done quite a bit of live. I want to get better
Speaker 1at live. So rather to train too much on you guys that are super cool members, I'm doing it as a public live. And it's just when I do coding for my own little tools or whatever, I do this live. So like this, I can practice better and hopefully I can get better at it. So it's something I need to learn. So today we're going to talk about the Rust web app. And there's a couple of things that I want to do. So it's going to be a live coding. And then always feel free to ask questions
Speaker 1that I will be more than happy to answer. And then take the time to explain the things and so on. So let's go and start it. So let's see. I'm going to share my screen. Maybe quite a bit on my screen because now I can see the chat. So I'm doing some experiment. This is kind of a live stream. This guy here, this is not the topic of today, but this is kind of a live stream that I'm
Speaker 1going to do. And I'm trying to now explain a little bit when I do the live stream, what I'm doing. So that is a do toggle, which is I'm using a stream deck to control my OBS and things. So that is one of the things that I'm sharing in the live stream, so when I do my little code. That's why I had that there. But this uses the same system that we have over there, which is now I have these little cool things, and now we're back
Speaker 1to our Rust. This one is a good one. To our Rust Nx. So that allows me to have this kind of diagram over there, and then I can turn it off like that. So hopefully it makes sense. And so let me share my screen. So I am on the Rust web app thing. So again, this is the source code here that we have available. And I'm just
Speaker 1doing a quick comment here. I didn't fully did it. When I do a git c is my alias to do a git commit. I added quite a bit in the gitignore. So that is a way that I like to do my things. I ignore everything which is with a dot, star kind of things. Let me see. I don't know why. Sometime. Yeah, sometime I don't have the
Speaker 1dot when I press. So... So this way, I know everything that starts with dot, except dot ignore, except what I say. And same thing with underscore. That is just my practice. And then I know a lot of these kind of things. If I have a node.js somewhere, some things, I try to ignore them. The rest, I change the target from being at the root at the end, such as I'm more aggressive in removing them all. And then one thing that I allow is a dot cargo slash config.
Speaker 1So that is one thing that I'm allowing because another way that for now, we're using it to set up our environment variables. That is what we have over there. So that allows us to set up the environment variables. Eventually, so when I'm going to, sorry, I'm being slow. When we're going to have this kind of development and we're going to go there, is the web server, which is
Speaker 1what we're developing right now, in fact, we're going to have it all the time running in Kubernetes. Because the whole point in production coding is to reduce the distance between development and production. And it's not like, oh, you're in a cloud environment and therefore the distance is shorter. That's not correct. For example, if you were in a cloud environment but deploy everything in EC2, bare-bones EC2, and then you deploy on Kubernetes, that would be a greater
Speaker 1distance than deploying everything on your local on Kubernetes and on production on Kubernetes. That is the thing I'm gonna say. So the point here is, eventually, and there's quite a bit of work, but that is what I had with my Bryce Snow company here, using Java and then Node.js and as well, and We had that model where we develop everything locally, and then we just deploy it, and it was just a delta. So there is some trick
Speaker 1to do to be able to do that, and that will be the goal here. So right now we are going to develop that like this, and eventually I will do a Docker image, Kubernetes files, and then we'll have a whole process. It's going to be pretty cool then because everything can be Rust can be super efficient. Now, with Rust, one of the trick, and that's how I'm going to explain that a little bit. When we have Node.js
Speaker 1or even Java, you can compile on your host, meaning macOS, and it doesn't really matter because when you compile JavaScript or TypeScript, you don't compile it, you transpile it into JavaScript. But even Java is bytecode, so the host doesn't have to know about the target in most of the cases. But with Go or Rust or C or C + + or Z or whatever, you have to know the
Speaker 1target because you cannot compile. And then after this trick where you can cross-compile, sometimes you cannot cross-compile, so you have to have all these kind of things. But bottom line, this is one thing that I need to solve, is to say when I'm going to have many services like that, we don't want, and because they are going to be part of this architecture that we have, I put it there, put everything there, you know where we have the libs,
Speaker 1this one needs to be a little bit updated, but it's close enough. We have the libs and we have our server over there. We do not want every time we have a new service to recompile all the leaves and everything because Rust already takes some time to compile. And then if every Docker image has to compile their own things, it's going to be very tricky. So in local development, what I want is, I'm going to say it's a hack, but I'm going to say it's a production hack. And that means that now we're going to
Speaker 1have a builder Docker that will build all of these guys and put the binary which won't work on mac which is fine will be the binary at the right place somewhere and then the docker image via kubernetes cmo will map that directory or file or whatever as a volume or whatever and that will allow us to have one Docker that compile all of this beast, which cannot
Speaker 1be our host, typically. So that needs to be at least in a Docker image. And then it would compile all of these binaries, and then the other one can use them, and then we'll restart it. So there's quite a bit of a tedious work to be done. And I've done that in many ways in Node.js, with TypeScript, there's other problematics there. So it's tedious to do, but once it's done, it's part of the blueprint. So it's a one-time tax in a way. And then after you
Speaker 1can reuse it and for a little bit of hack, which is just development, so it's not production anyway, we can get a very fast development cycles. So that's my goal with Rust. And this is why it took so much time because I need to have the right project and stuff. And now I do have the right projects to do this kind of work. So I'm going to focus on that. So that would be pretty cool. So hopefully that makes sense. Now I'm going to get better at a live stream. I'm learning also with my experiment here with a public live stream. Feel free to ask
Speaker 1questions anytime. I will read them. But one thing I'm not going to do is what sometimes I do when I'm on a live call or whatever, I say, hey, does that make sense? Any questions? Because we have a delay. And so if I'm waiting for the answers, make it very... not very productive. So I'm going to keep racing, but if something doesn't make sense, please tell me. me we'll go back yeah so that is the whole point of the sessions and we're going to have a lot of them and so by the way these sessions here which
Speaker 1is going to be you know the live stream member session i will always archive them i will not delete them yeah so you guys can always go and see them The session that I'm doing, like a lot of, yeah, yesterday I did two or three or whatever, and then today I'm going to probably do two or whatever. Those guys is more disposable sessions. If it's a good one, I might put it unlisted for the people that were there, and eventually I will put it in the live stream only, yeah,
Speaker 1for you guys. So people that have been there or the public will have a little bit, or the lower member will have a little bit and then you guys will have the good one. But I don't want to put all the session because sometimes there's not a lot of value. So rather to have you guys spending too much time trying to find the good values, I prefer to discard them. And then one day I need to have a process to perhaps have the little parts that make sense. Okay, so back to this guy. So the
Speaker 1thing I was going to do here is I was going to commit this I have my russweb10x extension that you can find here, russ10x. So this one points locally, I think, but you have it on. It's the same that you have there. And that allows me that when I am on gitignore, I do this. I have the min,
Speaker 1which is just give me that. And I have the more that give me all of this. Okay. So this is everything I have right now. So here again, I'm being very careful because in Git, if you commit a big file that you don't want to remove it completely, because otherwise it's part of the history. So everybody download it all the time. So you don't want that. You can remove it, but I always find it painful. So I'm trying to avoid and to be as conservative as possible.
Speaker 1One of the catch of this approach is if sometimes you want to do a PNG or whatever, you have to make sure to exclude them, exclude from the exclusion to make sure that they get saved. So change. Put the dot here because it's minor. Then I have plus when I add, minus when I fix. and uptick when I hang on something. And it's very subjective, so it doesn't have to be, but it gives a little hint.
Speaker 1When I'm doing production coding and when my team is doing production coding, what we have is, we have things where usually we try to have one ticket, one commit. Not trying to be too dogmatic about it, But I will do a git c, and git c is an alias, so you commit, I think it's commit dash a dash m, something like that. So I do a git c, and then usually we do, okay, this is for the issue 34, and then fix, and then we copy the title, usually,
Speaker 1of the stuff. And so this way, It's a nice way to see what you have done. Sometime we have two tickets, two commit for the same ticket. If we miss something, we don't want to change, do a git push for. So it's okay to have two commit. We try to have one, but not too dogmatic about it. There's one thing also in production and here I'm saying everything. I'm sharing all the production tips here with you guys. So if you want to have more coding and stuff, let me know. Yeah, we're going to go to coding,
Speaker 1but there's a lot of production. The next one we do as well, which obviously I'm not following here because this is kind of a blueprint, is we never code on main. So main is gold. And when you do a cloud application, so there's many ways to skin the cat. But the way that we like to skin it is to say that... I'm sorry, but I don't know if you hear it. but is to say that main is
Speaker 1gold and main is what has been deployed. So when we deploy it, we put it there. And I'm sorry, I have still the overlay here. So this is the thing I was saying before. But main is gold and main is what has been deployed. So we have a drop number, we'll talk about that later. I might do at some point, my hope is that I will use,
Speaker 1so I'm already using this blueprint for some of my clients. And so what I do is say, hey, go to the blueprint and this is our starting base. And then after we make it client specific, obviously. There's one thing that I might do at some point is to take the blueprint and make my own Brysno app. So Brysno is my consulting company, but I would like to have an app that allows the client to see the architecture, the recommendation, and even with AI and all of that.
Speaker 1And I might put it open source in a way because it's whatever. And then I will use a blueprint. And so we'll have a good use case of this. So anyway, so I'll do that. And so the point is, many goals is what has been deployed. Then usually what we do is we work on the dev branch. And the dev branch is a second gold. So everything gets merged to dev branch. And main is merged with dev
Speaker 1branch only when it's deployed. So usually you don't even need to do a repase. And then sometimes we have like feature branch or next-gen branch or whatever, or experimentation branches out of dev. So that is the way it works. And the developer work on their own branch and then they do pull requests or they send it to a developer that merge everything, everything. So we have this process that works pretty well. And that works well for cloud application where anyway, when you have a cloud application, most
Speaker 1of them, you have one source of truth, which is production. That is the last guys that you deployed. So that is really the thing that everything should be based from. Okay, so today there's a couple of things that I would like to do. So I'm going to assume that you guys are familiar with the Rust web app, since every time you're asking for Rust web app. But if you have questions about Rust web app, why we did the
Speaker 1things the way we did it, or whatever, feel free to ask. I'm more than happy to answer them here. But right now I had two things I wanted to do. One thing that I did is one of the live stream, which I think I give it to you guys. It's available. It's a Rust web app live stream. I'm looking at my studio over there. Content live. Yeah. So it's a
Speaker 1live coding that you should see it only, you guys, yeah. Yeah, live stream and QA. So it's, you know, one of the live streams. This one was a good one. So I put it for you guys. So I put it there. And so you have the live. And so I'm going to review this code here today because I don't think you manage to do it, to see it probably. So going back to my little dependency here. So this is
Speaker 1kind of the login flow. Remember? So when we do an API login, the user on the client side, usually that is a web browser scheme because API is different. They get a token somehow. Usually it's a login in a web UI. they get the token, and then they give us a token. So that is another business. An API key, I'm going to call it API key results on token. And then this one here is the user
Speaker 1kind of login, and then it goes login, and we do a first by username. So that is what we have. If I go to the code here, first by username, so that is what we have. There, yeah? And the cool thing here, and this is the amazing thing with Rust, yeah? So it's a little bit tricky to understand it, but that is what I love, yeah? Even in a strongly type,
Speaker 1fully type-based business, we can have a function that seems like returns different type. That is what it seems like. In fact, what happened is, again, in Rust, every time we have generic, rust underneath no no no it's not the same function it's another one so it does probably i don't know what it does but sometimes they like dollar sign or whatever and then they add you know and and it's a compiler that kind of route yeah
Speaker 1because when you call it now i have to say what i want to get back either with turbo fish or by specifying the return type. And when it does, it will pick the right one. So the function here will, it's not like Java where you do a if instance of E or whatever and you do a if else. The reason why that works, and so that is a trick, the catch of that is the reason why that works
Speaker 1is because let me explain, is because of that guy. Yeah? Because this guy also take an E. Yeah? If he didn't, then that wouldn't have been an E. And there's other functions like that that works because ModQL or whatever, I'm making sure that they take the generic as well. As long as you can cascade the generic enough, and usually
Speaker 1this is why we have the user by, because if we go to the user buy, I don't know why I'm getting into this case, but it's actually a very useful pattern in Rust. And even me, sometimes I need to remember, I say, oh yeah, I forgot to do this. But like here, user buy, it has, I say, okay, this is a trade, but this trade has to also implement all of these guys. So that is for SQLX. I think I'm almost sure that is for the whole thing to make sure that it works. And that is
Speaker 1for my fields business. So then once we have that, the cool thing is then the one that get the E say, oh, I know, like for example, the SQLX, they obviously do not know about my staff has fields, the ModQL, but the SQLX, they know about A bound with tree struct, with tree trait. Yeah, so here. Oh,
Speaker 1a bound, yeah, this one has three types. It's not tree struct, yeah? The query as with has three types. That is a way that SQLX works, okay? Because you have one for the database, I think, one for the entity, and one for the other one, yeah? So if you do this, DB, that is a lifetime. That is a DB, the first one. That is the output, and the A is the argument. And the argument, they have their own macros to... I don't know if they have macros here,
Speaker 1but they have their staff to make sure that they can take stuff. So that is how they get things. There's a whole argument about saying, well, if you do that, your binary size goes up. That's true, because it's staff. But at some point, the value that it gives back is huge. And the way that the binary goes back up, you can actually manage it, which means that within the implementation, here I'm going to go this one. This one is just,
Speaker 1you just passed it, yes, in this case. But basically you do, so this one is going to be, kind of complex here, but let's say, yeah, I don't have a good example here, but okay, yeah, so this one is good, yeah? So I have E, okay? I don't know the type of E, but then I have E, C, idents, which is the identifiers, yeah, for the columns. So the
Speaker 1thing here, that is something that I implemented, in my mode ql, okay? But let's say that here what the compiler will do is every time we do a user by like a user for auth or user for login, it will create a new function, okay? This is not too big. So that will be replicated twice, but that's not too big. If it were too big, I could put that in an inner function Yeah, either within the
Speaker 1same function is fine, and with a concrete type. And then if I have the concrete type, oh, I will get whatever I need to do stuff. So I will remove the generic, yeah, and I will have the one with the concrete type. And then in this case, then it will do the right job and I won't duplicate the code all the time. Like in this case, it doesn't really make sense because even I wouldn't, do a call for like first by username for the other type
Speaker 1because I will have to duplicate more or less all of those guys anyway, kind of. So you have to like judge about what you want. But this is very powerful here as a model. So if I go back here to my sketch, what we do here is a first user by username to get these guys. such as we can create the token. And so here we get the token sort kind of business. And then after we get the username and so on. And so that is
Speaker 1kind of the concept. And then once we have that, then when we want to create the the middleware auth resolve. Now, we don't need these guys. We don't need those two guys. We just need the ID, the username, which we don't even need, but eventually we can. Or perhaps we use it for this guy here. This guy, you can use username, ID,
Speaker 1or whatever you want. It doesn't really matter. And then you have the token sort. And that is what you use to create this signature here. So the signature is what we use there. At the beginning, we were using SHA-512. So if we go to my git log. What is this guy? They were cool. I need to learn how
Speaker 1to use the... Inside VS Code now, they have the whole git. kind of thing so I need to learn how to use that for this video but usually I do a git log and then if you see up sorry if you see there we have this guy where we updated to black three so the way we updated to black three we're going to look at it oh sorry sorry a mistake I need to find a way to not do that anymore so I was saying if
Speaker 1you do a git log you have the cargo things over there. You had the cargo, I'm sorry, not the cargo, the os black three, so this guy. Okay, so that is what we did last time and we're going to quickly review it. And it's very simple here, what we did. So that was in the lib os. In the lib os,
Speaker 1I have two, subfolder one for password and one for token and they are independent so you see that here i do not have an error for my libos because i don't need to cascade the error all the time to the parent module what i want is the pw for for this case yeah i want the pw to be independent from the token so i can use them when i use token i don't need to know about stuff from pw so that's why i kind of split
Speaker 1the error yeah so they have their own error and then this one has its error and then this one has his own error which is different guys okay now in the mod here the only thing that we change so one thing i like to do is we have the token type So those is the type, yeah, that we have with the token, and then the identifier and the expression, and then the sign, B64. Those guys are
Speaker 1unclear because I need some of the logic. And then this guy is B64U already because we don't care. It's just a black box. So the signature, when we sign, it will always send back a B64 URL. And then I have some stuff here that is plumbing in a way. And then I have the web token here where I generate the web token. And then I've validated the web token. And for the generate and validate, I have the same thing.
Speaker 1Here's the thing I was saying in the video before is I have the underscore to say it was private. This is bad. I think it's a bad pattern. So I'm going to rename. I will do a commit only for that. I didn't want to put it the last commit. I was experimenting. sometime I experiment with new things that go through my head in just one module and when they are bad I throw them away yeah so it's important to always experiment because otherwise we stay with pattern from the 90s yeah so you always want to change
Speaker 1it and then this one kind of conflict that was the thing I was thinking at the time as well but I wasn't really sure But it conflict with the idiomatic rush when you do an underscore, means that you are not using it. So it's not like a private business. So I think it's fine to say just to have the normal name. And in fact here, let's do that now. So we're going to F2, and I will say this is fine. I already have the, okay. So that will
Speaker 1be perfectly fine. I will do a cargo test. I'm not sure if I need to have the database running, so we'll do, but usually I will do a cargo test before do the start, but here if it compiles, it cannot fail. And then in the private here, so that is where we have the private. The token signature here is this guy. We're going to remove that as well. And so that is where We signed this thing. So
Speaker 1before we were using SHA-512, and now we are using BLEC3. Okay? The goal here of the Rust web app, and this is just because of my background, we do big apps with compliance and all these kind of things, highly secure and so on. And so there's some best practices that don't cost more to do them well from the start.
Speaker 1One of them, and we used to not do it. It's funny because they were another kind of company to say, well, if you really want to be secure, you do that. I don't think that even banks does that, but we do it. It is basically these things here that I'm showing, which is we have a sold pair user for the password, as well as for the token sold. Okay, so that's usually it's like, not a lot of people do this
Speaker 1kind of things. Usually they just have a global key. And then that's it. It doesn't really hurt anything. And it's kind of increased the security a lot because usually the global keys that you have to do your token, don't use the same anyway, for your token or for your password. But the keys that you use for one or the other are usually stored, for example, for us, we store that in KMS, because we use Kubernetes, so that is environment variables that get injected when the staff
Speaker 1and so on. And so we put them on the KMS. The benefit of that approach is that now to do the hash, you have to have access to the KMS store, which is usually encrypted at rest, but you will have to get this key, plus a key in a database. So it gets much harder, and more of the key on the database per user. So that is probably the highest level you can go, as far as entropy, I guess.
Speaker 1So that is what we use. Now, there's a trick here, which is, before when you created the SHA-12, we use a key as a key in SHA-12, I think, or whatever. And then this one, if you see here, we use a key like this, update key. And so the key here, the type of key is this guy. And that works pretty well. The reason why we did that is because there's a cool kind of new So let me see.
Speaker 1So that is minor. It's not. Let's clean up. Yeah. Token private function renames. The goal of each commit is not to be too dogmatic. It's just that at least people that are involved in the project should find that duck one way or another. Say, OK, just clean up. No big deal. Yeah, or something like that. The reason here,
Speaker 1why we put key here, in a dogmatic way, and I'm not a crypto expert, so we need to know where we're expert and where we're not. I'm not a crypto expert. I don't know, and I could ask, and I think I asked at some point. But I'm sure that there's a difference between putting a key in a hasher and then doing the update for the content. So the right way to put a sort is like this. You add it to the content one way or another. Now, What is the difference between putting the key in the
Speaker 1content or the key as the key of the thing? I'm sure there's some crypto algorithm difference and that it's, I would assume is a little bit better to put it in a sense, but both works pretty well. I'm pretty sure. Now the trick of this guy, they do have a new with a kid, a new hasher kid hash function. So I'm sure, again, in the math, it's probably a big difference. The trick of that is that
Speaker 1it seems to be, if I'm reading it right, that that is a fixed length. The fixed length, I don't know, it's 32. Well, right now, I do not want, right now, my keys... I do not want my keys to be too dependent on a hashing of a hasher. So if I go to black four, and then black four say, oh, no, it's not 32 anymore. It's 48 or 16. Then it's like, okay,
Speaker 1I need to change the key as well and everything. So that's why I was making the calls to say, well, I don't think I'm losing too much about not using the key. I'm sure there's less of entropy or whatever it's called. but I think it's way enough for a token. So that is the judgment call here that I made. And then we base 64. Now that we have that, everything works. Now, the way that I've implemented this kind
Speaker 1of function here is, and that is important here. The thing I was saying in the ad hoc stream is I I don't believe too much at the test coverage number. The highest is better. I don't think it's true. I think it's better to have only 50% of the things
Speaker 1that could break for whatever reason, coverage. So 50% of the things that could break rather than 80% of many things that will never break. And we missed 10 or 20% of things that could break. So that is a thing. So for example, if you have an algorithm, I'm going to do a super extreme here, which is obviously silly, but if you have an algorithm that does one plus one equal two, you could write a unit test about this, but yeah. I mean, yes, you could, but do you
Speaker 1really want to do it? Now, if you have something that does a login and everything and stuff, on this one, you want to make sure you validate and everything. I think unit test is pretty important because this, if it breaks, is kind of a pain in the whole kind of things and stuff. And so we don't have to, like, unit test. And in a way, a hash is a hash, so at some point you can't, you know. But my point was not to try to over... unit test this one,
Speaker 1but to have some unit tests at the validation. So that is what I had before, which was very nice. So I had this two test, this three test. Okay, I had the display and the from the parsing to make sure that I can parse. So those are important actually, because I wanted to make sure that when I had this kind of format, the things was passing out. So that is a from string and then a to string. In this case, the signature will be broken, obviously, but
Speaker 1it doesn't really matter because here I'm just testing that get the right thing. So that this one is base64 URL, this one is base64 URL, and then this one is clear... Okay. The comparison is clear text because it restores a clear text. So that is the things which... Yeah, I mean, in this case, that was already, it's assumed to already be encrypted. So that was a test I had, and then the
Speaker 1other one I had is a validator. So what I made sure to do is that I can do a cargo test, dash P. So now I need to do a dash P because it's, It's a thing there. Okay, I think I have it in the readme. So my recommendation is to put those guys in the readme because it can get tricky. So that is to start. That
Speaker 1is to dev. Okay, that is the thing. So I like to use CargoWatch, yeah. So you can use CargoWatch or Bacon. I made the video about Bacon. Bacon is pretty cool. It's very cool. On CargoWatch test, for watching the test, it's tricky because if you put no capture, there's some errors you don't get. And if you don't put no capture, then you have to always switch back to roll mode and make a keyboard shortcut. So I use Bacon to run things and run examples. For my test,
Speaker 1I'm going to still use this guy here. So now one thing I can do is something I think like that. I do a cargo test and I do the no capture. I like the no capture. I'm going to go and look at the token. And so the way I like to do it, and here because we are going to target only one lib is not a big deal but the way that i like to do it is that every test is unique the name is unique for the
Speaker 1whole at least crate because that simplifies a lot when you do your your testing you just you can just we're going to test this one which one we're going to test we're going to take this one yeah And then you can copy paste there and you don't have to do all the things and stuff. And then I also make sure, there's two things I make sure, is I make sure that the big agent, yeah, the order
Speaker 1of this is from more generic to more specific. Such as if I want to say, hey, I want to test all of the web token, error or not error. Or I want to test all the validate, yeah. And in fact, here, to be honest, I did it wrong. The talk, oh yeah, okay. I did it right on top and then wrong below. And the reason why, which is weird for me, because usually I don't really care too much about English, but it's because I wanted to speak English here. Yeah, so I copied the test function,
Speaker 1which was validate web token. But in fact, it's better to have token here and then probably you don't repeat it there. And that will be allowing you to say, well, I want to test all of the test token guys without having to worry about. And that will work well. So we're going to do that, actually. Let me know if it's this kind of content you want, or if you want to do more coding, we need to add organizations into the... code base that might be a little
Speaker 1bit more involved that what we can do is this stream or in an hour and a half i don't know how long you have guys but right now i'm explaining that which is a lot of my techniques of how i do coding and how i always evolve code and stuff if you want more stuff or more code on anything feel free to to chat i will adjust all the time so back to that So right now here, what we're going to want is we do the dash P. Yeah, it's exactly what we want. That is what was not
Speaker 1100% sure that it was the same dash P, but it is. And then we're going to make one function, which is this guy. Okay, so that we just copy this guy. And then we press stuff and then we hope that it works. Okay, now the reason why I like to have the no function no capture dash dash space dash dash no capture is that now I can go there and I can if I want for whatever reason I can do a let no I can do
Speaker 1a one piece so that is my I think this one is just has display so I should be able to do that and now I can see boom I have that if I wanted to check or whatever I was like, oh, okay, cool. This is what I was expecting and stuff. So I did that when I was fixing the code. If I didn't have this test, I would have created one before changing from SHA-512 to bcrypt.
Speaker 1And I think in this case, I probably was TDD. So the TDD is like everything. We should make sure that we are religion-less and it's all about net value all the time. So it's not about saying, oh, you know, I need to be TDD because I put it on my LinkedIn or whatever. You can put it on your LinkedIn. But when we code is we are TDD when it matters, but we don't have to be over TDD. Now, for me all the time when I start coding, I always try to myself to be more TDD for many things.
Speaker 1So that is my stuff. And when I say TDD, I don't even... I didn't read the books or whatever. What I'm saying is, say, when you start a function, more even in Rust, because Rust, to do tests like this with CargoWatch or whatever, or Bacon or whatever, it's amazing, yeah? Because you can just pinpoint exactly what you want, and because of the way the module works, system works and the way that the whole thing works is that it will always uh be private i mean always it will be you can test your private methods and stuff so
Speaker 1for me this is another thing that i think is being overlooked in in russ is yes the system is not perfect i'm sure people say well we can do xyz but they solve the right thing uh overhaul and it's it's allow us to be very very fast here so between the integration testing the examples that we can run and then the unit testing, yeah. So anti-corrosion testing, unit testing, we have everything we want. So this one is unit testing in a way. And so then after,
Speaker 1so when I was, okay. And then after I do that, and then when it's fine, I do the assert, and then I move on. Now this one, Oh, yeah, because validate return an error. So here, the check here is basically doing zero, there will be other ways to do it. But this works pretty well. So now, the things that I'm going to do on this is, I'm not happy about. Yeah,
Speaker 1so The reason, I understand myself, I'm not too mad with my old self, is the reason why I have this guy over there, he has this name, and I don't have the token prefix, is because that was the name of the function, which makes sense because that will be a function that people will use, so we don't need to be too Yoda-style. But this guy here, I'm going to make it Yoda-style, and I don't need... I don't need to press F2. I could press F2, but
Speaker 1I'm going to do token and then validate. That is where it gets a little bit weird there because I don't want validate web will be weird. So I can be redundant. It's fine. It's for testing. And then this one will be a token. Okay. And now that we have that, okay, I should be able to I'll do this.
Speaker 1And that will test all the tokens. And before pressing enter, I'll stress. Boom, that's it. So that I use this scheme a lot all the time. Because it saves me time. I go to one, make it work with one, then scale back, making it work with everybody. That is what I do. So we do stuff. Git log, I like to do that. I do the search here to make sure I remove this guy. And then I'm going to do git commit, git c, sorry. And then code cleanup.
Speaker 1Token test. Doesn't matter. And then GPO, git push already, and then that's it, okay? So that is my way of things. Again, if you want me to talk about something else, feel free to ping me here. And by the way, if you can tell me until how long are you guys planning to stay, I can stay until 1 or 1.30 or even 2. And so as long
Speaker 1as you guys want. So feel free to tell me when you have to check out. So that is basically what we did for the black tree. And so that is my process of the time. I'm always trying to do this kind of things. So now we go to the big one. And I'm not 200% sure that we're going to, I'm going to work hard to try to make it. So one of the models that we have
Speaker 1over there yeah deployment with docker files yes but that i need to prep yeah so i want to make sure that i'm not wasting you guys times there's a lot of things that i need to play with um and i've started i had a whole local branch on that i think i still have Yeah, I think it's
Speaker 1this one. Yeah, I need to learn with VS Code how to do the branch because I could go there. The problem is sometimes I use fork. I love fork. There's one thing in fork. I need to send an email to those guys. I didn't find a way to zoom. So it's super small for you guys. so i don't i don't find a way um yeah yeah so i
Speaker 1need so my goal is is to do that yeah so at some point i have that so if you go to the branch this but i'm not pushing it because i don't want to waste people's time which is actually not even there yeah okay this image was a bad name but That was my builder. Yes, I have the image for this guy, for the builder. And again,
Speaker 1it's hard to see here and I cannot really zoom. But that is the whole thing. I need to do the stuff. We're going to probably have a folder, k8s for Kubernetes. And I think the Docker file will probably be there. So my current question is to say, well, Do I have Docker files there? Which is a little bit what I have in the JavaScript. I have it there.
Speaker 1It could be possible and stuff. Or what I have it is more there. So I will have services, for example. web server slash Docker file. Now the problem with Docker file at some point our staff is sometimes you cannot, well, there's a whole discussion again, because the things that I don't want, I'm going to go a little bit here, but the things that I don't want is I don't
Speaker 1need this Docker file to, I don't want this Docker file to be the one that build web server. Yeah, so I will have kind of a builder docker file. And this one is the one that build and the stuff. So I need to find this stuff. And again, the big change here compared to what we used to do
Speaker 1with Java or even things is the one that compiles has to be, cannot be the host. So it adds a whole kind of little dance that I need to do. And the trick here, just to the side, we currently not have set PWD change. OK, so actually, I think I have something cool. Let me see if I can do that. I got some feedback here, not some time.
Speaker 1I'm not reading. Wait a sec. probably seeing behind the scene sorry I'm doing live live crafting here whatever it is okay so now you see it there yeah So
Speaker 1that is a good question. Yeah, we currently have no default set password and chance password. Should there be any other step for the token? So other than checking whether a password has been set previously and stuff. Yeah. So we do not have this is good. This is a good point. Let me think about it. So first of all,
Speaker 1we do not have a register API. So that is one thing that probably at some point we need to add a register API. The way I will do a register API is, let me show this guy. The way that I will do A register API is, I wouldn't have obviously RPC because in my head, the RPC is
Speaker 1for things that are logged in, in my head, sorry. In this application design, the API slash RPC is for things that are logged in. If I were going to do an API RPC for everybody, people that are not logged in, I would probably namespace it, like a P API, like public API or whatever, slash RPC, such as I have the endpoint that I know goes there and then, you know, it's tight. And then I have the endpoint that is public. So that is what we have in our code today. In our code, if we go to
Speaker 1if we go sorry if we go there the route rod rpc we should have yes sorry which will have
Speaker 1uh the middleware here which is require which will be require middleware context require so it requires a context okay so this route rpc say you cannot call me if you don't have the context which is basically if you are not logged in okay um so I will have another kind of route RPC, probably routes public RPC that
Speaker 1wouldn't have this, this route layer. Hopefully it makes sense. Now, going back here to the requirement to say, hey, how will we do a register? So that will do a register like that. So we'll have a register and then the register. So that will be the API that if the user use web app, It's not logged in or whatever. They can click register, and then that will create the stuff with a password and stuff. Now, there's another use case,
Speaker 1which is now you have an IT admin user that is going to invite someone or you want to have the reset password or all these kind of things. So, for example, you forgot your password. How do you get back the password? Yeah. So for that, the beauty of this token system works extremely well for that as well. Because you can put the expiration on 24 hours or 12 hours or six hours, whatever you want. And that is a token. So you can have another token sold
Speaker 1if you want or you want to use this token. It doesn't matter. And you will have a forgot password reset or whatever. And then with that, it will allow the user to say, if I click on the link and the link has this token in the URL, because those are base 64 now, so you can have those in the URL. And then when you have that, then you want to consume it because the less is stick over there, the better it is. And then you can
Speaker 1give the user a way to change a password because you know the stuff and then you will get a specific token. You will probably take this token and then you will be able to call your server. And then if you have this password reset token, the good one, then the user will be able to change a password. Okay, so that is one way. So typically what you want, the way we do it in production application is we do not, we did that at the beginning. No, actually,
Speaker 1what you don't want is to have And that means being able to set the password for someone, someone else. That shouldn't be, doesn't have to have this feature. Now, that being said, obviously you see that when we are running our application, we obviously have a password set up, yes? Because for example, if we go to sorry if I
Speaker 1go to examples and then I go to quick dev you see I log in as a user and password demo welcome and that is because so somewhere we will manage, and here is not a hack. We didn't want to do that as a hack and say, well, you know, if it's welcome or demo one or for these guys, we're going to accept it. So that would be very, very bad coding. So what we did is we had
Speaker 1the things where in the seed, so in the tool, we have this tool to be able to generate. So that is a tool to generate the key and to base64. url encoded it could be base64 encoded i just normalize everything on base64 url and so that is what we're setting over there so we have this service password so that is a prefix for the service and then that
Speaker 1is a password key and that is a global token key okay so now that we have that There's a seed somewhere. Let me see if I can find. Seed agents, seed staff, seed users. Username. Okay, so this one is
Speaker 1for test. I think, you know, it's not for test, it's for call. There's a one here, so if I'm going to do demo, welcome, I guess. Okay. Okay, so that is the initdb, sorry. So that is the initdb, so we have the password, welcome, and then we have,
Speaker 1According here, which is update password. So the update password will update a password because we want to be able to update the password, obviously. So the user should be able to say, I want to update my password. So that is the things. Now, the reason why there will be a thing to say, well, the update password, and that will be a good argument. You say, why do you have the user ID? as an argument of the staff,
Speaker 1it should take it from CTX. Well then, so that wouldn't be wrong, actually. So then we could say, okay, update password, only update the password of the guy that has been logged in as a CTX. In this case, the reason why I did it is because I said, well, I want to make sure that the admin, so here's a CTX is a root CTX. So we need that. Because the way that we're designing the Rust web app
Speaker 1things is to say, I don't want to have the Rust web app system calls and everything, bypassing everything. So in a way, you still have your root CTX and that is superpower and then you can call stuff. Eventually, and this is not now, but we're going to have many more videos about this stuff, but we're going to have an access control system, layer, whatever we want to call it, which is going to be at the data level,
Speaker 1at the model level, and not at the web level. On the web, we authenticate, make sure that the user is who you say he is, she is. The authorization, who can do what, is at the data layer. Once you've done that, it's cool because as we say before, so hopefully I answered your question here probably too much and everything. Let me know if I didn't answer your question, Dave.
Speaker 1I'm going to call you Davey there or Dave, yeah. So if I go to sketch here, because remember in the architecture, we have the core. And that is our core business that allows us to access the data with all of the access control. So the core will have all the access control. And because it will have all the access control, then you can put it in any service you want that needs it. So if you have
Speaker 1two web servers, one for the end user, one for IT, you can use the same core. And then everything uses the same core. So that's the concept of the approach. Okay? So in this case today, we already have an update. Things I'm using, I say, well, update is going to be for, is going to allow to give an user. There will be a good argument to say, hey, let's split this method in two. We have an update password,
Speaker 1which just CTX, takes the user off CTX, too bad if it's not you. And then the other one is more something for the IT admin, which might be on the future almost. And then you will include that only either for test, because we need it for test, or for dev, or for these kind of things. So there's also a thing here, I mean, you all know, obviously, features in Rust. And that's kind of unique, and it
Speaker 1kind of allows us to have the thing to say, hey, we have a dev feature where we have an update feature underscore pw underscore dev for example you know dev or dev update or whatever we want to call it and that will be used in dev in in test and it can also be used in an it server perhaps but again for me it wouldn't be used in a production even an it server because the right way
Speaker 1of doing it is to have the it admin say reset password there's a url And it's a one-time change. So what we don't want is, and I'm not finger pointing anything, but when you do a system, a production system, it's all about security. It's about surface attack. And an admin is a weak point. So it's not like we shouldn't trust admin, but we need to scope it. So
Speaker 1they shouldn't be able to, change password and stuff. And so once the password is changed, if the user cannot change it, it's like, well, I'm sorry, you know, I couldn't change my password. Yeah, because the URL was already used. So in this way, the admin cannot be a bad actor. I mean, it can, it's harder. Hopefully that was helpful. So I'm going deep into, I mean, I really enjoy all these kinds of things because that is what I'm, doing when I'm architecting and designing an application. And this
Speaker 1is what I'm always thinking about when I do the blueprint. And then I give the blueprint to my team for the clients. That has been working extremely well for 15 years. And these are all of these little nuances here. The benefit of having this thought process and thinking blueprint rather than frameworks is that rather to have frameworks to do these kind of things or whatever, at some point we are doing a medical application and then people say, well, why you don't use WordPress, believe it, or like Drupal
Speaker 1or something like that. I was like, okay, what are we talking about? It was a video annotation platform. And the reason why they say that, and they had kind of a point, was to say, well, you have to rebuild this whole user system and things with the tokens, the keys, and stuff. And the trick is, once you have the right pattern, and once you implement it once, it's done. And it's not more code than using GWT. I would argue here that sign, token sign, that that
Speaker 1is not that big of a deal for WebToken. Yeah, I mean, it's relatively simple and we don't need a framework and stuff. Now, if you get a WebToken from somewhere and JWT from somewhere and you need to somehow check the roles, which is for me, it's definitely not secure, then I can understand it's like, oh, okay, you know, I want to have a little crate that allows me to unparse this standard. Yeah, that's fine, yeah. But for your token, for our token, we don't need that. The
Speaker 1beautiful things about the token, and this is why I'm most passionate about that, which is kind of weird to be passionate about such a small thing, but is that this scheme, we can use it for web token in the cookie, which is what we're doing right now. But as I was saying today, password reset, same scheme. Same scheme. You might add another key to make sure that you might have another key for a password reset key, a global key, and then you can use a token solve key.
Speaker 1Token solve key, another key stuff such as, you know, you don't have a bug if, you know, whatever, such as you really need to call the function that does the stuff, and then you have another validate function, but it's the same scheme, yeah? So, or you generalize your functions. I mean, you can do that. But the point is that this scheme is super portable. So that is one thing that the JWT did very well. I liked it a lot, which is partitioning with a dot and base64
Speaker 1URL for the parts. And that is very good because then we end up having something which is very possible. You can put it as a cookie, but also as a URL. That's super nice. So that is the things. We're on the one hour mark. Let me know. I can't talk for 10 hours, guys. So you have to let me know here when you guys are, you know,
Speaker 1when you are checking out. But I will see, I guess. So next one here, so we have that. I think we, I'm sorry, I always have this kind of stuff. I think we've beaten this one pretty well. And so now what I would like to do is to create the
Speaker 1first pass at the org let me see the model that i have so the thing i like here is we see the model that we have over there we have the store which is the things that access the database we have the base which is all our utilities that are reused yeah so we have our crud function over there um That allows us to, so that is
Speaker 1utilities function. So CTX and it talks the model controller. So that will be the base stuff. So that's the way we can reuse things across stuff. And then we have the ACS, which is the access control system, layer or whatever, it's not done yet. And then the goal of this layer will be that, let's take one, for example, I'm going to take one that is relatively... Simple. Okay,
Speaker 1so we have our ConvBMC, okay? And our ConvBMC is going to be, so I don't know, I think I already talked about this last time. I don't know in which one, but our ConvBMC is the one that access the conversation object, the Conv entity. And so the goal here, will be that within, I think I put it here, will have a decorator attribute that have these kind of things where you say require privilege and then we have
Speaker 1some notation here, which is not going to be this one, but I need to design it and stuff. But that will be the privileges, not the roles. The role that expanded into a set of privileges. And these privileges that will be stored, cached, under CTX. So CTX will have an inner mutability, and then the access layer, so when we are going to add that over there, that will basically inject a function inside the body, which will be assert, privilege,
Speaker 1any of, or whatever, and that will be the string of these guys. Something like that. And then we have CTX and the model manager. So that would be something, there might be more, there might be something also at the end or whatever, but that is a goal. And so question mark over there and stuff. So that is going to be the goal. We put that there such as we don't have to add that, but at the beginning when I'm going to cut it, and this is
Speaker 1important when we do rough cutting. don't start with macros start by having good code design and then macro is to make it dry don't repeat yourself kind of business so first good code design i have a good guy here that is there in my discord there were some very good questions to say what if you want to check if you have access to this guy so here the trick is this add on conversation so here if
Speaker 1i have a conf and message to say, you know, I want this guy to make sure that he has the and message privilege, where I need to tell the function, you know, the ID of this conv. Yeah, because it will be a table somewhere, which will conv role. So usually in database, you start by just storing roles. Yeah, but in the code, that is a trick. database or whatever you store roles in the code you validate privileges
Speaker 1when you do that it's heaven because then later you have the flexibility to make the privilege of the roles dynamic if you validate roles in your code here then do done yeah then you're in a role and then you try to add privileges dynamic and stuff it's get a nightmare so this is why code should validate privileges which is one of our theme. And a privilege can belong to one of our role. And it's on something.
Speaker 1So that's why there's this little kind of prefix here. That's for conversation. That is for org. That would be probably something like that. And that is for space. Yeah, but I don't know if we even have space. So that is a way that the thing will work. I make that works. I have something here that I haven't designed and say, okay, how do I pass to the assert privileged staff thing? So I will probably pass an
Speaker 1enum that will be, for example, this is where Rust is very cool. I hope you are okay with the format here. I'm explaining a lot of things that go through my head when I'm implementing production stuff. So here the thing is, I don't want assert. to have some sort of type here and having all of that. I want these guys to be relatively generic in a way, because otherwise over typing is going to be tricky. At
Speaker 1the same time here, I'm going to have different objects. So for example, in this case here, we have conversation, we have agent, agent, I might scratch it, I don't know, but we have conversation, We have user where, yeah, we don't have more. And then we have message somewhere. I don't know. Oh, yeah, conversation message. Okay. Okay, conversation message.
Speaker 1So just to tell you one thing I don't like is conv underscore message is an entity on itself. Conv underscore user, it's a relation table. So I don't like they look alike. And so I don't like the asymmetry here, but that's another topic. And I don't know if there's a good solution for that, just to explain to you what goes through my head. So bottom line is, what we're going to do here in the Rust web app,
Speaker 1and I'm going to start, one is we're going to use add organizations. And then the organization are going to be, so the goal is to do a multi-tenant application there's a lot of people that have strong opinions and I don't like the word opinions I like the word perspectives because for me opinions is based on beliefs and perspective is based on expertise okay so I'm going to give the credit of perspectives to many people and they say
Speaker 1well if you don't have multiple database one database per client this is not multi-tenant I don't think that that is I mean actually it's not my perspective then there's another one that says, well, if you have a user that can belong to multiple organizations or multiple tenants, then it's not a multi-tenant architecture. Again, that is not my perspective. There's many different ways of doing multi-tenants. The goal of multi-tenancy is to make sure that the organization or the tenant is your key, meaning that It's your most important segregation.
Speaker 1So everything should be segregated with your tenant. So, for example, in the database, if we go back, so we're not going to implement it, but we're going to talk a lot about it. If we go back to our schema, so that is our database. We have our schema, we have users, we have agent, we have our conversations and everything. When we're going to add our organization, I'm going to
Speaker 1do that. And actually I'm going to, so that would be our tenant. Yeah, you can call it tenant, you can call it org. I'm going to call it org. I'm going to put it on top because in a way it's a big guy. And then we have the name. Okay, and then the name we're going to do something like that. Now you can have many other things, but in all of my items, I always have these guys. And so
Speaker 1that is super important when you do production coding. And I don't want to use production coding at the whole staff and But the point is, what you want is to make sure that you keep the data that are cheap to keep. Hopefully it makes sense. Meaning, When you create an item, it's very cheap to say who created it,
Speaker 1at what time he created it. And when you modify it, it's very cheap to create this stuff. So rather to have a table or have tracing and all these kind of things, which is good too. You don't want to lose the opportunity of capturing what is cheap to capture and a high value to consume. Because that has a lot of value. So for me, this is when you see that in my BMC and stuff, I have this has timestamp and everything, because sometimes some might not have, but usually they all have a timestamp, and that adds
Speaker 1a lot of value. That means that you always need a user to create an org. So that means that either you have an invalid user ID, because we have no new here, or either you have what i was saying about the root user where the root user can be you know user one or user zero or whatever you want to have it and that will allow you
Speaker 1to scope the root here and then making sure that your ctx gets the users so that is one thing that i'm i like to do quite a bit yeah um So this is the way I will create the organization. And then, okay. And I don't know if I'm going to run it today here. I don't, because it could be cumbersome. But then once we have that, so that create things. Right now, okay. Now I'm stuck here. I
Speaker 1want to run it. Now I'm curious. So, I'm going to do command K stuff. I'm going to pin this guy. This guy here, we're not going to do that, but you got the point, yeah, stuff. So the trick here is that the CTX might have org ID somewhere. But in my enum, I'm sorry, here, I'm jumping back and forth here. On this guy here on the asset, just to finish this one, I might have something like entity, Context,
Speaker 1however you use the word context, but here's the thing. I'm weaving, I guess. I'm going to explain how this goes back to the schema, the create schema stuff, the org thing. My point is, when you build an application, you have to decide which object are going to have their own privilege scope. You don't want everything to have
Speaker 1a privilege scope. So the trick is to say, well, we're going to have org, obviously. So when you create an org, you need to have users here that are the privilege of locking users, you know? or inviting users, or creating new conversation or whatever, or projects or whatever. So one thing that we probably add there is a concept of projects. I like the concept of workspace. But
Speaker 1sometimes people workspace is sometimes too abstract. And so I will probably have org project conversation. It's a little bit like chat GPT. Now they have projects and everything. So a project is a container. Could be workspace or whatever. And then conversation is another container. So when you build this kind of application, you say, okay, I want to have a set of roles at the organization. I want to have a set of roles as a project guy. And I want to have a set of role at the conversation layer. That's fair enough. So you decide that.
Speaker 1That will add complexity, because now you're going to have a table that say, what does this user has as a role on this conversation? What does this user has a role in this conversation? Now, the trick about the access control is that you can have, sometimes you don't have to have role explicit. Yeah, you can have implied roles. So for example, that is what we have with The
Speaker 1ad here, I don't want to go to two things, but this one is kind of an explicit role. Let's say that, so full access is bad because full access is too much in a way. It's almost a role. But, yeah, so that's why I don't like the full access. So here we have full access and stuff. It's almost like a role business, so it's tricky. But the point is that Here we're saying PRGs, the project full access. We'll
Speaker 1talk about this later. But then after we can say where for conversation, if the user ID of the guy is the owner ID colon of this, he can do the add message. So this way it allows us to, when I create a conversation, I don't need to be added the role perhaps. I don't need to be added the role owner because in my code, I have this implied privilege. So that allows me to not have the
Speaker 1role owner and then to kind of map it. And this could be any field I want. And so that is a convention of this add. That is just my convention for the ACS. So that allows us, like when you create, for example, an entity and you want to have something as an owner, that allows you to do that without having an owner role. But you can create an owner role if you want. The point is you
Speaker 1have to decide all of your objects that will have this kind of thing. So for example, for us, we're going to have entity and here we're in a conversation, the container is conversation, yeah, because we do an add. So we're going to have conv, so the entity context is a conv, and then inside, I will need to give, I'm sorry, I'm slow, d, and that is where it
Speaker 1gets a little bit tricky. And we'll be able to give the conv ID. Okay, because this is Conv ID. Now the trick is, how do I get that? Well, right now it's inside this guy, Conv ID. So the trick is, this guy doesn't know, I don't want this one to know about message. So what I can do is a trait that will do a, GetConvID or something
Speaker 1like that. So I will do, sorry, message C. It's ugly here, like it's in Java base, but GetConvID. So this way now, I'm going to have this type implementing GetConvID. And in fact, I can, go even further, I think
Speaker 1I could have a trait, because here I wouldn't need a trait in a way, I could just implement a function on the type. But what I could do is implement a crate that have something like get container context, and that will return the entity context. The name is
Speaker 1not there yet, but hopefully you understand the concept. And that will return conf. And then with the ID here that this guy has. So that will be a trait. And the trait return only one type, which is entity context. So the nice things about that is that now is I just need to implement these guys to wherever I want, and then the message is going to say, well, I know who is my container, is this guy. And then
Speaker 1it will do the same. Again, the name is not right and stuff. But once I have that, you can see that now the only thing I can do is, the Rust compiler will know that this one implement, the container context trait. And then even if I wanted to have here, this kind of a E for whatever reason, then I could bound it also to container context and then my assert will work. And so I can do
Speaker 1that or inside my assert, sorry, I'm thinking as I'm talking, I could also have, I could also, just have that, because my assert privileges any of, that will be a trait, which will have the container context or the entity context or whatever we want to call it, which will have
Speaker 1the entity context trait or whatever. And then this one we call the function and then that's it. So then that, because the important things here, we want to be able to be that, we want to be able to generate it from a string like that. So we cannot add too much code there because we could add it, us, but then when we want to make it a macro, we'll be stuck. That is why it's important to think about all these kind of things, such as then after this one is done. Done is a new smart. So what we want is the assert privileges any of, He's
Speaker 1smart inside to do its job, but he's dumb outside. Just take two guys, and then that's it. Anyway, that was long, but actually that was pretty good. I just designed it on the fly with a lot of thought I had before, but I think it's pretty good. Any questions here? We're like marking one hour and 30 seconds. I hope you guys are okay. We can go 30
Speaker 1minutes more, I guess, and then we'll see. If that doesn't work, it doesn't really matter. I will do the prep, and then in our next, we can see what I've done on this guy. So the org here, I have all of these guys. I'm not going to do it now because I want to see if everything compares and I didn't break everything. So I like to make the things very incremental. when I move forward. So right now, I'm just going to change the SQL. Often when I
Speaker 1change the SQL, it kind of breaks. Often it's because I have a comma at the end, and then I have some surprise. So I'm going to try to run it to make sure that everything works. But the point here is that once we have the org, and I don't do that for other entities. So like for project and conversation, we're not going to have I mean, we'll have conv underscore ID and project underscore ID to whatever it needs to be, but it's not going to be
Speaker 1a blanket one. But for organization, because it's a tenant, we cannot put organization there because we're going to say, in our case, we want a user to be able to belong to multiple organizations. Okay, that's fair. The agent here, I don't know what I'm going to do with this beast, but this guy, I'm going to make it. So the
Speaker 1PK is still ID, but I'm going to have an org ID. So to every object, and the money to money is the exception, might be the exception. We'll have a big int, not new. So that would be the design. The beauty about this design here is that when you're creating a production application, you want to make sure, and
Speaker 1there's multiple way of doing it, that when you receive an API, you are receiving it only for one org. And you want this way of saying this one org, you want to have it in a, almost in the API signature. It's not like, oh, give me a conversation ID and then I will look at which org it is. Org should be treated like almost like a first-class segregation point. Sometimes I put even the org ID as part of the API path, which is completely fine. It's very well segregated.
Speaker 1Then there's a very few APIs for IT admin and everything that are multi-orgs. Or even for the user, sometimes if you want to see the notification across orgs, But those ones are very scoped to be very, very small and not very informative. So I make sure that those APIs that are cross-org, they do not leak any PII, personal information, personal information. Or they don't leak PHI, which is a healthcare staff or whatever. So, What you want
Speaker 1is to have this API that always go to a log in a way. You can do it in the path or you can do it as a header. That's fine. This means that when you log in in a way, yeah, you can do it in both ways. I like the pathway, it's very simple. And that means that then in the ACS system, you can, yeah, yeah, Roberto, see you. It was a lot of information. So in the response of
Speaker 1the request, now in our ACS layer, what we can do is to say, hey, this query was for this org. So now whatever I'm sending back entities, I kind of have a generic checker to make sure that everything has the right org ID. And so that is like airport security, airport security is a bad example, but in a security system, you want to have security layers that doesn't have the
Speaker 1same algorithm in a way. And this algorithm is not like about roles and privilege or whatever. It doesn't look privileges and stuff. So it's not enough by itself, but it's a nice additional layer to say, you query what about org123, and in one of the items is all going to fall a break something wrong somewhere someone did a wrong sql somewhere something is wrong so we will
Speaker 1add that that would take time but this is adds a lot to the security of a system yeah so hopefully that will be stuff okay so that would be the way and i think we're going to call it a video here, but one thing I can do here, we have the org, so I'm going to keep this one, and then the only thing I want to do, and it's something I do, so first, I'm going to have my terminal, and I'm going to run that in my Docker, okay?
Speaker 1So that, run the Docker, you're not going to see much, it's very small, but that's fine. So I have that in the background here, and that's perfectly fine. So usually I don't have that in my stuff. I have that in a full background. And then once I have that, I do the thing here, the dev. So I'm going to have two guys. We should start the server. And if I start the server and if it doesn't complain,
Speaker 1I think everything is good. I start it. and everything is not good. It's never good when I change SQL, I don't know why. Well, that's not the SQL fault. Sometime I had a cargo watch. You can also do a cargo watch here. I could have done a cargo
Speaker 1watch dash what? SQL. Yep, I have always a problem here. I need to have Nightwalks. Yeah, I forgot that. That was my mistake. So Nightwalks, so that's good. And usually
Speaker 1what I do as a second one over there is I have my Quick Dev. And so today, and that might change over time, but today I'm using my Quick Dev as an integration test in a way, or not test, yeah, more kind of a sanity check. And so I'm doing that. And if that works, you mean that everything works. Now, everything is going to work because, so this is good, we log in, we have all the data and everything. And everything is going to work because we didn't take too much risk there. And the reason why I run it,
Speaker 1because exactly what I have, it's somehow, I don't know why I added braces over there. I forgot the stuff. So the syntax of SQL somehow missed out sometime. So this is why I do that. And then once I do that, I'm going to start writing the entity, and then the trick that we're going to have to do now is before we're going to have to create an org. So we're going to have doing an insert here, the org,
Speaker 1the demo, and then we're going to have to add the user to the org. So we'll have an org user table. We might have user underscore org, This way we solve our conf underscore message problem. Because if you start with user underscore, this means that it's a link to user. So at least for this case, it might be good. So anyway, so I think that that is going to conclude today. We didn't fully add org, but
Speaker 1we talked about a lot of production concepts. So hopefully you guys enjoyed it. And yeah, feel free to jump into... The Discord, which I think, I don't know if it's there. Feel free to give me feedback all the time. So I'm going to do some pollings for you guys. Hopefully, we can grow this membership over time, such as the more the merrier, because sometimes you have people asking some
Speaker 1cool questions. But having even two people here, very advanced users, is good. And then feel free to jump into my free, my ad hoc, my flash live stream in a way that goes away after. But this is always things. But this one is good. So we're going to do the next one in the next week or couple of weeks. And I will ask the time. But I think weekdays, noon like that works good. I will try to avoid the Friday because Friday is a little bit, you know, tricky.
Speaker 1And then one of these days, I might do also one on the weekend, perhaps if it works. Okay, so thank you a lot for joining. And until next one, happy coding.
Building production-ready web applications requires efficient database interaction, flexible query construction, and well-structured data access layers. We examine how these technologies work together to simplify...
In this episode, we continue our exploration of nine essential Rust programming best practices, focusing on utilities, practical examples, and software testing. Building reliable Rust applications requires more than...
In this comprehensive tutorial, we explore how to build database-driven applications using Rust and SQLite, covering essential database concepts and practical implementation techniques. We take a hands-on approach to...
In this episode, we explore data access in Rust web application development, focusing on how backend applications interact with databases to store, retrieve, and manage information. Data access is a critical component...