Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rebuilt frontend #288

Merged
merged 4 commits into from
Apr 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cmd/apps/skysocks-client/skysocks-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ func main() {
}()

if *serverPK == "" {
log.Fatal("Invalid server PubKey")
log.Warn("Empty server PubKey. Exiting")
return
}

pk := cipher.PubKey{}
Expand Down
41 changes: 22 additions & 19 deletions pkg/hypervisor/hypervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,25 +377,6 @@ func (hv *Hypervisor) putApp() http.HandlerFunc {
}
}

if reqBody.Status != nil {
switch *reqBody.Status {
case statusStop:
if err := ctx.RPC.StopApp(ctx.App.Name); err != nil {
httputil.WriteJSON(w, r, http.StatusInternalServerError, err)
return
}
case statusStart:
if err := ctx.RPC.StartApp(ctx.App.Name); err != nil {
httputil.WriteJSON(w, r, http.StatusInternalServerError, err)
return
}
default:
errMsg := fmt.Errorf("value of 'status' field is %d when expecting 0 or 1", *reqBody.Status)
httputil.WriteJSON(w, r, http.StatusBadRequest, errMsg)
return
}
}

const (
skysocksName = "skysocks"
skysocksClientName = "skysocks-client"
Expand All @@ -409,12 +390,34 @@ func (hv *Hypervisor) putApp() http.HandlerFunc {
}

if reqBody.PK != nil && ctx.App.Name == skysocksClientName {
log.Errorf("SETTING PK: %s", *reqBody.PK)
if err := ctx.RPC.SetSocksClientPK(*reqBody.PK); err != nil {
log.Errorf("ERROR SETTING PK")
httputil.WriteJSON(w, r, http.StatusInternalServerError, err)
return
}
}

if reqBody.Status != nil {
switch *reqBody.Status {
case statusStop:
if err := ctx.RPC.StopApp(ctx.App.Name); err != nil {
httputil.WriteJSON(w, r, http.StatusInternalServerError, err)
return
}
case statusStart:
if err := ctx.RPC.StartApp(ctx.App.Name); err != nil {
log.Errorf("ERROR STARTING APP")
httputil.WriteJSON(w, r, http.StatusInternalServerError, err)
return
}
default:
errMsg := fmt.Errorf("value of 'status' field is %d when expecting 0 or 1", *reqBody.Status)
httputil.WriteJSON(w, r, http.StatusBadRequest, errMsg)
return
}
}

httputil.WriteJSON(w, r, http.StatusOK, ctx.App)
})
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/buildinfo/buildinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type Info struct {

// WriteTo writes build info summary to io.Writer.
func (info *Info) WriteTo(w io.Writer) (int64, error) {
msg := fmt.Sprintf("Version %q built on %q agaist commit %q\n", info.Version, info.Date, info.Commit)
msg := fmt.Sprintf("Version %q built on %q against commit %q\n", info.Version, info.Date, info.Commit)
n, err := w.Write([]byte(msg))
return int64(n), err
}
47 changes: 0 additions & 47 deletions pkg/visor/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,53 +96,6 @@ func (c *Config) flush() error {
return ioutil.WriteFile(*c.Path, bytes, filePerm)
}

func (c *Config) updateAppAutoStart(appName string, autoStart bool) error {
changed := false

for i := range c.Apps {
if c.Apps[i].App == appName {
c.Apps[i].AutoStart = autoStart
changed = true
break
}
}

if !changed {
return nil
}

return c.flush()
}

func (c *Config) updateAppArg(appName, argName, value string) error {
configChanged := true

for i := range c.Apps {
argChanged := false
if c.Apps[i].App == appName {
configChanged = true

for j := range c.Apps[i].Args {
if c.Apps[i].Args[j] == argName && j+1 < len(c.Apps[i].Args) {
c.Apps[i].Args[j+1] = value
argChanged = true
break
}
}

if !argChanged {
c.Apps[i].Args = append(c.Apps[i].Args, argName, value)
}
}
}

if configChanged {
return c.flush()
}

return nil
}

// Keys returns visor public and secret keys extracted from config.
// If they are not found, new keys are generated.
func (c *Config) Keys() *KeyPair {
Expand Down
63 changes: 60 additions & 3 deletions pkg/visor/visor.go
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ func (visor *Visor) setAutoStart(appName string, autoStart bool) error {

visor.logger.Infof("Saving auto start = %v for app %v to config", autoStart, appName)

return visor.conf.updateAppAutoStart(appName, autoStart)
return visor.updateAppAutoStart(appName, autoStart)
}

func (visor *Visor) setSocksPassword(password string) error {
Expand All @@ -710,7 +710,7 @@ func (visor *Visor) setSocksPassword(password string) error {
passcodeArgName = "-passcode"
)

if err := visor.conf.updateAppArg(socksName, passcodeArgName, password); err != nil {
if err := visor.updateAppArg(socksName, passcodeArgName, password); err != nil {
return err
}

Expand All @@ -732,7 +732,7 @@ func (visor *Visor) setSocksClientPK(pk cipher.PubKey) error {
pkArgName = "-srv"
)

if err := visor.conf.updateAppArg(socksClientName, pkArgName, pk.String()); err != nil {
if err := visor.updateAppArg(socksClientName, pkArgName, pk.String()); err != nil {
return err
}

Expand All @@ -746,6 +746,63 @@ func (visor *Visor) setSocksClientPK(pk cipher.PubKey) error {
return nil
}

func (visor *Visor) updateAppAutoStart(appName string, autoStart bool) error {
changed := false

for i := range visor.conf.Apps {
if visor.conf.Apps[i].App == appName {
visor.conf.Apps[i].AutoStart = autoStart
if v, ok := visor.appsConf[appName]; ok {
v.AutoStart = autoStart
visor.appsConf[appName] = v
}

changed = true
break
}
}

if !changed {
return nil
}

return visor.conf.flush()
}

func (visor *Visor) updateAppArg(appName, argName, value string) error {
configChanged := true

for i := range visor.conf.Apps {
argChanged := false
if visor.conf.Apps[i].App == appName {
configChanged = true

for j := range visor.conf.Apps[i].Args {
if visor.conf.Apps[i].Args[j] == argName && j+1 < len(visor.conf.Apps[i].Args) {
visor.conf.Apps[i].Args[j+1] = value
argChanged = true
break
}
}

if !argChanged {
visor.conf.Apps[i].Args = append(visor.conf.Apps[i].Args, argName, value)
}

if v, ok := visor.appsConf[appName]; ok {
v.Args = visor.conf.Apps[i].Args
visor.appsConf[appName] = v
}
}
}

if configChanged {
return visor.conf.flush()
}

return nil
}

// UnlinkSocketFiles removes unix socketFiles from file system
func UnlinkSocketFiles(socketFiles ...string) error {
for _, f := range socketFiles {
Expand Down
1 change: 1 addition & 0 deletions static/skywire-manager-src/dist/5.534b04fca902cb9c391b.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading