|
| 1 | +// Copyright 2025 Specter Ops, Inc. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | +// |
| 15 | +// SPDX-License-Identifier: Apache-2.0 |
| 16 | + |
1 | 17 | package lab
|
2 | 18 |
|
3 | 19 | import (
|
@@ -49,17 +65,6 @@ type Edge struct {
|
49 | 65 | Properties map[string]any `json:"properties"`
|
50 | 66 | }
|
51 | 67 |
|
52 |
| -// ParseGraphFixtureJsonFile takes in a fs.File interface and parses its contents into a |
53 |
| -// GraphFixture struct. |
54 |
| -func ParseGraphFixtureJsonFile(fh fs.File) (GraphFixture, error) { |
55 |
| - var graphFixture GraphFixture |
56 |
| - if err := json.NewDecoder(fh).Decode(&graphFixture); err != nil { |
57 |
| - return graphFixture, fmt.Errorf("could not unmarshal graph data: %w", err) |
58 |
| - } else { |
59 |
| - return graphFixture, nil |
60 |
| - } |
61 |
| -} |
62 |
| - |
63 | 68 | // LoadGraphFixture requires a graph.Database interface and a GraphFixture struct.
|
64 | 69 | // It will import the nodes and edges from the GraphFixture and inserts them into
|
65 | 70 | // the graph database. It uses the `id` property of the nodes as the local
|
@@ -96,15 +101,16 @@ func LoadGraphFixture(db graph.Database, g *GraphFixture) error {
|
96 | 101 | // parse then file into a GraphFixture, and finally import the GraphFixture
|
97 | 102 | // Nodes and Edges into the graph.Database.
|
98 | 103 | func LoadGraphFixtureFile(db graph.Database, fSys fs.FS, path string) error {
|
99 |
| - if fh, err := fSys.Open(path); err != nil { |
| 104 | + fh, err := fSys.Open(path) |
| 105 | + if err != nil { |
100 | 106 | return fmt.Errorf("could not open graph data file: %w", err)
|
101 |
| - } else { |
102 |
| - defer fh.Close() |
103 |
| - if graphFixture, err := ParseGraphFixtureJsonFile(fh); err != nil { |
104 |
| - return fmt.Errorf("could not parse graph data file: %w", err) |
105 |
| - } else if err := LoadGraphFixture(db, &graphFixture); err != nil { |
106 |
| - return fmt.Errorf("could not load graph data: %w", err) |
107 |
| - } |
| 107 | + } |
| 108 | + defer fh.Close() |
| 109 | + var graphFixture GraphFixture |
| 110 | + if err := json.NewDecoder(fh).Decode(&graphFixture); err != nil { |
| 111 | + return fmt.Errorf("could not parse graph data file: %w", err) |
| 112 | + } else if err := LoadGraphFixture(db, &graphFixture); err != nil { |
| 113 | + return fmt.Errorf("could not load graph data: %w", err) |
108 | 114 | }
|
109 | 115 | return nil
|
110 | 116 | }
|
0 commit comments