github.com/hugh712/snapd@v0.0.0-20200910133618-1a99902bd583/overlord/configstate/configcore/snapshots.go (about)

     1  // -*- Mode: Go; indent-tabs-mode: t -*-
     2  // +build !nomanagers
     3  
     4  /*
     5   * Copyright (C) 2019 Canonical Ltd
     6   *
     7   * This program is free software: you can redistribute it and/or modify
     8   * it under the terms of the GNU General Public License version 3 as
     9   * published by the Free Software Foundation.
    10   *
    11   * This program is distributed in the hope that it will be useful,
    12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
    13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14   * GNU General Public License for more details.
    15   *
    16   * You should have received a copy of the GNU General Public License
    17   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    18   *
    19   */
    20  
    21  package configcore
    22  
    23  import (
    24  	"fmt"
    25  	"time"
    26  
    27  	"github.com/snapcore/snapd/overlord/configstate/config"
    28  )
    29  
    30  func init() {
    31  	// add supported configuration of this module
    32  	supportedConfigurations["core.snapshots.automatic.retention"] = true
    33  }
    34  
    35  func validateAutomaticSnapshotsExpiration(tr config.Conf) error {
    36  	expirationStr, err := coreCfg(tr, "snapshots.automatic.retention")
    37  	if err != nil {
    38  		return err
    39  	}
    40  	if expirationStr != "" && expirationStr != "no" {
    41  		dur, err := time.ParseDuration(expirationStr)
    42  		if err != nil {
    43  			return fmt.Errorf("snapshots.automatic.retention cannot be parsed: %v", err)
    44  		}
    45  		if dur < time.Hour*24 {
    46  			return fmt.Errorf("snapshots.automatic.retention must be a value greater than 24 hours, or \"no\" to disable")
    47  		}
    48  	}
    49  	return nil
    50  }