github.com/cloud-foundations/dominator@v0.0.0-20221004181915-6e4fee580046/imageserver/client/expiration.go (about)

     1  package client
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/Cloud-Foundations/Dominator/lib/errors"
     7  	"github.com/Cloud-Foundations/Dominator/lib/srpc"
     8  	"github.com/Cloud-Foundations/Dominator/proto/imageserver"
     9  )
    10  
    11  func changeImageExpiration(client *srpc.Client, name string,
    12  	expiresAt time.Time) error {
    13  	request := imageserver.ChangeImageExpirationRequest{
    14  		ImageName: name,
    15  		ExpiresAt: expiresAt,
    16  	}
    17  	var reply imageserver.ChangeImageExpirationResponse
    18  	err := client.RequestReply("ImageServer.ChangeImageExpiration", request,
    19  		&reply)
    20  	if err != nil {
    21  		return err
    22  	}
    23  	return errors.New(reply.Error)
    24  }
    25  
    26  func getImageExpiration(client *srpc.Client, name string) (time.Time, error) {
    27  	request := imageserver.GetImageExpirationRequest{ImageName: name}
    28  	var reply imageserver.GetImageExpirationResponse
    29  	err := client.RequestReply("ImageServer.GetImageExpiration", request,
    30  		&reply)
    31  	if err != nil {
    32  		return time.Time{}, err
    33  	}
    34  	if err := errors.New(reply.Error); err != nil {
    35  		return time.Time{}, err
    36  	}
    37  	return reply.ExpiresAt, nil
    38  }