| OLD | NEW |
| 1 // Copyright 2016 The LUCI Authors. All rights reserved. | 1 // Copyright 2016 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 // Package lucictx implements a Go client for the protocol defined here: | 5 // Package lucictx implements a Go client for the protocol defined here: |
| 6 // https://github.com/luci/luci-py/blob/master/client/LUCI_CONTEXT.md | 6 // https://github.com/luci/luci-py/blob/master/client/LUCI_CONTEXT.md |
| 7 // | 7 // |
| 8 // It differs from the python client in a couple ways: | 8 // It differs from the python client in a couple ways: |
| 9 // * The initial LUCI_CONTEXT value is captured once at application start, and | 9 // * The initial LUCI_CONTEXT value is captured once at application start, and |
| 10 // the environment variable is REMOVED. | 10 // the environment variable is REMOVED. |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 return &nullExport{}, nil | 168 return &nullExport{}, nil |
| 169 } | 169 } |
| 170 | 170 |
| 171 if dir == "" { | 171 if dir == "" { |
| 172 dir = os.TempDir() | 172 dir = os.TempDir() |
| 173 } | 173 } |
| 174 // Note: this makes a file in 0600 mode. This is what we want, the conte
xt | 174 // Note: this makes a file in 0600 mode. This is what we want, the conte
xt |
| 175 // may have secrets. | 175 // may have secrets. |
| 176 f, err := ioutil.TempFile(dir, "luci_context.") | 176 f, err := ioutil.TempFile(dir, "luci_context.") |
| 177 if err != nil { | 177 if err != nil { |
| 178 » » return nil, errors.Annotate(err).Reason("creating luci_context f
ile").Err() | 178 » » return nil, errors.Annotate(err, "creating luci_context file").E
rr() |
| 179 } | 179 } |
| 180 | 180 |
| 181 l := &liveExport{path: f.Name()} | 181 l := &liveExport{path: f.Name()} |
| 182 data, _ := json.Marshal(cur) | 182 data, _ := json.Marshal(cur) |
| 183 _, err = f.Write(data) | 183 _, err = f.Write(data) |
| 184 f.Close() // intentionally do this even on error. | 184 f.Close() // intentionally do this even on error. |
| 185 if err != nil { | 185 if err != nil { |
| 186 l.Close() // cleans up the tempfile | 186 l.Close() // cleans up the tempfile |
| 187 » » return nil, errors.Annotate(err).Reason("writing luci_context").
Err() | 187 » » return nil, errors.Annotate(err, "writing luci_context").Err() |
| 188 } | 188 } |
| 189 return l, nil | 189 return l, nil |
| 190 } | 190 } |
| OLD | NEW |