gitee.com/mysnapcore/mysnapd@v0.1.0/store/details.go (about)

     1  // -*- Mode: Go; indent-tabs-mode: t -*-
     2  
     3  /*
     4   * Copyright (C) 2014-2022 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 store
    21  
    22  import (
    23  	"gitee.com/mysnapcore/mysnapd/jsonutil/safejson"
    24  	"gitee.com/mysnapcore/mysnapd/snap"
    25  	"gitee.com/mysnapcore/mysnapd/strutil"
    26  )
    27  
    28  // snapDetails encapsulates the data sent to us from the store as JSON.
    29  type snapDetails struct {
    30  	Architectures    []string           `json:"architecture"`
    31  	Channel          string             `json:"channel,omitempty"`
    32  	DownloadSha3_384 string             `json:"download_sha3_384,omitempty"`
    33  	Summary          safejson.String    `json:"summary,omitempty"`
    34  	Description      safejson.Paragraph `json:"description,omitempty"`
    35  	DownloadSize     int64              `json:"binary_filesize,omitempty"`
    36  	DownloadURL      string             `json:"download_url,omitempty"`
    37  	LastUpdated      string             `json:"last_updated,omitempty"`
    38  	Name             string             `json:"package_name"`
    39  	Prices           map[string]float64 `json:"prices,omitempty"`
    40  	// Note that the publisher is really the "display name" of the
    41  	// publisher
    42  	Publisher      string           `json:"publisher,omitempty"`
    43  	RatingsAverage float64          `json:"ratings_average,omitempty"`
    44  	Revision       int              `json:"revision"` // store revisions are ints starting at 1
    45  	SnapID         string           `json:"snap_id"`
    46  	License        string           `json:"license,omitempty"`
    47  	Base           string           `json:"base,omitempty"`
    48  	Media          []storeSnapMedia `json:"media,omitempty"`
    49  
    50  	// FIXME: the store should send "contact" here, once it does we
    51  	//        can remove support_url
    52  	SupportURL string `json:"support_url"`
    53  	Contact    string `json:"contact"`
    54  
    55  	Title   safejson.String `json:"title"`
    56  	Type    snap.Type       `json:"content,omitempty"`
    57  	Version string          `json:"version"`
    58  
    59  	Developer           string `json:"origin"`
    60  	DeveloperID         string `json:"developer_id"`
    61  	DeveloperName       string `json:"developer_name"`
    62  	DeveloperValidation string `json:"developer_validation"`
    63  
    64  	Private     bool   `json:"private"`
    65  	Confinement string `json:"confinement"`
    66  
    67  	CommonIDs []string `json:"common_ids,omitempty"`
    68  }
    69  
    70  func infoFromRemote(d *snapDetails) *snap.Info {
    71  	info := &snap.Info{}
    72  	info.Architectures = d.Architectures
    73  	info.SnapType = d.Type
    74  	info.Version = d.Version
    75  	info.RealName = d.Name
    76  	info.SnapID = d.SnapID
    77  	info.Revision = snap.R(d.Revision)
    78  
    79  	// https://forum.snapcraft.io/t/title-length-in-snapcraft-yaml-snap-yaml/8625/10
    80  	info.EditedTitle = strutil.ElliptRight(d.Title.Clean(), 40)
    81  
    82  	info.EditedSummary = d.Summary.Clean()
    83  	info.EditedDescription = d.Description.Clean()
    84  	// Note that the store side is using confusing terminology here.
    85  	// What the store calls "developer" is actually the publisher
    86  	// username.
    87  	//
    88  	// It also sends "publisher" and "developer_name" which are
    89  	// the "publisher display name" which we cannot use currently
    90  	// because it is not validated (i.e. the publisher could put
    91  	// anything in there and mislead the users this way).
    92  	info.Publisher = snap.StoreAccount{
    93  		ID:          d.DeveloperID,
    94  		Username:    d.Developer,
    95  		DisplayName: d.DeveloperName,
    96  		Validation:  d.DeveloperValidation,
    97  	}
    98  	info.Channel = d.Channel
    99  	info.Sha3_384 = d.DownloadSha3_384
   100  	info.Size = d.DownloadSize
   101  	info.DownloadURL = d.DownloadURL
   102  	info.Prices = d.Prices
   103  	info.Private = d.Private
   104  	info.Paid = len(info.Prices) > 0
   105  	info.Confinement = snap.ConfinementType(d.Confinement)
   106  	info.LegacyEditedContact = d.Contact
   107  	info.License = d.License
   108  	info.Base = d.Base
   109  	info.CommonIDs = d.CommonIDs
   110  
   111  	addMedia(info, d.Media)
   112  
   113  	// FIXME: once the store sends "contact" for everything, remove
   114  	//        the "SupportURL" part of the if
   115  	if info.LegacyEditedContact == "" {
   116  		info.LegacyEditedContact = d.SupportURL
   117  	}
   118  
   119  	return info
   120  }