github.com/Cloud-Foundations/Dominator@v0.3.4/imageserver/rpcd/expiration.go (about)

     1  package rpcd
     2  
     3  import (
     4  	"fmt"
     5  	"time"
     6  
     7  	"github.com/Cloud-Foundations/Dominator/lib/errors"
     8  	"github.com/Cloud-Foundations/Dominator/lib/format"
     9  	"github.com/Cloud-Foundations/Dominator/lib/srpc"
    10  	"github.com/Cloud-Foundations/Dominator/proto/imageserver"
    11  )
    12  
    13  func (t *srpcType) ChangeImageExpiration(conn *srpc.Conn,
    14  	request imageserver.ChangeImageExpirationRequest,
    15  	reply *imageserver.ChangeImageExpirationResponse) error {
    16  	if err := t.checkMutability(); err != nil {
    17  		reply.Error = errors.ErrorToString(err)
    18  		return nil
    19  	}
    20  	var msg string
    21  	if request.ExpiresAt.IsZero() {
    22  		msg = "to not expire"
    23  	} else {
    24  		msg = fmt.Sprintf("expire in %s",
    25  			format.Duration(time.Until(request.ExpiresAt)))
    26  	}
    27  	if username := conn.Username(); username == "" {
    28  		t.logger.Printf("ChangeImageExpiration(%s) %s\n",
    29  			request.ImageName, msg)
    30  	} else {
    31  		t.logger.Printf("ChangeImageExpiration(%s) %s by %s\n",
    32  			request.ImageName, msg, username)
    33  	}
    34  	_, err := t.imageDataBase.ChangeImageExpiration(
    35  		request.ImageName, request.ExpiresAt, conn.GetAuthInformation())
    36  	reply.Error = errors.ErrorToString(err)
    37  	return nil
    38  }
    39  
    40  func (t *srpcType) GetImageExpiration(conn *srpc.Conn,
    41  	request imageserver.GetImageExpirationRequest,
    42  	reply *imageserver.GetImageExpirationResponse) error {
    43  	if img := t.imageDataBase.GetImage(request.ImageName); img == nil {
    44  		reply.Error = "image not found"
    45  	} else {
    46  		reply.ExpiresAt = img.ExpiresAt
    47  	}
    48  	return nil
    49  }