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

Side by Side Diff: server/internal/logdog/config/fileConfig.go

Issue 1610993002: LogDog: Add collector service implementation. (Closed) Base URL: https://github.com/luci/luci-go@master
Patch Set: Reorganized, cleaned up, comments, and updated for pRPC. Created 4 years, 10 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
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
iannucci 2016/02/05 23:41:01 I feel like this sort of thing should really be so
dnj (Google) 2016/02/06 04:10:37 If it were fully implemented I'd agree, but ATM it
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 {
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698