Skip to content

Commit 44d47f3

Browse files
committed
fix: api and docs
1 parent 51989ca commit 44d47f3

35 files changed

Lines changed: 1469 additions & 344 deletions

Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ COPY --from=builder /app/build/authonomy .
1919

2020
COPY --from=builder /app/config.yaml .
2121

22+
COPY --from=builder /app/web ./web
23+
2224
# sample schemas
23-
COPY --from=builder /app/sample_schema ./sample_schema
25+
COPY --from=builder /app/ssi/schemas ./ssi/schemas
2426

2527
EXPOSE 8081
2628

cmd/cmd.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ var rootCmd = &cobra.Command{
1414
Long: "authonomy service build over ssi service",
1515
}
1616

17+
// init initialize the command.
1718
func init() {
1819
cobra.OnInitialize(getConfig)
1920
rootCmd.AddCommand(startCmd)
2021
startCmd.Flags().BoolVarP(&resetFlag, "reset", "r", false, "Reset the service")
2122
}
2223

24+
// getConfig read the configuration.
2325
func getConfig() {
2426
// Set the base name of the config file, without the file extension.
2527
viper.SetConfigName("config")
@@ -35,6 +37,7 @@ func getConfig() {
3537
}
3638
}
3739

40+
// servicePort get the port from the config else sets the default.
3841
func servicePort() string {
3942
port := viper.GetString("service.port")
4043
if port == "" {
@@ -43,19 +46,21 @@ func servicePort() string {
4346
return ":" + port
4447
}
4548

49+
// resetFlag the flag is to reset the database and imports the supported schema.
4650
var resetFlag bool
51+
4752
var startCmd = &cobra.Command{
4853
Use: "start",
4954
Short: "Start the authonomy service",
5055
Run: func(cmd *cobra.Command, args []string) {
5156
dbPath := viper.GetString("service.badger_path")
5257
secret := viper.GetString("service.db_encryption_key")
53-
apiKey := viper.GetString("api.x-api-key")
5458
ssiUrl := viper.GetString("service.ssi_service_url")
55-
Start(dbPath, secret, apiKey, servicePort(), ssiUrl, resetFlag)
59+
Start(dbPath, secret, servicePort(), ssiUrl, resetFlag)
5660
},
5761
}
5862

63+
// Execute entrypoint for the service.
5964
func Execute() {
6065
err := rootCmd.Execute()
6166
if err != nil {

cmd/server.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ import (
1010

1111
_ "authonomy/docs" // Swaggo generates docs in this package
1212

13+
"github.com/google/uuid"
1314
httpSwagger "github.com/swaggo/http-swagger"
1415
)
1516

16-
func Start(dbPath, secret, apiKey, port, ssiUrl string, reset bool) {
17+
func Start(dbPath, secret, port, ssiUrl string, reset bool) {
1718
// Initialize the data store (e.g., database connection)
1819
store, err := store.NewStore(dbPath, secret)
1920
if err != nil {
@@ -35,7 +36,8 @@ func Start(dbPath, secret, apiKey, port, ssiUrl string, reset bool) {
3536
log.Fatalf("Failed to create policies: %v", err)
3637
}
3738
}
38-
39+
// generate a new api key
40+
apiKey := uuid.New().String()
3941
fmt.Println("=======================")
4042
fmt.Println("\033[32m", "------x-api-key------", "\033[0m")
4143
fmt.Println("\033[32m", apiKey, "\033[0m")
@@ -52,7 +54,7 @@ func Start(dbPath, secret, apiKey, port, ssiUrl string, reset bool) {
5254
credentialHandler := handlers.NewCredentialHandler(ssiService, store)
5355
authHandler := handlers.NewAuthHandler(ssiService, store)
5456
// Swagger endpoint
55-
url := httpSwagger.URL("http://localhost:8081/swagger/doc.json") // The url pointing to API definition
57+
url := httpSwagger.URL("http://localhost" + port + "/swagger/doc.json")
5658
http.Handle("/swagger/", httpSwagger.Handler(
5759
url, //The url pointing to API definition
5860
))
@@ -73,7 +75,7 @@ func Start(dbPath, secret, apiKey, port, ssiUrl string, reset bool) {
7375
http.HandleFunc("/revoke-credential", m.ChainMiddleware(m.XApiKeyMiddleware, m.LoggingMiddleware)(credentialHandler.RevokeOAuthCredential))
7476

7577
// application itself access
76-
http.HandleFunc("/validate-access", m.ChainMiddleware(m.LoggingMiddleware)(authHandler.VerifyAccess))
78+
http.HandleFunc("/verify-access", m.ChainMiddleware(m.LoggingMiddleware)(authHandler.VerifyAccess))
7779
http.HandleFunc("/issue-credential", m.ChainMiddleware(m.EnableCORS, m.LoggingMiddleware)(credentialHandler.IssueOAuthCredential))
7880
// application user access
7981
http.HandleFunc("/callback/", m.ChainMiddleware(m.EnableCORS, m.LoggingMiddleware)(callbackHandler.HandleCallback))
@@ -82,7 +84,7 @@ func Start(dbPath, secret, apiKey, port, ssiUrl string, reset bool) {
8284

8385
http.HandleFunc("/get-access-token", m.ChainMiddleware(m.LoggingMiddleware)(authHandler.GetAccessToken))
8486
http.HandleFunc("/request-access", m.ChainMiddleware(m.LoggingMiddleware)(authHandler.RequestAccess))
85-
87+
http.HandleFunc("/get-access-list", m.ChainMiddleware(m.LoggingMiddleware)(authHandler.GetAccessList))
8688
// static web page for access_token
8789
fs := http.FileServer(http.Dir("web"))
8890
http.Handle("/web/", http.StripPrefix("/web/", fs))

config.yaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,4 @@ service:
44
db_encryption_key: badger
55
jwt_encryption_key: random
66
port: 8081
7-
ssi_service_url : http://172.23.0.5:8080/v1
8-
api:
9-
x-api-key: 9dfccbf4-8c41-412f-841f-8cc10e4a26be
10-
7+
ssi_service_url : http://ssi:3000/v1

docker-compose.yaml

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,75 @@ services:
1212
volumes:
1313
- .:/app
1414
- ./config.yaml:/root/config.yaml
15-
- ./sample_schema:/root/sample_schema
15+
- ./ssi/schema:/root/ssi/schema
16+
- ./web:/root/web
17+
networks:
18+
- ssi_network
19+
depends_on:
20+
- ssi
21+
ssi:
22+
container_name: ssi
23+
image: ghcr.io/tbd54566975/ssi-service:main
24+
ports:
25+
- "8080:3000"
26+
environment:
27+
- CONFIG_PATH=/app/config/test.toml
28+
- JAEGER_HTTP_URL=http://jaeger:14268/api/traces
29+
depends_on:
30+
- jaeger
31+
- redis
32+
volumes:
33+
- ./ssi/config:/app/config
34+
networks:
35+
- ssi_network
36+
- universal-resolver
37+
links:
38+
- uni-resolver
39+
jaeger:
40+
image: jaegertracing/all-in-one:latest
41+
platform: "linux/amd64"
42+
ports:
43+
- "6831:6831/udp"
44+
- "16686:16686"
45+
- "14268:14268"
46+
networks:
47+
- ssi_network
48+
redis:
49+
image: redis:alpine
50+
environment:
51+
- ALLOW_EMPTY_PASSWORD=yes
52+
# This allows for data to not be persisted on new runs
53+
command: [sh, -c, "rm -f /data/dump.rdb && redis-server --save ''"]
54+
ports:
55+
- "6379:6379"
56+
networks:
57+
- ssi_network
58+
redis-commander:
59+
container_name: redis-commander
60+
hostname: redis-commander
61+
image: ghcr.io/joeferner/redis-commander:latest
62+
restart: always
63+
environment:
64+
- REDIS_HOSTS=local:redis:6379
65+
ports:
66+
- "9001:8081"
67+
networks:
68+
- ssi_network
69+
uni-resolver:
70+
image: universalresolver/uni-resolver-web:latest
71+
ports:
72+
- "8088:8080"
73+
platform: "linux/amd64"
74+
networks:
75+
- universal-resolver
76+
driver-did-ion:
77+
image: identityfoundation/driver-did-ion:v0.8.1
78+
ports:
79+
- "8089:8080"
80+
platform: "linux/amd64"
81+
networks:
82+
- universal-resolver
1683

84+
networks:
85+
ssi_network:
86+
universal-resolver:

0 commit comments

Comments
 (0)