GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

pkg/storage/protected.go   F
last analyzed

Size/Duplication

Total Lines 335
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
cc 72
eloc 189
dl 0
loc 335
ccs 0
cts 166
cp 0
crap 5256
rs 2.64
c 0
b 0
f 0

16 Methods

Rating   Name   Duplication   Size   Complexity  
A storage.*Storage.CreateTarget 0 17 5
A storage.*Storage.ReadAlias 0 14 4
A storage.*Storage.DeleteTarget 0 14 4
A storage.*Storage.UpdateLink 0 14 4
A storage.*Storage.UpdateTarget 0 17 5
A storage.*Storage.CreateLink 0 14 4
B storage.*Storage.CreateAlias 0 26 7
A storage.*Storage.UpdateNamespace 0 14 4
A storage.*Storage.ReadLink 0 14 4
A storage.*Storage.DeleteAlias 0 14 4
A storage.*Storage.ReadTarget 0 14 4
A storage.*Storage.DeleteLink 0 14 4
A storage.*Storage.ReadNamespace 0 14 4
A storage.*Storage.DeleteNamespace 0 14 4
A storage.*Storage.CreateNamespace 0 14 4
B storage.*Storage.UpdateAlias 0 26 7
1
package storage
2
3
import (
4
	"context"
5
6
	"github.com/kamilsk/click/pkg/domain"
7
	"github.com/kamilsk/click/pkg/storage/query"
8
	"github.com/kamilsk/click/pkg/storage/types"
9
	"golang.org/x/sync/errgroup"
10
)
11
12
/*
13
 *
14
 * Link
15
 *
16
 */
17
18
// CreateLink TODO issue#131
19
func (storage *Storage) CreateLink(ctx context.Context, tokenID domain.ID, data query.CreateLink) (types.Link, error) {
20
	var entity types.Link
21
22
	conn, closer, connErr := storage.connection(ctx)
23
	if connErr != nil {
24
		return entity, connErr
25
	}
26
	defer func() { _ = closer() }()
27
28
	token, authErr := storage.exec.UserManager(ctx, conn).Token(tokenID)
29
	if authErr != nil {
30
		return entity, authErr
31
	}
32
	return storage.exec.LinkEditor(ctx, conn).Create(token, data)
33
}
34
35
// ReadLink TODO issue#131
36
func (storage *Storage) ReadLink(ctx context.Context, tokenID domain.ID, data query.ReadLink) (types.Link, error) {
37
	var entity types.Link
38
39
	conn, closer, connErr := storage.connection(ctx)
40
	if connErr != nil {
41
		return entity, connErr
42
	}
43
	defer func() { _ = closer() }()
44
45
	token, authErr := storage.exec.UserManager(ctx, conn).Token(tokenID)
46
	if authErr != nil {
47
		return entity, authErr
48
	}
49
	return storage.exec.LinkEditor(ctx, conn).Read(token, data)
50
}
51
52
// UpdateLink TODO issue#131
53
func (storage *Storage) UpdateLink(ctx context.Context, tokenID domain.ID, data query.UpdateLink) (types.Link, error) {
54
	var entity types.Link
55
56
	conn, closer, connErr := storage.connection(ctx)
57
	if connErr != nil {
58
		return entity, connErr
59
	}
60
	defer func() { _ = closer() }()
61
62
	token, authErr := storage.exec.UserManager(ctx, conn).Token(tokenID)
63
	if authErr != nil {
64
		return entity, authErr
65
	}
66
	return storage.exec.LinkEditor(ctx, conn).Update(token, data)
67
}
68
69
// DeleteLink TODO issue#131
70
func (storage *Storage) DeleteLink(ctx context.Context, tokenID domain.ID, data query.DeleteLink) (types.Link, error) {
71
	var entity types.Link
72
73
	conn, closer, connErr := storage.connection(ctx)
74
	if connErr != nil {
75
		return entity, connErr
76
	}
77
	defer func() { _ = closer() }()
78
79
	token, authErr := storage.exec.UserManager(ctx, conn).Token(tokenID)
80
	if authErr != nil {
81
		return entity, authErr
82
	}
83
	return storage.exec.LinkEditor(ctx, conn).Delete(token, data)
84
}
85
86
/*
87
 *
88
 * Namespace
89
 *
90
 */
