Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(157)

Side by Side Diff: go/src/infra/tools/cipd/client.go

Issue 1194803002: Add a package listing API to cipd. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /* 5 /*
6 Package cipd implements client side of Chrome Infra Package Deployer. 6 Package cipd implements client side of Chrome Infra Package Deployer.
7 7
8 TODO: write more. 8 TODO: write more.
9 9
10 Binary package file format (in free form representation): 10 Binary package file format (in free form representation):
(...skipping 23 matching lines...) Expand all
34 */ 34 */
35 package cipd 35 package cipd
36 36
37 import ( 37 import (
38 "bufio" 38 "bufio"
39 "errors" 39 "errors"
40 "fmt" 40 "fmt"
41 "io" 41 "io"
42 "net/http" 42 "net/http"
43 "os" 43 "os"
44 "sort"
44 "strings" 45 "strings"
45 "time" 46 "time"
46 47
47 "github.com/luci/luci-go/common/logging" 48 "github.com/luci/luci-go/common/logging"
48 49
49 "infra/tools/cipd/common" 50 "infra/tools/cipd/common"
50 "infra/tools/cipd/local" 51 "infra/tools/cipd/local"
51 ) 52 )
52 53
53 // PackageACLChangeAction defines a flavor of PackageACLChange. 54 // PackageACLChangeAction defines a flavor of PackageACLChange.
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 // processed" responses. 161 // processed" responses.
161 AttachTagsWhenReady(pin common.Pin, tags []string) error 162 AttachTagsWhenReady(pin common.Pin, tags []string) error
162 163
163 // FetchInstance downloads package instance file from the repository. 164 // FetchInstance downloads package instance file from the repository.
164 FetchInstance(pin common.Pin, output io.WriteSeeker) error 165 FetchInstance(pin common.Pin, output io.WriteSeeker) error
165 166
166 // FetchAndDeployInstance fetches the package instance and deploys it in to 167 // FetchAndDeployInstance fetches the package instance and deploys it in to
167 // the site root. It doesn't check whether the instance is already deplo yed. 168 // the site root. It doesn't check whether the instance is already deplo yed.
168 FetchAndDeployInstance(pin common.Pin) error 169 FetchAndDeployInstance(pin common.Pin) error
169 170
171 // ListPackages returns a list of strings of package names.
172 ListPackages(path string, recursive bool) ([]string, error)
173
170 // ProcessEnsureFile parses text file that describes what should be inst alled 174 // ProcessEnsureFile parses text file that describes what should be inst alled
171 // by EnsurePackages function. It is a text file where each line has a f orm: 175 // by EnsurePackages function. It is a text file where each line has a f orm:
172 // <package name> <desired version>. Whitespaces are ignored. Lines that start 176 // <package name> <desired version>. Whitespaces are ignored. Lines that start
173 // with '#' are ignored. Version can be specified as instance ID, tag or ref. 177 // with '#' are ignored. Version can be specified as instance ID, tag or ref.
174 // Will resolve tags and refs to concrete instance IDs by calling the ba ckend. 178 // Will resolve tags and refs to concrete instance IDs by calling the ba ckend.
175 ProcessEnsureFile(r io.Reader) ([]common.Pin, error) 179 ProcessEnsureFile(r io.Reader) ([]common.Pin, error)
176 180
177 // EnsurePackages is high-level interface for installation, removal and update 181 // EnsurePackages is high-level interface for installation, removal and update
178 // of packages inside the installation site root. Given a description of 182 // of packages inside the installation site root. Given a description of
179 // what packages (and versions) should be installed it will do all neces sary 183 // what packages (and versions) should be installed it will do all neces sary
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 } 275 }
272 276
273 func (client *clientImpl) FetchACL(packagePath string) ([]PackageACL, error) { 277 func (client *clientImpl) FetchACL(packagePath string) ([]PackageACL, error) {
274 return client.remote.fetchACL(packagePath) 278 return client.remote.fetchACL(packagePath)
275 } 279 }
276 280
277 func (client *clientImpl) ModifyACL(packagePath string, changes []PackageACLChan ge) error { 281 func (client *clientImpl) ModifyACL(packagePath string, changes []PackageACLChan ge) error {
278 return client.remote.modifyACL(packagePath, changes) 282 return client.remote.modifyACL(packagePath, changes)
279 } 283 }
280 284
285 func (client *clientImpl) ListPackages(path string, recursive bool) ([]string, e rror) {
286 pkgs, dirs, err := client.remote.listPackages(path, recursive)
287 if err != nil {
288 return nil, err
289 }
290
291 // Add trailing slash to directories.
292 for k, d := range dirs {
Vadim Sh. 2015/06/23 00:08:35 IIUC, that's the only place where dir vs pkg matte
estaab 2015/06/23 02:26:13 Sounds fine, we show both now.
293 dirs[k] = d + "/"
294 }
295 // Merge and sort packages and directories.
296 allPkgs := append(pkgs, dirs...)
297 sort.Sort(sort.StringSlice(allPkgs))
Vadim Sh. 2015/06/23 00:08:35 sort.Strings(allPkgs)
estaab 2015/06/23 02:26:14 Done.
298 return allPkgs, nil
299 }
300
281 func (client *clientImpl) UploadToCAS(sha1 string, data io.ReadSeeker, session * UploadSession) error { 301 func (client *clientImpl) UploadToCAS(sha1 string, data io.ReadSeeker, session * UploadSession) error {
282 // Open new upload session if an existing is not provided. 302 // Open new upload session if an existing is not provided.
283 var err error 303 var err error
284 if session == nil { 304 if session == nil {
285 client.Logger.Infof("cipd: uploading %s: initiating", sha1) 305 client.Logger.Infof("cipd: uploading %s: initiating", sha1)
286 session, err = client.remote.initiateUpload(sha1) 306 session, err = client.remote.initiateUpload(sha1)
287 if err != nil { 307 if err != nil {
288 client.Logger.Warningf("cipd: can't upload %s - %s", sha 1, err) 308 client.Logger.Warningf("cipd: can't upload %s - %s", sha 1, err)
289 return err 309 return err
290 } 310 }
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 modifyACL(packagePath string, changes []PackageACLChange) error 609 modifyACL(packagePath string, changes []PackageACLChange) error
590 610
591 resolveVersion(packageName, version string) (common.Pin, error) 611 resolveVersion(packageName, version string) (common.Pin, error)
592 612
593 initiateUpload(sha1 string) (*UploadSession, error) 613 initiateUpload(sha1 string) (*UploadSession, error)
594 finalizeUpload(sessionID string) (bool, error) 614 finalizeUpload(sessionID string) (bool, error)
595 registerInstance(pin common.Pin) (*registerInstanceResponse, error) 615 registerInstance(pin common.Pin) (*registerInstanceResponse, error)
596 616
597 attachTags(pin common.Pin, tags []string) error 617 attachTags(pin common.Pin, tags []string) error
598 fetchInstance(pin common.Pin) (*fetchInstanceResponse, error) 618 fetchInstance(pin common.Pin) (*fetchInstanceResponse, error)
619
620 listPackages(path string, recursive bool) ([]string, []string, error)
599 } 621 }
600 622
601 type storage interface { 623 type storage interface {
602 upload(url string, data io.ReadSeeker) error 624 upload(url string, data io.ReadSeeker) error
603 download(url string, output io.WriteSeeker) error 625 download(url string, output io.WriteSeeker) error
604 } 626 }
605 627
606 type registerInstanceResponse struct { 628 type registerInstanceResponse struct {
607 uploadSession *UploadSession 629 uploadSession *UploadSession
608 alreadyRegistered bool 630 alreadyRegistered bool
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 } 667 }
646 668
647 // buildInstanceIDMap builds mapping {package name -> instance ID}. 669 // buildInstanceIDMap builds mapping {package name -> instance ID}.
648 func buildInstanceIDMap(pins []common.Pin) map[string]string { 670 func buildInstanceIDMap(pins []common.Pin) map[string]string {
649 out := map[string]string{} 671 out := map[string]string{}
650 for _, p := range pins { 672 for _, p := range pins {
651 out[p.PackageName] = p.InstanceID 673 out[p.PackageName] = p.InstanceID
652 } 674 }
653 return out 675 return out
654 } 676 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698