Every week, we run a meetup for the Investec Programmable Banking community. Developers demo cool projects they’ve been working on and everyone has the chance to ask questions. If you’ve been wondering where programmable banking is at, here’s your sneak peek!
In this demo, Ross Purdon shares how he built a simple CLI interface for his bank account so that he can retrieve his bank balance and transactions safely.
Check out the code repo here.
Transcript of the demo
Awesome. Hi, everyone. My demo is quite simple. So, I’m a DevOps Engineer, and I work in the terminal quite a bit. Having to log in and use the phone and do the two factor auth the whole time can sometimes get a bit tedious so I thought, what’s an easy way for me to view the data that I have? So, what I built was a little Investec CLI tool. If we have a look at it, you’ll just see – I was just trying out new packages that I found. It was very quick to build this out. I did it last night. I didn’t think it would be that quick, so I was actually quite surprised.
You have Investec, you have different commands. We have our accounts, and the balances which we can log into, and our transactions. Then these are just the properties that we have set. There’s an Investec CLI, and inside there, there’s a credentials file, which is just JSON, which pretty much has your client ID, your secret. Then we write the token and token type that we get back from the OAuth process. So, just to show you how it works: If we do Investec CLI, we’ll first log in, and then we will be able to do Investec’s CLI accounts. Then this will actually just display the different accounts that I have on there.
There are still a few things I want to do. I don’t want to have to enter the account ID to see the balances and stuff. There’s more work that really does need to be done, but this is just a quick prototype, I suppose.
The next thing that we could do is Investec’s CLI balance, and there we can see this is the balance in my account currently, what the available balance is and the currencies. What I want to add on further is the option to enter the currency that you’d like to see, so for example, if you want to convert it to US or UK pounds, for example.
Then the other thing that we can do with it is just see the transactions that are linked to a specific account. It’s just a quick way to see what’s happening in the account through the CLI, without having to go into the web client each time.
So yeah, very simple. I don’t mind taking people through the code. It’s also very simple and the tools that were used. So if you do a class, very simple, you have your [index], you have your credentials path that can be overwritten. This can also be overwritten via the CLI, and this will go set up a whole bunch of things.
We then have the login method, which will go OAuth and get the token back from us. We store that into the properties and then just write that back to the file. This is a very quick and dirty method of doing it. And then we’ve got the accounts method, which is just a call to the API endpoint and get that data back.
It will write up those graphs for you, and you can configure it in multiple different ways ,have different headers, give it different data structures. And then it’s pretty much a repeat all the way down for your balance and your transactions as well.
Then just to show the two packages – so this is the Python package called Python Tabulate. It’s quite nifty, very quick to use and easy to pick up. Then I used Google Python Fire for the CLI. It’s super easy actually, just to get it working. So what you do is, in my initiation class, you just call Fire-Fire over your class, and it pretty much writes out the whole CLI tool for your accounts and it does the documentation, the Help menu and all of that. Yeah, that was pretty much what I did.
[Meetup host] [22:57]
Nice, cool. Very, very impressive. But you did it so quickly, I guess, finding the right packages is useful. Is there anything surprising that you learned?
At first, I thought it’d be quite tedious to do it honestly because you already have so much of the tools available to you to view that information, but actually, once I started doing it already today, I was like playing around with this and I spent so much time on CLI, it was actually quite cool, and I was thinking of how can you expand it further.
I want to be able to put in 90 days of my transactions back. How can you get that sort of information or can you tell me how much money I have spent between this and this time? I really want to try to find a graph or a library that can-do graphing on the CLI and possibly graph your spend over a month and have that running and see if I can flatten the curve. No, it was fun. I quite enjoyed it, and it was nice playing with the OpenAPI.
I think I’m going to add a few roadmap items onto the project as well for other things that you could get, which I think would be quite cool. But yeah, I won’t delve too deep into that now. But it was fun and it was good to play around with.
[Meetup host] [24:15]
That’s awesome. Yeah. Looks like it was quite a cool little thing that you managed to put together. Do you see other people picking it up and extending it and in what ways would you see them building on it or extending it or taking it in a different direction?
I’ve got no idea. Anyone’s welcome to grab the repo and extend it and see what they want to do. I was thinking maybe trying to put it in DynamoDB, or maybe even put all of this into Lambda’s and then just have a CLI that will interface to the API gateway with Lambda because it’s just better for storing all the secrets and having that information.
I think that would be the next step if I had to build a bit more and I could actually put this in AWS with Serverless and explore that side better, and possibly play around with the new not RDS, but that new Serverless RDS database, maybe play around with that, or DynamoDB and see which one works better and then actually pull stats and do more analytics.
[Meetup host] [25:24]
Cool. Awesome. That’s cool. Any questions from the audience?
[Audience member] [25:34]
I have two questions, one for Ross and one, possibly for the Investec team if they’re online because it relates to what Ross has done. Ross, do you have maybe an auto-login perhaps as an idea instead of having to physically log in or type in the login command, before typing in accounts, for example, is that something you can maybe look at so that it’s more convenient to use instead of having to post the Investec CLI login and then continue on with everything else?
Yeah, I was actually thinking about doing that – just putting it straight into the initialiser and just saying login every time sort of like a refresh token, I suppose you could do that in a sense with the OAuth. I quite like the approach of having to do the login myself, because if anybody else got onto my computer, and they figure out the CLI tool, it means they have full access. But I suppose they could also just do the login command and get full access at the same time, so no – I haven’t really thought about that much, but I do like the approach. It would be nice if you could have a proper refresh token, I suppose, that you could check against the OpenAPI or build that in yourself.
[Audience member] [26:45]
The other question is, let’s say, for example, you put this on some serverless architecture or something like that, right. And this is probably where it would be interesting because we don’t want to copy what you did – we just want to use what you have, so there must be a way that I can use your code but not having to copy it in a sense without sharing my credentials with you.
[Audience member] [27:08]
That’s maybe something that we need to look at because there’s a lot of cool stuff that’s going on, but I have to copy the code literally and run it on my own. Everyone has to run your code on their own for us to be able to use it, and that’s probably not ideal. I don’t know maybe if the Investec guys can think of a way that we can somehow share the details or give Ross’ program a token or something like that, that he can use to get the information from my API transactions without me giving him my keys. There is something that we need to do, there maybe.
I think that is a valid concern, obviously. I’ll have to try and get my head around that. I am busy with another integration now, so it would mean that this is kind of third-party integration, right. And fair enough, you don’t want to share your secret. However, as part of one of our other integration projects, we are in the process of implementing direct authorisation, in which case you can actually generate an API key through Investec alignment, and you can then use this on a third party application, but I don’t want to get your hopes up there yet.
Ross has had an interest in computers since he was young, and really found his passion in highschool when he was tasked with writing a small program in IT class with the Java Gogga class. Since he’s started his career as a developer, he’s worked across multiple teams, doing everything from platform engineering to data engineering before finding his calling in DevOps. He’s currently working at Names & Faces as the head of their DevOps team. When he’s not Dev-Ops-ing away, he enjoys braais with friends and family, and travelling as much as he can.
Get involved in the Programmable Banking Community
For those of you in the community, check out our GitLab to see more of the awesome projects members of our community are working on. You can also sign up for challenges, where you can help find solutions for real life problems.
For more information, pop me a mail.