github.com/david-imola/snapd@v0.0.0-20210611180407-2de8ddeece6d/snap/naming/wellknown.go (about)

     1  // -*- Mode: Go; indent-tabs-mode: t -*-
     2  
     3  /*
     4   * Copyright (C) 2020 Canonical Ltd
     5   *
     6   * This program is free software: you can redistribute it and/or modify
     7   * it under the terms of the GNU General Public License version 3 as
     8   * published by the Free Software Foundation.
     9   *
    10   * This program is distributed in the hope that it will be useful,
    11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
    12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13   * GNU General Public License for more details.
    14   *
    15   * You should have received a copy of the GNU General Public License
    16   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    17   *
    18   */
    19  
    20  package naming
    21  
    22  import (
    23  	"github.com/snapcore/snapd/snapdenv"
    24  )
    25  
    26  var (
    27  	prodWellKnownSnapIDs = map[string]string{
    28  		"core":   "99T7MUlRhtI3U0QFgl5mXXESAiSwt776",
    29  		"snapd":  "PMrrV4ml8uWuEUDBT8dSGnKUYbevVhc4",
    30  		"core18": "CSO04Jhav2yK0uz97cr0ipQRyqg0qQL6",
    31  		"core20": "DLqre5XGLbDqg9jPtiAhRRjDuPVa5X1q",
    32  	}
    33  
    34  	stagingWellKnownSnapIDs = map[string]string{
    35  		"core":   "xMNMpEm0COPZy7jq9YRwWVLCD9q5peow",
    36  		"snapd":  "Z44rtQD1v4r1LXGPCDZAJO3AOw1EDGqy",
    37  		"core18": "NhSvwckvNdvgdiVGlsO1vYmi3FPdTZ9U",
    38  		// TODO:UC20 no core20 uploaded to staging yet
    39  		"core20": "",
    40  	}
    41  )
    42  
    43  var wellKnownSnapIDs = prodWellKnownSnapIDs
    44  
    45  func init() {
    46  	if snapdenv.UseStagingStore() {
    47  		wellKnownSnapIDs = stagingWellKnownSnapIDs
    48  	}
    49  }
    50  
    51  // WellKnownSnapID returns the snap-id of well-known snaps (snapd, core*)
    52  // given the snap name or the empty string otherwise.
    53  func WellKnownSnapID(snapName string) string {
    54  	return wellKnownSnapIDs[snapName]
    55  }
    56  
    57  func UseStagingIDs(staging bool) (restore func()) {
    58  	old := wellKnownSnapIDs
    59  	if staging {
    60  		wellKnownSnapIDs = stagingWellKnownSnapIDs
    61  	} else {
    62  		wellKnownSnapIDs = prodWellKnownSnapIDs
    63  	}
    64  	return func() {
    65  		wellKnownSnapIDs = old
    66  	}
    67  }