mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-11 19:04:35 +00:00
App API (#291)
* app deployment * add source to deployment * support without https prefix * add image * minor comment * fix deploy * further fixes * fix the error output * add account name * set limits * fix error handling * fix app handler * fix unmarshalling * remove http2 * set status * fix bug * . * add ability to specify branch * . * . * add better error handling * add app limit * add function limit * update app readme * log status error * update app to use the store * remove double e limit * switch to created/updated * update app handler * 5 bucks * 10 bucks * unique deployments * fix the sid * unique name handling * allow running where reservation expired * check for reservations * update readme * fix update check * update proto comment * add resolve endpoint * ship with domain * fix url * create unprivileged service account * add service account to update * . * . * update comment * . * update public api json
This commit is contained in:
@@ -20,7 +20,9 @@ type App struct{}
|
||||
var (
|
||||
mtx sync.Mutex
|
||||
|
||||
ReservationKey = "reservedApp/"
|
||||
OwnerKey = "app/owner/"
|
||||
ServiceKey = "app/service/"
|
||||
ReservationKey = "app/reservation/"
|
||||
NameFormat = regexp.MustCompilePOSIX("[a-z0-9]+")
|
||||
)
|
||||
|
||||
@@ -83,14 +85,29 @@ func (a *App) Reserve(ctx context.Context, req *pb.ReserveRequest, rsp *pb.Reser
|
||||
return errors.BadRequest("app.reserve", "name already reserved")
|
||||
}
|
||||
|
||||
// check the owner matches
|
||||
if rsrv.Owner != id {
|
||||
// check the owner matches or if the reservation expired
|
||||
if rsrv.Owner != id && rsrv.Expires.After(time.Now()) {
|
||||
return errors.BadRequest("app.reserve", "name already reserved")
|
||||
}
|
||||
|
||||
// update the reservation
|
||||
// update the owner
|
||||
rsrv.Owner = id
|
||||
|
||||
// update the reservation expiry
|
||||
rsrv.Expires = time.Now().AddDate(1, 0, 0)
|
||||
} else {
|
||||
// check if its already running
|
||||
key := ServiceKey + req.Name
|
||||
recs, err := store.Read(key, store.ReadLimit(1))
|
||||
if err != nil && err != store.ErrNotFound {
|
||||
return errors.InternalServerError("app.reserve", "failed to reserve name")
|
||||
}
|
||||
|
||||
// existing service is running by that name
|
||||
if len(recs) > 0 {
|
||||
return errors.BadRequest("app.reserve", "service already exists")
|
||||
}
|
||||
|
||||
// not reserved
|
||||
rsrv = &Reservation{
|
||||
Name: req.Name,
|
||||
|
||||
Reference in New Issue
Block a user