Skip to content

Commit

Permalink
Add confirmation stream to deploy api #2
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasMahe committed Dec 6, 2018
1 parent 541b0fc commit 993215e
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions api/deploy.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package api

import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"sync"

"github.com/mesg-foundation/core/database"
"github.com/mesg-foundation/core/service"
"github.com/mesg-foundation/core/service/importer"
"github.com/mesg-foundation/core/x/xdocker/xarchive"
Expand Down Expand Up @@ -153,6 +156,22 @@ func (d *serviceDeployer) deploy(r io.Reader) (*service.Service, *importer.Valid
return nil, validationErr, nil
}

// check if a previous service exist with the same alias
// if a service exist with the same alias, ask user to confirm, then continue.
previousService, err := d.api.db.Get(s.Alias)
if err != nil && !database.IsErrNotFound(err) {
return nil, nil, err
}
if previousService != nil {
fmt.Println("ask user for confirmation")
d.sendStatus(fmt.Sprintf("A service already exist with alias %q and will be replace by new service. Do you confirm?", s.Alias), Confirmation)
conf := <-d.confirmations
fmt.Println("receive user confirmation", conf)
if !conf {
return nil, nil, errors.New("deployment interupted by user")
}
}

return s, nil, d.api.db.Save(s)
}

Expand Down

0 comments on commit 993215e

Please sign in to comment.