WIP logs in dryad sandbox/aalexanderr/logs
authorAlexander Mazuruk <a.mazuruk@samsung.com>
Thu, 6 Sep 2018 16:31:24 +0000 (18:31 +0200)
committerAlexander Mazuruk <a.mazuruk@samsung.com>
Fri, 14 Sep 2018 09:36:34 +0000 (11:36 +0200)
Change-Id: Ie19da61a2c114178c774ce49055e5dcea82a3fd4
Signed-off-by: Alexander Mazuruk <a.mazuruk@samsung.com>
dryad/key.go
dryad/rusalka.go

index 9a41b74..bae8f2d 100644 (file)
@@ -23,26 +23,46 @@ import (
        "strconv"
 
        "golang.org/x/crypto/ssh"
+
+       "git.tizen.org/tools/slav/logger"
 )
 
 // installPublicKey marshals and stores key in a proper location to be read by ssh daemon.
 func installPublicKey(key *ssh.PublicKey, homedir, uid, gid string) error {
+       logger.WithProperty("method", "installPublicKey").
+               WithProperty("PublicKey", key).
+               WithProperty("homedir", homedir).
+               WithProperty("uid", uid).
+               WithProperty("gid", gid).
+               Debug("Start.")
        if key == nil {
+               logger.WithProperty("method", "installPublicKey").
+                       WithProperty("PublicKey", key).
+                       Error("Empty public ssh key provided.")
                return errors.New("empty public key")
        }
        sshDir := path.Join(homedir, ".ssh")
        err := os.MkdirAll(sshDir, 0755)
        if err != nil {
+               logger.WithProperty("method", "installPublicKey").
+                       WithProperty("PublicKey", key).
+                       Error("Failed to create ssh directory.")
                return err
        }
        f, err := os.OpenFile(path.Join(sshDir, "authorized_keys"),
                os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
        if err != nil {
+               logger.WithProperty("method", "installPublicKey").
+                       WithProperty("PublicKey", key).
+                       Errorf("Failed to open %v/authorized_keys file.", sshDir)
                return err
        }
        defer f.Close()
        err = updateOwnership(f, sshDir, uid, gid)
        if err != nil {
+               logger.WithProperty("method", "installPublicKey").
+                       WithProperty("PublicKey", key).
+                       Error("Failed to update ownership of authorized_keys file.")
                return err
        }
        _, err = f.Write(ssh.MarshalAuthorizedKey(*key))
index 7ce3731..ad17ccd 100644 (file)
@@ -25,6 +25,7 @@ import (
 
        "git.tizen.org/tools/boruta"
        "git.tizen.org/tools/muxpi/sw/nanopi/stm"
+       "git.tizen.org/tools/slav/logger"
        "golang.org/x/crypto/ssh"
 )
 
@@ -50,8 +51,14 @@ func NewRusalka(stmConn stm.Interface, username string, groups []string) boruta.
 // Otherwise it may make it unusable for other STM users. It is closed
 // when blinkMaintenanceLED exits.
 func (r *Rusalka) PutInMaintenance(msg string) error {
+       logger.WithProperty("type", "Rusalka").WithProperty("method", "PutInMaintenance").
+               WithProperty("Message", msg).
+               Debug("Start.")
        err := r.stm.printMessage(msg)
        if err != nil {
+               logger.WithProperty("type", "Rusalka").WithProperty("method", "PutInMaintenance").
+                       WithProperty("Message", msg).WithError(err).
+                       Error("Failed to print on stm display.")
                return err
        }
        var ctx context.Context
@@ -62,6 +69,9 @@ func (r *Rusalka) PutInMaintenance(msg string) error {
 
 // Prepare is part of implementation of Dryad interface. Call to Prepare stops LED blinking.
 func (r *Rusalka) Prepare(key *ssh.PublicKey) (err error) {
+       logger.WithProperty("type", "Rusalka").WithProperty("method", "Prepare").
+               WithProperty("SSH public key", key).
+               Debug("Start.")
        // Stop maintenance.
        if r.cancelMaintenance != nil {
                r.cancelMaintenance()
@@ -70,15 +80,24 @@ func (r *Rusalka) Prepare(key *ssh.PublicKey) (err error) {
        // Remove/Add user.
        err = r.dryadUser.delete()
        if err != nil {
+               logger.WithProperty("type", "Rusalka").WithProperty("method", "Prepare").
+                       WithProperty("SSH public key", key).WithError(err).
+                       Error("User removal failed")
                return fmt.Errorf("user removal failed: %s", err)
        }
        err = r.dryadUser.add()
        if err != nil {
+               logger.WithProperty("type", "Rusalka").WithProperty("method", "Prepare").
+                       WithProperty("SSH public key", key).WithError(err).
+                       Error("User creation failed")
                return fmt.Errorf("user creation failed: %s", err)
        }
        // Verify user's existance.
        err = r.dryadUser.update()
        if err != nil {
+               logger.WithProperty("type", "Rusalka").WithProperty("method", "Prepare").
+                       WithProperty("SSH public key", key).WithError(err).
+                       Error("user information update failed")
                return fmt.Errorf("user information update failed: %s", err)
        }
        return r.dryadUser.installKey(key)