Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
API
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
flow3r
API
Commits
4aa151bf
Commit
4aa151bf
authored
Aug 18, 2023
by
rahix
Browse files
Options
Downloads
Patches
Plain Diff
Add shame endpoint
parent
23f51bb5
No related branches found
No related tags found
1 merge request
!2
Add endpoint for apps which throw errors
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
main.go
+1
-0
1 addition, 0 deletions
main.go
server.go
+14
-3
14 additions, 3 deletions
server.go
server_apps.go
+66
-6
66 additions, 6 deletions
server_apps.go
with
81 additions
and
9 deletions
main.go
+
1
−
0
View file @
4aa151bf
...
...
@@ -33,6 +33,7 @@ func main() {
http
.
HandleFunc
(
"/api/release/"
,
s
.
handleReleaseMirror
)
http
.
HandleFunc
(
"/api/apps/zip/"
,
s
.
handleAppZip
)
http
.
HandleFunc
(
"/api/apps/tar/"
,
s
.
handleAppTargz
)
http
.
HandleFunc
(
"/api/apps/shame.json"
,
s
.
handleAppShame
)
http
.
HandleFunc
(
"/api/apps/"
,
s
.
handleApp
)
log
.
Printf
(
"Listening on %s..."
,
flagListen
)
http
.
ListenAndServe
(
flagListen
,
nil
)
...
...
This diff is collapsed.
Click to expand it.
server.go
+
14
−
3
View file @
4aa151bf
...
...
@@ -22,7 +22,7 @@ type server struct {
type
req
struct
{
getReleases
chan
[]
GLRelease
getAppRegistry
chan
[]
*
app
Descriptor
getAppRegistry
chan
*
app
Registry
}
func
(
s
*
server
)
run
(
ctx
context
.
Context
)
{
...
...
@@ -70,11 +70,22 @@ func (s *server) getReleases(ctx context.Context) ([]GLRelease, error) {
}
func
(
s
*
server
)
getApps
(
ctx
context
.
Context
)
([]
*
appDescriptor
,
error
)
{
sresC
:=
make
(
chan
[]
*
app
Descriptor
)
sresC
:=
make
(
chan
*
app
Registry
)
select
{
case
s
.
reqC
<-
&
req
{
getAppRegistry
:
sresC
}
:
res
:=
<-
sresC
return
res
,
nil
return
res
.
apps
,
nil
case
<-
ctx
.
Done
()
:
return
nil
,
ctx
.
Err
()
}
}
func
(
s
*
server
)
getAppShame
(
ctx
context
.
Context
)
([]
*
appShame
,
error
)
{
sresC
:=
make
(
chan
*
appRegistry
)
select
{
case
s
.
reqC
<-
&
req
{
getAppRegistry
:
sresC
}
:
res
:=
<-
sresC
return
res
.
shame
,
nil
case
<-
ctx
.
Done
()
:
return
nil
,
ctx
.
Err
()
}
...
...
This diff is collapsed.
Click to expand it.
server_apps.go
+
66
−
6
View file @
4aa151bf
...
...
@@ -26,6 +26,16 @@ import (
"github.com/pelletier/go-toml/v2"
)
type
appRegistry
struct
{
shame
[]
*
appShame
apps
[]
*
appDescriptor
}
type
appShame
struct
{
repository
string
errorMsg
string
}
type
appDescriptor
struct
{
repository
string
pathInRepo
string
...
...
@@ -386,7 +396,7 @@ func (s *server) getAppInfo(ctx context.Context, pathInRepo, repo string) (*appI
return
app
,
nil
}
func
(
s
*
server
)
getAppRegistry
(
ctx
context
.
Context
)
(
[]
*
app
Descriptor
,
error
)
{
func
(
s
*
server
)
getAppRegistry
(
ctx
context
.
Context
)
(
*
app
Registry
,
error
)
{
s
.
gitMu
.
Lock
()
defer
s
.
gitMu
.
Unlock
()
if
s
.
appRepo
==
nil
{
...
...
@@ -421,7 +431,7 @@ func (s *server) getAppRegistry(ctx context.Context) ([]*appDescriptor, error) {
return
nil
,
err
}
var
re
s
[]
*
appDescriptor
var
re
gistry
appRegistry
for
{
f
,
err
:=
iter
.
Next
()
if
err
==
io
.
EOF
{
...
...
@@ -440,6 +450,10 @@ func (s *server) getAppRegistry(ctx context.Context) ([]*appDescriptor, error) {
reader
,
err
:=
f
.
Reader
()
if
err
!=
nil
{
log
.
Printf
(
"App %q: couldn't read TOML: %v"
,
m
[
1
],
err
)
registry
.
shame
=
append
(
registry
.
shame
,
&
appShame
{
repository
:
fmt
.
Sprintf
(
"<app-list toml: %q>"
,
m
[
1
]),
errorMsg
:
fmt
.
Sprintf
(
"couldn't read TOML: %v"
,
err
),
})
continue
}
...
...
@@ -452,23 +466,35 @@ func (s *server) getAppRegistry(ctx context.Context) ([]*appDescriptor, error) {
reader
.
Close
()
if
err
!=
nil
{
log
.
Printf
(
"App %q: couldn't parse TOML: %v"
,
m
[
1
],
err
)
registry
.
shame
=
append
(
registry
.
shame
,
&
appShame
{
repository
:
fmt
.
Sprintf
(
"<app-list toml: %q>"
,
m
[
1
]),
errorMsg
:
fmt
.
Sprintf
(
"couldn't read TOML: %v"
,
err
),
})
continue
}
n
:=
reAppRepo
.
FindStringSubmatch
(
dat
.
Repo
)
if
n
==
nil
{
log
.
Printf
(
"App %q: invalid repo %q"
,
m
[
1
],
dat
.
Repo
)
registry
.
shame
=
append
(
registry
.
shame
,
&
appShame
{
repository
:
fmt
.
Sprintf
(
"<app-list toml: %q>"
,
m
[
1
]),
errorMsg
:
fmt
.
Sprintf
(
"invalid repo %q"
,
dat
.
Repo
),
})
continue
}
res
=
append
(
res
,
&
appDescriptor
{
re
gistry
.
app
s
=
append
(
re
gistry
.
app
s
,
&
appDescriptor
{
repository
:
dat
.
Repo
,
pathInRepo
:
dat
.
PathInRepo
,
})
}
for
_
,
app
:=
range
res
{
for
_
,
app
:=
range
re
gistry
.
app
s
{
info
,
err
:=
s
.
getAppInfo
(
ctx
,
app
.
pathInRepo
,
app
.
repository
)
if
err
!=
nil
{
log
.
Printf
(
"App %q: %v"
,
app
.
repository
,
err
)
registry
.
shame
=
append
(
registry
.
shame
,
&
appShame
{
repository
:
app
.
repository
,
errorMsg
:
fmt
.
Sprintf
(
"%v"
,
err
),
})
continue
}
else
{
log
.
Printf
(
"App: %q: okay"
,
app
.
repository
)
...
...
@@ -476,8 +502,9 @@ func (s *server) getAppRegistry(ctx context.Context) ([]*appDescriptor, error) {
app
.
appInfo
=
info
}
log
.
Printf
(
"Got %d apps"
,
len
(
res
))
return
res
,
nil
log
.
Printf
(
"Got %d apps and %d apps with shame"
,
len
(
registry
.
apps
),
len
(
registry
.
shame
))
return
&
registry
,
nil
}
type
jsonApp
struct
{
...
...
@@ -573,6 +600,39 @@ func (s *server) handleApp(w http.ResponseWriter, r *http.Request) {
http
.
NotFound
(
w
,
r
)
}
func
(
s
*
server
)
handleAppShame
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
ctx
:=
r
.
Context
()
appShame
,
err
:=
s
.
getAppShame
(
ctx
)
if
err
!=
nil
{
return
}
type
jsonAppShame
struct
{
Repo
string
`json:"repo"`
ErrorMsg
string
`json:"errorMsg"`
}
type
res
struct
{
DT
time
.
Time
`json:"isodatetime"`
Apps
[]
jsonAppShame
`json:"shame"`
}
resp
:=
res
{
DT
:
time
.
Now
(),
}
for
_
,
shame
:=
range
appShame
{
// Guarenteed to be exactly 2 parts because of the regex
resp
.
Apps
=
append
(
resp
.
Apps
,
jsonAppShame
{
Repo
:
shame
.
repository
,
ErrorMsg
:
shame
.
errorMsg
,
})
}
w
.
Header
()
.
Add
(
"Access-Control-Allow-Origin"
,
"*"
)
w
.
Header
()
.
Add
(
"Content-Type"
,
"application/json"
)
j
:=
json
.
NewEncoder
(
w
)
j
.
Encode
(
resp
)
}
var
(
reAppZipURL
=
regexp
.
MustCompile
(
`^/api/apps/zip/([^/]+)/([^/]+)\.zip$`
)
reAppTargzURL
=
regexp
.
MustCompile
(
`^/api/apps/tar/([^/]+)/([^/]+)\.tar\.gz$`
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment