Conditions | 2 |
Paths | 2 |
Total Lines | 28 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
31 | public function handle(Credentials $credentials) |
||
32 | { |
||
33 | $filename = config('credentials.file'); |
||
34 | |||
35 | $decrypted = $credentials->load($filename); |
||
36 | |||
37 | $handle = tmpfile(); |
||
38 | $meta = stream_get_meta_data($handle); |
||
39 | |||
40 | fwrite($handle, json_encode($decrypted, JSON_PRETTY_PRINT | JSON_FORCE_OBJECT)); |
||
41 | |||
42 | $editor = config('credential.editor', 'vi'); |
||
43 | |||
44 | $process = new Process([$editor, $meta['uri']]); |
||
45 | |||
46 | $process->setTty(true); |
||
47 | $process->mustRun(); |
||
48 | |||
49 | $data = json_decode(file_get_contents($meta['uri']), JSON_OBJECT_AS_ARRAY); |
||
50 | |||
51 | if (JSON_ERROR_NONE !== json_last_error()) { |
||
52 | throw InvalidJSON::create(json_last_error()); |
||
53 | } |
||
54 | |||
55 | $credentials->store($data, $filename); |
||
56 | |||
57 | $this->info('Successfully updated credentials.'); |
||
58 | } |
||
59 | } |
||
60 |