Skip to content

Commit 3336831

Browse files
committed
chore: BED-5468 - added licenses and minor code cleanup in fixture loader
1 parent da96c5d commit 3336831

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed

packages/go/lab/loader.go

+25-19
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
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+
117
package lab
218

319
import (
@@ -49,17 +65,6 @@ type Edge struct {
4965
Properties map[string]any `json:"properties"`
5066
}
5167

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-
6368
// LoadGraphFixture requires a graph.Database interface and a GraphFixture struct.
6469
// It will import the nodes and edges from the GraphFixture and inserts them into
6570
// 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 {
96101
// parse then file into a GraphFixture, and finally import the GraphFixture
97102
// Nodes and Edges into the graph.Database.
98103
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 {
100106
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)
108114
}
109115
return nil
110116
}

0 commit comments

Comments
 (0)