-
Notifications
You must be signed in to change notification settings - Fork 0
/
reloadsourcesnapshot.go
68 lines (60 loc) · 1.77 KB
/
reloadsourcesnapshot.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package insights
import (
"compress/zlib"
"encoding/json"
"io"
)
// ReloadSourceSnapshot sends the given entities and relationships to the referenced Elimity Insights server.
func ReloadSourceSnapshot(
entities []Entity, insightsURL, sourceID, sourceToken string, relationships []Relationship,
skipSSLVerification bool,
) error {
reader, writer := io.Pipe()
snapshot := snapshot{
Entities: entities,
Relationships: relationships,
}
go writeSnapshot(snapshot, writer)
err := request(
"application/octet-stream", insightsURL, sourceID, sourceToken, "%s/api/sources/%s/snapshots", reader,
skipSSLVerification,
)
_ = reader.Close()
return err
}
func writeSnapshot(snapshot snapshot, pipeWriter *io.PipeWriter) {
zlibWriter := zlib.NewWriter(pipeWriter)
encoder := json.NewEncoder(zlibWriter)
_ = encoder.Encode(snapshot)
_ = zlibWriter.Close()
_ = pipeWriter.Close()
}
// AttributeAssignment represents the assignment of a value for an attribute type to an entity or a relationship.
type AttributeAssignment struct {
AttributeTypeID string
Value Value
}
// Entity represents a domain graph entity together with its attribute assignments.
type Entity struct {
AttributeAssignments []AttributeAssignment
ID string
Name string
Type string
}
// Relationship represents a domain graph relationship together with its attribute assignments.
type Relationship struct {
AttributeAssignments []AttributeAssignment
FromEntityID string
FromEntityType string
ToEntityID string
ToEntityType string
}
// Value represents a typed value of an attribute assignment.
type Value struct {
Type string
Value any
}
type snapshot struct {
Entities []Entity
Relationships []Relationship
}