Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 27 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ Optional features include:
* Repository URLs cached alongside dependency data for faster Scorecard lookups.
* GraphViz visual output when `-graph` is supplied (for `/purl` requests).

Dependencies can also be fetched using a [package URL](https://github.com/package-url/purl-spec) via the `/purl/{purl}` endpoint.
Dependencies can also be fetched using a [package URL](https://github.com/package-url/purl-spec) via the `/api/purl/{purl}` endpoint.

Deps.dev API base URLs are exposed via `/config` and package name suggestions (currently npm only) can be requested from `/suggest/{manager}/{query}`.
Deps.dev API base URLs are exposed via `/api/config` and package name suggestions (currently npm only) can be requested from `/api/suggest/{manager}/{query}`.
### Supported package managers

| Manager | Path component mapping | Notes |
Expand Down Expand Up @@ -163,29 +163,29 @@ The binary accepts the following flags:
## API Usage
```

GET /dependencies/{manager}/{namespace}/{name}/{version}
GET /dependencies/{manager}/{name}/{version}
GET /purl/{purl}
GET /config
GET /suggest/{manager}/{query}
GET /repo/{repo}
GET /api/dependencies/{manager}/{namespace}/{name}/{version}
GET /api/dependencies/{manager}/{name}/{version}
GET /api/purl/{purl}
GET /api/config
GET /api/suggest/{manager}/{query}
GET /api/repo/{repo}

GET /lookup?manager=<manager>&name=<name>&version=<version>[&namespace=<ns>][&recursive=true][&vuln=true][&scorecard=true]
GET /api/lookup?manager=<manager>&name=<name>&version=<version>[&namespace=<ns>][&recursive=true][&vuln=true][&scorecard=true]

```

Example for npm (no namespace):

```
curl http://localhost:8080/dependencies/npm/express/4.18.2
curl http://localhost:8080/purl/pkg:npm/express@4.18.2
curl http://localhost:8080/api/dependencies/npm/express/4.18.2
curl http://localhost:8080/api/purl/pkg:npm/express@4.18.2
```

Optional boolean query parameters `recursive`, `vuln`, and `scorecard` can override the
server flags per request:

```
curl "http://localhost:8080/dependencies/npm/express/4.18.2?recursive=true&vuln=true&scorecard=true"
curl "http://localhost:8080/api/dependencies/npm/express/4.18.2?recursive=true&vuln=true&scorecard=true"
```

The response JSON has the simple shape:
Expand Down Expand Up @@ -215,7 +215,7 @@ The `/lookup` endpoint exposes the same functionality using query parameters ins
Example:

```bash
curl "http://localhost:8080/lookup?manager=npm&name=express&version=4.18.2&recursive=true&vuln=true&scorecard=true"
curl "http://localhost:8080/api/lookup?manager=npm&name=express&version=4.18.2&recursive=true&vuln=true&scorecard=true"
```

## Example requests
Expand All @@ -224,33 +224,33 @@ Below are sample invocations for each supported manager with shortened output:

```bash
# npm
curl -s http://localhost:8080/dependencies/npm/express/4.18.2 | head -c 80
curl -s http://localhost:8080/api/dependencies/npm/express/4.18.2 | head -c 80
{"dependencies":{"accepts":"~1.3.8",...}}
curl -s http://localhost:8080/dependencies/npm/@babel/core/7.21.0 | head -c 80
curl -s http://localhost:8080/api/dependencies/npm/@babel/core/7.21.0 | head -c 80
{"dependencies":{"@ampproject/remapping":"^2.2.0",...}}

# pypi
curl -s http://localhost:8080/dependencies/pypi/requests/2.31.0 | head -c 80
curl -s http://localhost:8080/api/dependencies/pypi/requests/2.31.0 | head -c 80
{"dependencies":{"PySocks (!=1.5.7,>=1.5.6) ; extra == 'socks',...}}
curl -s http://localhost:8080/dependencies/pypi/urllib3/2.2.0 | head -c 80
curl -s http://localhost:8080/api/dependencies/pypi/urllib3/2.2.0 | head -c 80
{"dependencies":{"brotli>=1.0.9; (platform_python_implementation == 'CPython') and extra == 'brotli',...}}

# go
curl -s http://localhost:8080/dependencies/go/github.com/gorilla/mux/v1.8.1 | head -c 80
curl -s http://localhost:8080/api/dependencies/go/github.com/gorilla/mux/v1.8.1 | head -c 80
{"dependencies":{}}
curl -s http://localhost:8080/dependencies/go/github.com/stretchr/testify/v1.8.2 | head -c 80
curl -s http://localhost:8080/api/dependencies/go/github.com/stretchr/testify/v1.8.2 | head -c 80
{"dependencies":{"github.com/davecgh/go-spew":"v1.1.1",...}}

# maven
curl -s http://localhost:8080/dependencies/maven/org.apache.commons/commons-lang3/3.12.0 | head -c 80
curl -s http://localhost:8080/api/dependencies/maven/org.apache.commons/commons-lang3/3.12.0 | head -c 80
{"dependencies":{"com.google.code.findbugs:jsr305":"3.0.2",...}}
curl -s http://localhost:8080/dependencies/maven/junit/junit/4.13.2 | head -c 80
curl -s http://localhost:8080/api/dependencies/maven/junit/junit/4.13.2 | head -c 80
{"dependencies":{"org.hamcrest:hamcrest-core":"${hamcrestVersion}",...}}

# cargo
curl -s http://localhost:8080/dependencies/cargo/rand/0.8.5 | head -c 80
curl -s http://localhost:8080/api/dependencies/cargo/rand/0.8.5 | head -c 80
{"dependencies":{"bincode":"^1.2.1",...}}
curl -s http://localhost:8080/dependencies/cargo/serde/1.0.200 | head -c 80
curl -s http://localhost:8080/api/dependencies/cargo/serde/1.0.200 | head -c 80
{"dependencies":{"serde_derive":"^1"}}
```

Expand All @@ -259,7 +259,7 @@ curl -s http://localhost:8080/dependencies/cargo/serde/1.0.200 | head -c 80
The following shows the complete JSON returned for one of the above requests:

```bash
curl -s http://localhost:8080/dependencies/npm/express/4.18.2 | jq
curl -s http://localhost:8080/api/dependencies/npm/express/4.18.2 | jq
{
"dependencies": {
"qs": "6.11.0",
Expand Down Expand Up @@ -317,11 +317,11 @@ Example requests with the expanded output:

```bash
# npm
curl -s http://localhost:8080/dependencies/npm/express/4.18.2 | head -c 80
curl -s http://localhost:8080/api/dependencies/npm/express/4.18.2 | head -c 80
# maven
curl -s http://localhost:8080/dependencies/maven/org.apache.commons/commons-lang3/3.12.0 | head -c 80
curl -s http://localhost:8080/api/dependencies/maven/org.apache.commons/commons-lang3/3.12.0 | head -c 80
# go
curl -s http://localhost:8080/dependencies/go/github.com/stretchr/testify/v1.8.2 | head -c 80
curl -s http://localhost:8080/api/dependencies/go/github.com/stretchr/testify/v1.8.2 | head -c 80
```

Any dependencies that fail to resolve will appear in an `errors` array in the JSON response.
Expand Down
16 changes: 8 additions & 8 deletions cmd/oss-deps-explorer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -699,12 +699,12 @@ func main() {
r := mux.NewRouter()
r.Use(logRequests)

r.HandleFunc("/config", func(w http.ResponseWriter, req *http.Request) {
r.HandleFunc("/api/config", func(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(cfg.PackageManager)
}).Methods(http.MethodGet)

r.HandleFunc("/suggest/{manager}/{query}", func(w http.ResponseWriter, req *http.Request) {
r.HandleFunc("/api/suggest/{manager}/{query}", func(w http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
pm := vars["manager"]
q := vars["query"]
Expand Down Expand Up @@ -744,7 +744,7 @@ func main() {
w.Write(data)
}).Methods(http.MethodGet)

r.HandleFunc("/repo/{repo:.*}", func(w http.ResponseWriter, req *http.Request) {
r.HandleFunc("/api/repo/{repo:.*}", func(w http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
repo := strings.TrimPrefix(vars["repo"], "github.com/")
ctx := req.Context()
Expand All @@ -758,7 +758,7 @@ func main() {
}).Methods(http.MethodGet)

// generic lookup endpoint using query parameters
r.HandleFunc("/lookup", func(w http.ResponseWriter, req *http.Request) {
r.HandleFunc("/api/lookup", func(w http.ResponseWriter, req *http.Request) {
q := req.URL.Query()
pm := q.Get("manager")
ns := q.Get("namespace")
Expand Down Expand Up @@ -830,7 +830,7 @@ func main() {
}).Methods(http.MethodGet)

// special route for Go modules which may contain slashes in the module path
r.HandleFunc("/dependencies/go/{module:.+}/{version}", func(w http.ResponseWriter, req *http.Request) {
r.HandleFunc("/api/dependencies/go/{module:.+}/{version}", func(w http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
module := vars["module"]
version := vars["version"]
Expand Down Expand Up @@ -905,7 +905,7 @@ func main() {
}).Methods(http.MethodGet)

// lookup via package URL
r.HandleFunc("/purl/{purl}", func(w http.ResponseWriter, req *http.Request) {
r.HandleFunc("/api/purl/{purl}", func(w http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
pstr := vars["purl"]
pu, err := purl.FromString(pstr)
Expand Down Expand Up @@ -989,7 +989,7 @@ func main() {
}).Methods(http.MethodGet)

// route with namespace
r.HandleFunc("/dependencies/{manager}/{namespace}/{name}/{version}", func(w http.ResponseWriter, req *http.Request) {
r.HandleFunc("/api/dependencies/{manager}/{namespace}/{name}/{version}", func(w http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
pm := vars["manager"]
ns := vars["namespace"]
Expand Down Expand Up @@ -1062,7 +1062,7 @@ func main() {
}).Methods(http.MethodGet)

// route without namespace
r.HandleFunc("/dependencies/{manager}/{name}/{version}", func(w http.ResponseWriter, req *http.Request) {
r.HandleFunc("/api/dependencies/{manager}/{name}/{version}", func(w http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
pm := vars["manager"]
name := vars["name"]
Expand Down
3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ services:
- "8080:8080"
depends_on:
- redis
restart: always
ui:
build:
context: ./ui
ports:
- "8081:80"
restart: always
redis:
image: redis:7-alpine
restart: always
command: redis-server --save "" --appendonly no
14 changes: 7 additions & 7 deletions ui/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ function App() {
const defaults = {
r: 0,
g: 0,
b: 0,
opacity: 1,
b: 30,
opacity: 0.65,
brightness: 100,
elementOpacity: 1,
};
Expand Down Expand Up @@ -95,7 +95,7 @@ function App() {
});
const [includeScorecard, setIncludeScorecard] = React.useState(() => {
const v = localStorage.getItem("includeScorecard");
return v === null ? false : v === "true";
return v === null ? true : v === "true";
});
const showVersionSuggestions = !version && latestVersions.length > 0;

Expand Down Expand Up @@ -324,7 +324,7 @@ function App() {
}
let cancelled = false;
const timer = setTimeout(() => {
fetchInternal(`${apiOrigin}/suggest/${manager}/${encodeURIComponent(name)}`)
fetchInternal(`${apiOrigin}/api/suggest/${manager}/${encodeURIComponent(name)}`)
.then((resp) => (resp.ok ? resp.json() : []))
.then((data) => {
if (!cancelled) {
Expand Down Expand Up @@ -367,7 +367,7 @@ function App() {
}, []);

React.useEffect(() => {
fetchInternal(`${apiOrigin}/config`)
fetchInternal(`${apiOrigin}/api/config`)
.then((resp) => (resp.ok ? resp.json() : {}))
.then((data) => setPmURLs(data))
.catch(() => {});
Expand All @@ -381,7 +381,7 @@ function App() {
);
const repo = repos[key];
if (repo && !repoMeta[repo]) {
fetchInternal(`${apiOrigin}/repo/${repo}`)
fetchInternal(`${apiOrigin}/api/repo/${repo}`)
.then((resp) => (resp.ok ? resp.json() : {}))
.then((data) => {
setRepoMeta((prev) => ({ ...prev, [repo]: data }));
Expand Down Expand Up @@ -714,7 +714,7 @@ function App() {
setSubmittedNamespace(nsVal);
setSubmittedManager(mgrVal);

const base = `${apiOrigin}/dependencies/${mgrVal}`;
const base = `${apiOrigin}/api/dependencies/${mgrVal}`;
const path = nsVal
? `${base}/${nsVal}/${nameVal}/${ver}`
: `${base}/${nameVal}/${ver}`;
Expand Down
4 changes: 2 additions & 2 deletions ui/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
url = `${apiOrigin}/purl/${purl}`;
} else if (parts.length === 3) {
const [mgr, name, ver] = parts;
url = `${apiOrigin}/dependencies/${mgr}/${name}/${ver}`;
url = `${apiOrigin}/api/dependencies/${mgr}/${name}/${ver}`;
} else if (parts.length === 4) {
const [mgr, ns, name, ver] = parts;
url = `${apiOrigin}/dependencies/${mgr}/${ns}/${name}/${ver}`;
url = `${apiOrigin}/api/dependencies/${mgr}/${ns}/${name}/${ver}`;
} else {
addMsg(
"bot",
Expand Down
8 changes: 3 additions & 5 deletions ui/theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ body {
font-family: 'Inter', 'Roboto', Arial, sans-serif;
margin: 0;
padding: 0 20px 60px 60px;
background: radial-gradient(circle at center top, rgba(0, 229, 255, 0.15), var(--background-default) 80%);
background: radial-gradient(circle at center top, rgba(67, 99, 117, 0.842), var(--background-default) 75%);
color: var(--text-color);
overflow-y: hidden;
}
Expand Down Expand Up @@ -196,14 +196,13 @@ form {
gap: 10px;
align-items: center;
margin-top: 5px;
margin-left: auto;
}

.options-row label {
display: flex;
align-items: center;
gap: 4px;
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
text-shadow: 0 1px 12px rgba(0, 0, 0, 1);
}

.options-row input[type="checkbox"] {
Expand Down Expand Up @@ -337,7 +336,7 @@ form {

hr.repo-divider {
border: none;
border-top: 1px solid rgba(255, 255, 255, 0.15);
border-top: 1px solid rgba(0, 0, 30, 0.65);
margin: 6px 0;
width: 100%;
}
Expand Down Expand Up @@ -803,7 +802,6 @@ li.transitive {
margin-right: auto;
align-items: flex-start;
position: relative;
z-index: -1;
padding-left: 0;
}

Expand Down
Loading
Loading