Skip to content

Commit 27587c4

Browse files
committed
Fix auth0 and cli linting errors
1 parent 2336137 commit 27587c4

6 files changed

Lines changed: 119 additions & 82 deletions

File tree

.golangci.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ linters:
2828
- wrapcheck
2929

3030
settings:
31+
ireturn:
32+
allow:
33+
- error
34+
- empty
35+
- generic
36+
- proto.Message
37+
- plugins.Plugin
38+
- stdlib
39+
- v3.ImporterClient
3140
gomoddirectives:
3241
replace-local: true
3342
lll:

cli/cmd/ds-load/main.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,26 @@ import (
1313
"github.com/aserto-dev/ds-load/sdk/common/kongyaml"
1414
)
1515

16+
const errWritingToStdErr = 2
17+
1618
func main() {
1719
pluginEnum := ""
1820

1921
pluginFinder, err := plugin.NewHomeDirFinder(true)
2022
if err != nil {
21-
os.Stderr.WriteString(err.Error())
23+
if _, err := os.Stderr.WriteString(err.Error()); err != nil {
24+
os.Exit(errWritingToStdErr)
25+
}
26+
2227
os.Exit(1)
2328
}
2429

2530
plugins, err := pluginFinder.Find()
2631
if err != nil {
27-
os.Stderr.WriteString(err.Error())
32+
if _, err := os.Stderr.WriteString(err.Error()); err != nil {
33+
os.Exit(errWritingToStdErr)
34+
}
35+
2836
os.Exit(1)
2937
}
3038

cli/pkg/app/cli.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ func (listPlugins *ListPluginsCmd) Run(c *cc.CommonCtx) error {
5151
}
5252

5353
for _, p := range plugins {
54-
os.Stdout.WriteString(p.Name + " " + p.Path + "\n")
54+
if _, err := os.Stdout.WriteString(p.Name + " " + p.Path + "\n"); err != nil {
55+
return err
56+
}
5557
}
5658

5759
return nil

cli/pkg/app/exec.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,9 @@ func listenOnStderr(c *cc.CommonCtx, wg *sync.WaitGroup, stderr io.ReadCloser) {
155155

156156
for {
157157
line, err := scanner.ReadBytes('\n')
158-
os.Stderr.Write(line)
158+
if _, err := os.Stderr.Write(line); err != nil {
159+
c.Log.Fatal().Err(err).Send()
160+
}
159161

160162
if len(line) > 0 {
161163
gotError = true
@@ -169,7 +171,7 @@ func listenOnStderr(c *cc.CommonCtx, wg *sync.WaitGroup, stderr io.ReadCloser) {
169171

170172
break
171173
} else if err != nil {
172-
c.Log.Fatal().Err(err)
174+
c.Log.Fatal().Err(err).Send()
173175
}
174176
}
175177

cli/pkg/publish/publisher_v3.go

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func (p *DirectoryPublisher) Publish(ctx context.Context, reader io.Reader) erro
4949
var message msg.Transform
5050

5151
err := jsonReader.ReadProtoMessage(&message)
52-
if err == io.EOF {
52+
if errors.Is(err, io.EOF) {
5353
break
5454
}
5555

@@ -91,23 +91,23 @@ func (p *DirectoryPublisher) publishMessages(ctx context.Context, message *msg.T
9191

9292
errGroup.Go(p.doneHandler(stream.Context()))
9393

94-
opCode := message.OpCode
94+
opCode := message.GetOpCode()
9595
if opCode == dsi3.Opcode_OPCODE_UNKNOWN {
9696
opCode = dsi3.Opcode_OPCODE_SET
9797
}
9898

9999
// import objects
100-
for _, object := range message.Objects {
100+
for _, object := range message.GetObjects() {
101101
if err := validator.Object(object); err != nil {
102-
fmt.Fprintf(os.Stderr, "validation failed, object: [%s] type [%s]\n", object.Id, object.Type)
102+
fmt.Fprintf(os.Stderr, "validation failed, object: [%s] type [%s]\n", object.GetId(), object.GetType())
103103
continue
104104
}
105105

106-
if (opCode == dsi3.Opcode_OPCODE_DELETE || opCode == dsi3.Opcode_OPCODE_DELETE_WITH_RELATIONS) && object.Type == "group" {
106+
if (opCode == dsi3.Opcode_OPCODE_DELETE || opCode == dsi3.Opcode_OPCODE_DELETE_WITH_RELATIONS) && object.GetType() == "group" {
107107
continue
108108
}
109109

110-
fmt.Fprintf(os.Stdout, "object: [%s] type [%s]\n", object.Id, object.Type)
110+
fmt.Fprintf(os.Stdout, "object: [%s] type [%s]\n", object.GetId(), object.GetType())
111111
sErr := stream.Send(&dsi3.ImportRequest{
112112
Msg: &dsi3.ImportRequest_Object{
113113
Object: object,
@@ -119,13 +119,14 @@ func (p *DirectoryPublisher) publishMessages(ctx context.Context, message *msg.T
119119
}
120120

121121
// import relations
122-
for _, relation := range message.Relations {
122+
for _, relation := range message.GetRelations() {
123123
if err := validator.Relation(relation); err != nil {
124-
fmt.Fprintf(os.Stderr, "validation failed, relation: [%s] obj: [%s] subj [%s]\n", relation.Relation, relation.ObjectId, relation.SubjectId)
124+
fmt.Fprintf(os.Stderr, "validation failed, relation: [%s] obj: [%s] subj [%s]\n",
125+
relation.GetRelation(), relation.GetObjectId(), relation.GetSubjectId())
125126
continue
126127
}
127128

128-
fmt.Fprintf(os.Stdout, "relation: [%s] obj: [%s] subj [%s]\n", relation.Relation, relation.ObjectId, relation.SubjectId)
129+
fmt.Fprintf(os.Stdout, "relation: [%s] obj: [%s] subj [%s]\n", relation.GetRelation(), relation.GetObjectId(), relation.GetSubjectId())
129130
sErr := stream.Send(&dsi3.ImportRequest{
130131
Msg: &dsi3.ImportRequest_Relation{
131132
Relation: relation,
@@ -154,15 +155,15 @@ func (p *DirectoryPublisher) handleStreamError(err error) {
154155
return
155156
}
156157

157-
p.Log.Err(err)
158+
p.Log.Err(err).Msg("stream error")
158159
common.SetExitCode(1)
159160
}
160161

161162
func (p *DirectoryPublisher) receiver(stream dsi3.Importer_ImportClient) func() error {
162163
return func() error {
163164
for {
164165
result, err := stream.Recv()
165-
if err == io.EOF {
166+
if errors.Is(err, io.EOF) {
166167
return nil
167168
}
168169

@@ -171,13 +172,13 @@ func (p *DirectoryPublisher) receiver(stream dsi3.Importer_ImportClient) func()
171172
}
172173

173174
if result != nil {
174-
switch m := result.Msg.(type) {
175+
switch m := result.GetMsg().(type) {
175176
case *dsi3.ImportResponse_Status:
176177
p.errs = true
177178

178179
printStatus(os.Stderr, m.Status)
179180
case *dsi3.ImportResponse_Counter:
180-
switch m.Counter.Type {
181+
switch m.Counter.GetType() {
181182
case objectsCounter:
182183
p.objCounter = m.Counter
183184
case relationsCounter:
@@ -206,17 +207,17 @@ func (p *DirectoryPublisher) doneHandler(ctx context.Context) func() error {
206207
func printStatus(w io.Writer, status *dsi3.ImportStatus) {
207208
fmt.Fprintf(w, "%-9s : %s - %s (%d)\n",
208209
"error",
209-
status.Msg,
210-
codes.Code(status.Code).String(),
211-
status.Code)
210+
status.GetMsg(),
211+
codes.Code(status.GetCode()).String(),
212+
status.GetCode())
212213
}
213214

214215
func printCounter(w io.Writer, ctr *dsi3.ImportCounter) {
215216
fmt.Fprintf(w, "%-9s : %d (set:%d delete:%d error:%d)\n",
216-
ctr.Type,
217-
ctr.Recv,
218-
ctr.Set,
219-
ctr.Delete,
220-
ctr.Error,
217+
ctr.GetType(),
218+
ctr.GetRecv(),
219+
ctr.GetSet(),
220+
ctr.GetDelete(),
221+
ctr.GetError(),
221222
)
222223
}

0 commit comments

Comments
 (0)