nebraska
nebraska copied to clipboard
Create lib for wrapping Nebraska's REST API
Current situation
We have a REST API but we should make it more accessible for go users, so we can more easily automate common workflows.
Impact
It'll make it easier to manipulate Nebraska and improve a lot of what can be automated.
**Implementation options
Here is a rough idea of what it should look like:
Each Nebraska server should have an endpoint for its nebraska related functions:
SERVER_BASE_URL/v1/nebraska
We have 5 main actors (or 4 main actors under each application):
- Application
- Group
- Channel
- Package
- Instance
There's a Nebraska
struct whose functions are related to the applications, and to hold the SERVER_URL:
ListApps() []Application, err
GetApp(id_or_product_id string) Application, err
DeleteApp(id_or_product_id string) err
AddApp(app Application) err
-> See Add(ACTOR) below for some text on the reasoning.
Then, since the rest of the actors are really related to an application, the Application
struct will have:
Groups() []Group
Channels() []Channel
Packages() []Package
Instances() []Instance
DeleteACTOR(id string) err
GetACTOR(id string) ACTOR, err
Update(item ACTOR) err
Add(item ACTOR) ACTOR, err
-> Will take an ACTOR instance and try to add it to the database. I thought about having maybe an ACTORConfig, for a NewACTOR
func but maybe we can go with just creating an instance and adding it like this. It returns a complete actor on success, i.e. with the ID it will get from the DB, etc.
Functions for the Application
struct which will list the actors belonging to this app:
Functions for the Group
struct:
its fields, including Channel
for getting the channel, and
Instances() []Instance
Functions for the Channel
struct:
its fields, including Package
for getting the package
For the Package
and Instance
structs:
only their fields
Rough example for assigning a new channel to all the groups in an app:
import (
nebraska "github.com/kinvolk/nebraska/v1"
)
SERVER_URL := "https://myserver.com/v1/nebraska"
n := nebraska.New(SERVER_URL)
app, err := n.GetApp("io.kinvolk.Headlamp")
...
channel, err := app.Add(nebraska.Channel{Name: "stable"})
...
groups, err := app.GetGroups()
...
for _, group := range groups {
group.Channel = channel
app.Update(group)
}