-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The application now provides a `resolver` command that can be used to deploy a DIF Universal Resolver driver for the `did:algo` method. More information: https://github.com/decentralized-identity/universal-resolver
- Loading branch information
Showing
43 changed files
with
1,026 additions
and
545 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
"os" | ||
"syscall" | ||
"time" | ||
|
||
"github.com/algorandfoundation/did-algo/client/internal" | ||
"github.com/algorandfoundation/did-algo/info" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
"go.bryk.io/pkg/cli" | ||
pkgHttp "go.bryk.io/pkg/net/http" | ||
"go.bryk.io/pkg/otel" | ||
) | ||
|
||
var resolverCmd = &cobra.Command{ | ||
Use: "resolver", | ||
Short: "Start a standalone resolver server", | ||
RunE: runResolverServer, | ||
Long: `Resolver server | ||
Resolver server provides a DIF compatible endpoint for DID | ||
document resolution. The server endpoint can be used as a | ||
standalone Universal Resolver Driver. | ||
More information: | ||
https://github.com/decentralized-identity/universal-resolver`, | ||
} | ||
|
||
func init() { | ||
params := []cli.Param{ | ||
{ | ||
Name: "port", | ||
Usage: "TCP port to use for the server", | ||
FlagKey: "resolver.port", | ||
ByDefault: 9091, | ||
Short: "p", | ||
}, | ||
{ | ||
Name: "proxy-protocol", | ||
Usage: "enable support for PROXY protocol", | ||
FlagKey: "resolver.proxy_protocol", | ||
ByDefault: false, | ||
Short: "P", | ||
}, | ||
{ | ||
Name: "tls", | ||
Usage: "enable secure communications using TLS with provided credentials", | ||
FlagKey: "resolver.tls.enabled", | ||
ByDefault: false, | ||
}, | ||
{ | ||
Name: "tls-ca", | ||
Usage: "TLS custom certificate authority (path to PEM file)", | ||
FlagKey: "resolver.tls.ca", | ||
ByDefault: "", | ||
}, | ||
{ | ||
Name: "tls-cert", | ||
Usage: "TLS certificate (path to PEM file)", | ||
FlagKey: "resolver.tls.cert", | ||
ByDefault: "/etc/algoid/tls/tls.crt", | ||
}, | ||
{ | ||
Name: "tls-key", | ||
Usage: "TLS private key (path to PEM file)", | ||
FlagKey: "resolver.tls.key", | ||
ByDefault: "/etc/algoid/tls/tls.key", | ||
}, | ||
{ | ||
Name: "agent", | ||
Usage: "Network agent to communicate with", | ||
FlagKey: "resolver.client.node", | ||
ByDefault: internal.DefaultAgentEndpoint, | ||
Short: "a", | ||
}, | ||
{ | ||
Name: "agent-insecure", | ||
Usage: "Use an insecure connection to the network agent", | ||
FlagKey: "resolver.client.insecure", | ||
ByDefault: false, | ||
}, | ||
} | ||
if err := cli.SetupCommandParams(resolverCmd, params, viper.GetViper()); err != nil { | ||
panic(err) | ||
} | ||
rootCmd.AddCommand(resolverCmd) | ||
} | ||
|
||
func runResolverServer(cmd *cobra.Command, args []string) error { | ||
// Observability operator | ||
oop, err := otel.NewOperator([]otel.OperatorOption{ | ||
otel.WithLogger(log), | ||
otel.WithServiceName("algoid"), | ||
otel.WithServiceVersion(info.CoreVersion), | ||
otel.WithHostMetrics(), | ||
otel.WithRuntimeMetrics(5 * time.Second), | ||
}...) | ||
if err != nil { | ||
return err | ||
} | ||
defer oop.Shutdown(context.Background()) | ||
|
||
// Load settings | ||
conf := new(internal.ResolverSettings) | ||
conf.Load(viper.GetViper()) | ||
|
||
// Resolver instance | ||
conn, err := getClientConnection(conf.Client) | ||
if err != nil { | ||
return err | ||
} | ||
rr, err := conf.Resolver(conn) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Start server | ||
mux := http.NewServeMux() | ||
mux.HandleFunc("/1.0/identifiers/", rr.ResolutionHandler) | ||
srv, err := pkgHttp.NewServer(conf.ServerOpts(mux, releaseCode())...) | ||
if err != nil { | ||
return err | ||
} | ||
go func() { | ||
_ = srv.Start() | ||
}() | ||
|
||
// wait for system signals | ||
log.Info("waiting for incoming requests") | ||
<-cli.SignalsHandler([]os.Signal{ | ||
syscall.SIGHUP, | ||
syscall.SIGINT, | ||
syscall.SIGTERM, | ||
syscall.SIGQUIT, | ||
}) | ||
|
||
// stop server | ||
log.Info("preparing to exit") | ||
_ = conn.Close() // client internal API client connection | ||
return srv.Stop(true) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.