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

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
« no previous file with comments | « go/src/infra/tools/cipd/apps/cipd/main.go ('k') | go/src/infra/tools/cipd/client_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 // processed" responses. 169 // processed" responses.
169 AttachTagsWhenReady(pin common.Pin, tags []string) error 170 AttachTagsWhenReady(pin common.Pin, tags []string) error
170 171
171 // FetchInstance downloads package instance file from the repository. 172 // FetchInstance downloads package instance file from the repository.
172 FetchInstance(pin common.Pin, output io.WriteSeeker) error 173 FetchInstance(pin common.Pin, output io.WriteSeeker) error
173 174
174 // FetchAndDeployInstance fetches the package instance and deploys it in to 175 // FetchAndDeployInstance fetches the package instance and deploys it in to
175 // the site root. It doesn't check whether the instance is already deplo yed. 176 // the site root. It doesn't check whether the instance is already deplo yed.
176 FetchAndDeployInstance(pin common.Pin) error 177 FetchAndDeployInstance(pin common.Pin) error
177 178
179 // ListPackages returns a list of strings of package names.
180 ListPackages(path string, recursive bool) ([]string, error)
181
178 // ProcessEnsureFile parses text file that describes what should be inst alled 182 // ProcessEnsureFile parses text file that describes what should be inst alled
179 // by EnsurePackages function. It is a text file where each line has a f orm: 183 // by EnsurePackages function. It is a text file where each line has a f orm:
180 // <package name> <desired version>. Whitespaces are ignored. Lines that start 184 // <package name> <desired version>. Whitespaces are ignored. Lines that start
181 // with '#' are ignored. Version can be specified as instance ID, tag or ref. 185 // with '#' are ignored. Version can be specified as instance ID, tag or ref.
182 // Will resolve tags and refs to concrete instance IDs by calling the ba ckend. 186 // Will resolve tags and refs to concrete instance IDs by calling the ba ckend.
183 ProcessEnsureFile(r io.Reader) ([]common.Pin, error) 187 ProcessEnsureFile(r io.Reader) ([]common.Pin, error)
184 188
185 // EnsurePackages is high-level interface for installation, removal and update 189 // EnsurePackages is high-level interface for installation, removal and update
186 // of packages inside the installation site root. Given a description of 190 // of packages inside the installation site root. Given a description of
187 // what packages (and versions) should be installed it will do all neces sary 191 // 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
279 } 283 }
280 284
281 func (client *clientImpl) FetchACL(packagePath string) ([]PackageACL, error) { 285 func (client *clientImpl) FetchACL(packagePath string) ([]PackageACL, error) {
282 return client.remote.fetchACL(packagePath) 286 return client.remote.fetchACL(packagePath)
283 } 287 }
284 288
285 func (client *clientImpl) ModifyACL(packagePath string, changes []PackageACLChan ge) error { 289 func (client *clientImpl) ModifyACL(packagePath string, changes []PackageACLChan ge) error {
286 return client.remote.modifyACL(packagePath, changes) 290 return client.remote.modifyACL(packagePath, changes)
287 } 291 }
288 292
293 func (client *clientImpl) ListPackages(path string, recursive bool) ([]string, e rror) {
294 pkgs, dirs, err := client.remote.listPackages(path, recursive)
295 if err != nil {
296 return nil, err
297 }
298
299 // Add trailing slash to directories.
300 for k, d := range dirs {
301 dirs[k] = d + "/"
302 }
303 // Merge and sort packages and directories.
304 allPkgs := append(pkgs, dirs...)
305 sort.Strings(allPkgs)
306 return allPkgs, nil
307 }
308
289 func (client *clientImpl) UploadToCAS(sha1 string, data io.ReadSeeker, session * UploadSession) error { 309 func (client *clientImpl) UploadToCAS(sha1 string, data io.ReadSeeker, session * UploadSession) error {
290 // Open new upload session if an existing is not provided. 310 // Open new upload session if an existing is not provided.
291 var err error 311 var err error
292 if session == nil { 312 if session == nil {
293 client.Logger.Infof("cipd: uploading %s: initiating", sha1) 313 client.Logger.Infof("cipd: uploading %s: initiating", sha1)
294 session, err = client.remote.initiateUpload(sha1) 314 session, err = client.remote.initiateUpload(sha1)
295 if err != nil { 315 if err != nil {
296 client.Logger.Warningf("cipd: can't upload %s - %s", sha 1, err) 316 client.Logger.Warningf("cipd: can't upload %s - %s", sha 1, err)
297 return err 317 return err
298 } 318 }
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 644
625 resolveVersion(packageName, version string) (common.Pin, error) 645 resolveVersion(packageName, version string) (common.Pin, error)
626 646
627 initiateUpload(sha1 string) (*UploadSession, error) 647 initiateUpload(sha1 string) (*UploadSession, error)
628 finalizeUpload(sessionID string) (bool, error) 648 finalizeUpload(sessionID string) (bool, error)
629 registerInstance(pin common.Pin) (*registerInstanceResponse, error) 649 registerInstance(pin common.Pin) (*registerInstanceResponse, error)
630 650
631 setRef(ref string, pin common.Pin) error 651 setRef(ref string, pin common.Pin) error
632 attachTags(pin common.Pin, tags []string) error 652 attachTags(pin common.Pin, tags []string) error
633 fetchInstance(pin common.Pin) (*fetchInstanceResponse, error) 653 fetchInstance(pin common.Pin) (*fetchInstanceResponse, error)
654
655 listPackages(path string, recursive bool) ([]string, []string, error)
634 } 656 }
635 657
636 type storage interface { 658 type storage interface {
637 upload(url string, data io.ReadSeeker) error 659 upload(url string, data io.ReadSeeker) error
638 download(url string, output io.WriteSeeker) error 660 download(url string, output io.WriteSeeker) error
639 } 661 }
640 662
641 type registerInstanceResponse struct { 663 type registerInstanceResponse struct {
642 uploadSession *UploadSession 664 uploadSession *UploadSession
643 alreadyRegistered bool 665 alreadyRegistered bool
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 } 702 }
681 703
682 // buildInstanceIDMap builds mapping {package name -> instance ID}. 704 // buildInstanceIDMap builds mapping {package name -> instance ID}.
683 func buildInstanceIDMap(pins []common.Pin) map[string]string { 705 func buildInstanceIDMap(pins []common.Pin) map[string]string {
684 out := map[string]string{} 706 out := map[string]string{}
685 for _, p := range pins { 707 for _, p := range pins {
686 out[p.PackageName] = p.InstanceID 708 out[p.PackageName] = p.InstanceID
687 } 709 }
688 return out 710 return out
689 } 711 }
OLDNEW
« no previous file with comments | « go/src/infra/tools/cipd/apps/cipd/main.go ('k') | go/src/infra/tools/cipd/client_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698