Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package config | |
| 6 | |
| 7 import ( | |
| 8 "bytes" | |
| 9 "crypto/sha256" | |
| 10 "encoding/hex" | |
| 11 "errors" | |
| 12 "net/url" | |
| 13 "os" | |
| 14 | |
| 15 "github.com/luci/luci-go/common/config" | |
| 16 ) | |
| 17 | |
| 18 var errNotImplemented = errors.New("not implemented") | |
| 19 | |
| 20 // fileConfig is an implementation of config.Interface that represents itself | |
| 21 // as a configuration instance with one specific ConfigSet containing one | |
| 22 // specific file. | |
| 23 // | |
| 24 // This is a partial implementation of the config.Interface interface sufficient | |
| 25 // for a ConfigManager to use. | |
| 26 type fileConfig struct { | |
|
iannucci
2016/01/28 01:15:35
this doesn't match the source file name?
dnj
2016/01/29 20:46:52
Done.
| |
| 27 path string | |
| 28 | |
| 29 configSet string | |
| 30 configPath string | |
| 31 } | |
| 32 | |
| 33 var _ config.Interface = (*fileConfig)(nil) | |
| 34 | |
| 35 func (fc *fileConfig) GetConfig(configSet, path string, hashOnly bool) (*config. Config, error) { | |
| 36 if configSet != fc.configSet || path != fc.configPath { | |
| 37 return nil, config.ErrNoConfig | |
| 38 } | |
| 39 | |
| 40 buf := bytes.Buffer{} | |
| 41 fd, err := os.Open(fc.path) | |
| 42 if err != nil { | |
| 43 return nil, err | |
| 44 } | |
| 45 defer fd.Close() | |
| 46 | |
| 47 _, err = buf.ReadFrom(fd) | |
| 48 if err != nil { | |
| 49 return nil, err | |
| 50 } | |
| 51 | |
| 52 hash := sha256.Sum256(buf.Bytes()) | |
| 53 return &config.Config{ | |
| 54 Content: buf.String(), | |
| 55 ContentHash: hex.EncodeToString(hash[:]), | |
| 56 }, nil | |
| 57 } | |
| 58 | |
| 59 func (fc *fileConfig) GetConfigByHash(contentHash string) (string, error) { | |
| 60 return "", errNotImplemented | |
| 61 } | |
| 62 | |
| 63 func (fc *fileConfig) GetConfigSetLocation(configSet string) (*url.URL, error) { | |
| 64 return nil, errNotImplemented | |
| 65 } | |
| 66 | |
| 67 func (fc *fileConfig) GetProjectConfigs(path string, hashesOnly bool) ([]config. Config, error) { | |
| 68 return nil, errNotImplemented | |
| 69 } | |
| 70 | |
| 71 func (fc *fileConfig) GetProjects() ([]config.Project, error) { | |
| 72 return nil, errNotImplemented | |
| 73 } | |
| 74 | |
| 75 func (fc *fileConfig) GetRefConfigs(path string, hashesOnly bool) ([]config.Conf ig, error) { | |
| 76 return nil, errNotImplemented | |
| 77 } | |
| 78 | |
| 79 func (fc *fileConfig) GetRefs(projectID string) ([]string, error) { | |
| 80 return nil, errNotImplemented | |
| 81 } | |
| OLD | NEW |