91
92
// CreateNamespace TODO issue#131
93
func (storage *Storage) CreateNamespace(ctx context.Context, tokenID domain.ID, data query.CreateNamespace) (types.Namespace, error) {
94
	var entity types.Namespace
95
96
	conn, closer, connErr := storage.connection(ctx)
97
	if connErr != nil {
98
		return entity, connErr
99
	}
100
	defer func() { _ = closer() }()
101
102
	token, authErr := storage.exec.UserManager(ctx, conn).Token(tokenID)
103
	if authErr != nil {
104
		return entity, authErr
105
	}
106
	return storage.exec.NamespaceEditor(ctx, conn).Create(token, data)
107
}
108
109
// ReadNamespace TODO issue#131
110
func (storage *Storage) ReadNamespace(ctx context.Context, tokenID domain.ID, data query.ReadNamespace) (types.Namespace, error) {
111
	var entity types.Namespace
112
113
	conn, closer, connErr := storage.connection(ctx)
114
	if connErr != nil {
115
		return entity, connErr
116
	}
117
	defer func() { _ = closer() }()
118
119
	token, authErr := storage.exec.UserManager(ctx, conn).Token(tokenID)
120
	if authErr != nil {
121
		return entity, authErr
122
	}
123
	return storage.exec.NamespaceEditor(ctx, conn).Read(token, data)
124
}
125
126
// UpdateNamespace TODO issue#131
127
func (storage *Storage) UpdateNamespace(ctx context.Context, tokenID domain.ID, data query.UpdateNamespace) (types.Namespace, error) {
128
	var entity types.Namespace
129
130
	conn, closer, connErr := storage.connection(ctx)
131
	if connErr != nil {
132
		return entity, connErr
133
	}
134
	defer func() { _ = closer() }()
135
136
	token, authErr := storage.exec.UserManager(ctx, conn).Token(tokenID)
137
	if authErr != nil {
138
		return entity, authErr
139
	}
140
	return storage.exec.NamespaceEditor(ctx, conn).Update(token, data)
141
}
142
143
// DeleteNamespace TODO issue#131
144
func (storage *Storage) DeleteNamespace(ctx context.Context, tokenID domain.ID, data query.DeleteNamespace) (types.Namespace, error) {
145
	var entity types.Namespace
146
147
	conn, closer, connErr := storage.connection(ctx)
148
	if connErr != nil {
149
		return entity, connErr
150
	}
151
	defer func() { _ = closer() }()
152
153
	token, authErr := storage.exec.UserManager(ctx, conn).Token(tokenID)
154
	if authErr != nil {
155
		return entity, authErr
156
	}
157
	return storage.exec.NamespaceEditor(ctx, conn).Delete(token, data)
158
}
159
160
/*
161
 *
162
 * Alias
163
 *
164
 */
165
166
// CreateAlias TODO issue#131
167
func (storage *Storage) CreateAlias(ctx context.Context, tokenID domain.ID, data query.CreateAlias) (types.Alias, error) {
168
	var entity types.Alias
169
170
	conn, closer, connErr := storage.connection(ctx)
171
	if connErr != nil {
172
		return entity, connErr
173
	}
174
	defer func() { _ = closer() }()
175
176
	token, authErr := storage.exec.UserManager(ctx, conn).Token(tokenID)
177
	if authErr != nil {
178
		return entity, authErr
179
	}
180
	g := &errgroup.Group{}
181
	g.Go(func() error {
182
		_, readErr := storage.exec.LinkEditor(ctx, conn).Read(token, query.ReadLink{ID: data.LinkID})
183
		return readErr
184
	})
185
	g.Go(func() error {
186
		_, readErr := storage.exec.NamespaceEditor(ctx, conn).Read(token, query.ReadNamespace{ID: data.NamespaceID})
187
		return readErr
188
	})
189
	if readErr := g.Wait(); readErr != nil {
190
		return entity, readErr
191
	}
192
	return storage.exec.AliasEditor(ctx, conn).Create(token, data)
193
}
194
195
// ReadAlias TODO issue#131
196
func (storage *Storage) ReadAlias(ctx context.Context, tokenID domain.ID, data query.ReadAlias) (types.Alias, error) {
197
	var entity types.Alias
198
199
	conn, closer, connErr := storage.connection(ctx)
200
	if connErr != nil {
201
		return entity, connErr
202
	}
203
	defer func() { _ = closer() }()
204
205
	token, authErr := storage.exec.UserManager(ctx, conn).Token(tokenID)
206
	if authErr != nil {
207
		return entity, authErr
208
	}
209
	return storage.exec.AliasEditor(ctx, conn).Read(token, data)
210
}
211
212
// UpdateAlias TODO issue#131
213
func (storage *Storage) UpdateAlias(ctx context.Context, tokenID domain.ID, data query.UpdateAlias) (types.Alias, error) {
214
	var entity types.Alias
215
216
	conn, closer, connErr := storage.connection(ctx)
217
	if connErr != nil {
218
		return entity, connErr
219
	}
220
	defer func() { _ = closer() }()
221
222
	token, authErr := storage.exec.UserManager(ctx, conn).Token(tokenID)
223
	if authErr != nil {
224
		return entity, authErr
225
	}
226
	g := &errgroup.Group{}
227
	g.Go(func() error {
228
		_, readErr := storage.exec.LinkEditor(ctx, conn).Read(token, query.ReadLink{ID: data.LinkID})
229
		return readErr
230
	})
231
	g.Go(func() error {
232
		_, readErr := storage.exec.NamespaceEditor(ctx, conn).Read(token, query.ReadNamespace{ID: data.NamespaceID})
233
		return readErr
234
	})
235
	if readErr := g.Wait(); readErr != nil {
236
		return entity, readErr
237
	}
238
	return storage.exec.AliasEditor(ctx, conn).Update(token, data)
239
}
240
241
// DeleteAlias TODO issue#131
242
func (storage *Storage) DeleteAlias(ctx context.Context, tokenID domain.ID, data query.DeleteAlias) (types.Alias, error) {
243
	var entity types.Alias
244
245
	conn, closer, connErr := storage.connection(ctx)
246
	if connErr != nil {
247
		return entity, connErr
248
	}
249
	defer func() { _ = closer() }()
250
251
	token, authErr := storage.exec.UserManager(ctx, conn).Token(tokenID)
252
	if authErr != nil {
253
		return entity, authErr
254
	}
255
	return storage.exec.AliasEditor(ctx, conn).Delete(token, data)
256
}
257
258
/*
259
 *
260
 * Target
261
 *
262
 */
