// fakeChannels is a stopgap method of getting pseudo-channels until // the details endpoint provides the real thing for us. The main // difference between this pseudo one and the real thing is that a // channel can be closed, and we'll be oblivious to it. func (s *Store) fakeChannels(snapID string, user *auth.UserState) (map[string]*snap.ChannelSnapInfo, error) { snaps := make([]currentSnapJson, 4) for i, channel := range []string{"stable", "candidate", "beta", "edge"} { snaps[i] = currentSnapJson{ SnapID: snapID, Channel: channel, // revision, confinement, epoch purposely left empty } } jsonData, err := json.Marshal(metadataWrapper{ Snaps: snaps, Fields: channelSnapInfoFields, }) if err != nil { return nil, err } reqOptions := &requestOptions{ Method: "POST", URL: s.bulkURI, Accept: halJsonContentType, ContentType: jsonContentType, Data: jsonData, } var results struct { Payload struct { SnapDetails []*snapDetails `json:"clickindex:package"` } `json:"_embedded"` } resp, err := s.retryRequestDecodeJSON(context.TODO(), s.client, reqOptions, user, &results, nil) if err != nil { return nil, err } if resp.StatusCode != http.StatusOK { return nil, respToError(resp, "query the store for channel information") } channelInfos := make(map[string]*snap.ChannelSnapInfo, 4) for _, item := range results.Payload.SnapDetails { channelInfos[item.Channel] = &snap.ChannelSnapInfo{ Revision: snap.R(item.Revision), Confinement: snap.ConfinementType(item.Confinement), Version: item.Version, Channel: item.Channel, Epoch: item.Epoch, Size: item.DownloadSize, } } return channelInfos, nil }
func infoFromRemote(d snapDetails) *snap.Info { info := &snap.Info{} info.Architectures = d.Architectures info.Type = d.Type info.Version = d.Version info.Epoch = "0" info.RealName = d.Name info.SnapID = d.SnapID info.Revision = snap.R(d.Revision) info.EditedSummary = d.Summary info.EditedDescription = d.Description info.DeveloperID = d.DeveloperID info.Developer = d.Developer // XXX: obsolete, will be retired after full backfilling of DeveloperID info.Channel = d.Channel info.Sha3_384 = d.DownloadSha3_384 info.Size = d.DownloadSize info.IconURL = d.IconURL info.AnonDownloadURL = d.AnonDownloadURL info.DownloadURL = d.DownloadURL info.Prices = d.Prices info.Private = d.Private info.Confinement = snap.ConfinementType(d.Confinement) deltas := make([]snap.DeltaInfo, len(d.Deltas)) for i, d := range d.Deltas { deltas[i] = snap.DeltaInfo{ FromRevision: d.FromRevision, ToRevision: d.ToRevision, Format: d.Format, AnonDownloadURL: d.AnonDownloadURL, DownloadURL: d.DownloadURL, Size: d.Size, Sha3_384: d.Sha3_384, } } info.Deltas = deltas screenshots := make([]snap.ScreenshotInfo, 0, len(d.ScreenshotURLs)) for _, url := range d.ScreenshotURLs { screenshots = append(screenshots, snap.ScreenshotInfo{ URL: url, }) } info.Screenshots = screenshots return info }