-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set ups CRUD operations, leaves stubs for auth in comments. (#12)
* Set ups CRUD operations, leaves stibs for auth in comments. Signed-off-by: Andrew Holtzmann <[email protected]> * PR Feedback Signed-off-by: Andrew Holtzmann <[email protected]> * Makes supported types better, rename api/v1/record -> records Signed-off-by: Andrew Holtzmann <[email protected]> * Have the isSupported check return the ErrorUnsupportedType Signed-off-by: Andrew Holtzmann <[email protected]> * Fix comments Signed-off-by: Andrew Holtzmann <[email protected]> * Use defined errors more Signed-off-by: Andrew Holtzmann <[email protected]> Signed-off-by: Andrew Holtzmann <[email protected]>
- Loading branch information
Showing
20 changed files
with
1,110 additions
and
126 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
coverage.out | ||
.tools/ | ||
.vscode/ | ||
.vscode/ | ||
vendor/ | ||
dnscontroller | ||
crdb-data |
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,68 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/jmoiron/sqlx" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
"go.hollow.sh/toolbox/ginjwt" | ||
|
||
"go.hollow.sh/dnscontroller/internal/httpsrv" | ||
dbx "go.hollow.sh/dnscontroller/internal/x/db" | ||
flagsx "go.hollow.sh/dnscontroller/internal/x/flags" | ||
) | ||
|
||
var serveCmd = &cobra.Command{ | ||
Use: "serve", | ||
Short: "starts the dns-controller api server", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
serve(cmd.Context()) | ||
}, | ||
} | ||
|
||
func init() { | ||
root.Cmd.AddCommand(serveCmd) | ||
|
||
logger = root.Options.GetLogger() | ||
|
||
serveCmd.Flags().String("listen", "0.0.0.0:14000", "address on which to listen") | ||
flagsx.MustBindPFlag("listen", serveCmd.Flags().Lookup("listen")) | ||
|
||
serveCmd.Flags().String("db-uri", "postgresql://root@localhost:26257/dns-controller?sslmode=disable", "URI for database connection") | ||
flagsx.MustBindPFlag("db.uri", serveCmd.Flags().Lookup("db-uri")) | ||
|
||
flagsx.RegisterOIDCFlags(serveCmd) | ||
} | ||
|
||
func serve(ctx context.Context) { | ||
var db *sqlx.DB | ||
if viper.GetBool("tracing.enabled") { | ||
db = dbx.NewDBWithTracing(logger) | ||
} else { | ||
db = dbx.NewDB(logger) | ||
} | ||
|
||
logger.Infow("starting dns-controller api server", "address", viper.GetString("listen")) | ||
|
||
hs := &httpsrv.Server{ | ||
Logger: logger, | ||
Listen: viper.GetString("listen"), | ||
Debug: viper.GetBool("logging.debug"), | ||
DB: db, | ||
AuthConfig: ginjwt.AuthConfig{ | ||
Enabled: viper.GetBool("oidc.enabled"), | ||
Audience: viper.GetString("oidc.audience"), | ||
Issuer: viper.GetString("oidc.issuer"), | ||
JWKSURI: viper.GetString("oidc.jwksuri"), | ||
LogFields: viper.GetStringSlice("oidc.log"), // TODO: We don't seem to be grabbing this from config? | ||
RolesClaim: viper.GetString("oidc.claims.roles"), | ||
UsernameClaim: viper.GetString("oidc.claims.username"), | ||
}, | ||
TrustedProxies: viper.GetStringSlice("gin.trustedproxies"), | ||
} | ||
|
||
if err := hs.Run(); err != nil { | ||
logger.Fatalw("failed starting metadata server", "error", err) | ||
} | ||
} |
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
Oops, something went wrong.