263
264
// CreateTarget TODO issue#131
265
func (storage *Storage) CreateTarget(ctx context.Context, tokenID domain.ID, data query.CreateTarget) (types.Target, error) {
266
	var entity types.Target
267
268
	conn, closer, connErr := storage.connection(ctx)
269
	if connErr != nil {
270
		return entity, connErr
271
	}
272
	defer func() { _ = closer() }()
273
274
	token, authErr := storage.exec.UserManager(ctx, conn).Token(tokenID)
275
	if authErr != nil {
276
		return entity, authErr
277
	}
278
	if _, readErr := storage.exec.LinkEditor(ctx, conn).Read(token, query.ReadLink{ID: data.LinkID}); readErr != nil {
279
		return entity, readErr
280
	}
281
	return storage.exec.TargetEditor(ctx, conn).Create(token, data)
282
}
283
284
// ReadTarget TODO issue#131
285
func (storage *Storage) ReadTarget(ctx context.Context, tokenID domain.ID, data query.ReadTarget) (types.Target, error) {
286
	var entity types.Target
287
288
	conn, closer, connErr := storage.connection(ctx)
289
	if connErr != nil {
290
		return entity, connErr
291
	}
292
	defer func() { _ = closer() }()
293
294
	token, authErr := storage.exec.UserManager(ctx, conn).Token(tokenID)
295
	if authErr != nil {
296
		return entity, authErr
297
	}
298
	return storage.exec.TargetEditor(ctx, conn).Read(token, data)
299
}
300
301
// UpdateTarget TODO issue#131
302
func (storage *Storage) UpdateTarget(ctx context.Context, tokenID domain.ID, data query.UpdateTarget) (types.Target, error) {
303
	var entity types.Target
304
305
	conn, closer, connErr := storage.connection(ctx)
306
	if connErr != nil {
307
		return entity, connErr
308
	}
309
	defer func() { _ = closer() }()
310
311
	token, authErr := storage.exec.UserManager(ctx, conn).Token(tokenID)
312
	if authErr != nil {
313
		return entity, authErr
314
	}
315
	if _, readErr := storage.exec.LinkEditor(ctx, conn).Read(token, query.ReadLink{ID: data.LinkID}); readErr != nil {
316
		return entity, readErr
317
	}
318
	return storage.exec.TargetEditor(ctx, conn).Update(token, data)
319
}
320
321
// DeleteTarget TODO issue#131
322
func (storage *Storage) DeleteTarget(ctx context.Context, tokenID domain.ID, data query.DeleteTarget) (types.Target, error) {
323
	var entity types.Target
324
325
	conn, closer, connErr := storage.connection(ctx)
326
	if connErr != nil {
327
		return entity, connErr
328
	}
329
	defer func() { _ = closer() }()
330
331
	token, authErr := storage.exec.UserManager(ctx, conn).Token(tokenID)
332
	if authErr != nil {
333
		return entity, authErr
334
	}
335
	return storage.exec.TargetEditor(ctx, conn).Delete(token, data)
336
}
337