-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #747 from openziti/update_interstitial_config
Endpoint for Synchronzing Interstitial Configs (#744)
- Loading branch information
Showing
27 changed files
with
1,704 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/openziti/zrok/environment" | ||
"github.com/openziti/zrok/rest_client_zrok/admin" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
adminCmd.AddCommand(newAdminGrantsCommand().cmd) | ||
} | ||
|
||
type adminGrantsCommand struct { | ||
cmd *cobra.Command | ||
email string | ||
} | ||
|
||
func newAdminGrantsCommand() *adminGrantsCommand { | ||
cmd := &cobra.Command{ | ||
Use: "grants <email>", | ||
Short: "Synchronize ziti objects with account grants", | ||
Args: cobra.ExactArgs(1), | ||
} | ||
command := &adminGrantsCommand{cmd: cmd} | ||
cmd.Run = command.run | ||
cmd.Flags().StringVarP(&command.email, "email", "e", "", "email address") | ||
return command | ||
} | ||
|
||
func (command *adminGrantsCommand) run(_ *cobra.Command, args []string) { | ||
env, err := environment.LoadRoot() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
zrok, err := env.Client() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
req := admin.NewGrantsParams() | ||
req.Body.Email = args[0] | ||
|
||
_, err = zrok.Admin.Grants(req, mustGetAdminAuth()) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
fmt.Println("success.") | ||
} |
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,86 @@ | ||
package controller | ||
|
||
import ( | ||
"github.com/go-openapi/runtime/middleware" | ||
"github.com/openziti/zrok/controller/zrokEdgeSdk" | ||
"github.com/openziti/zrok/rest_model_zrok" | ||
"github.com/openziti/zrok/rest_server_zrok/operations/admin" | ||
"github.com/openziti/zrok/sdk/golang/sdk" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
type grantsHandler struct{} | ||
|
||
func newGrantsHandler() *grantsHandler { | ||
return &grantsHandler{} | ||
} | ||
|
||
func (h *grantsHandler) Handle(params admin.GrantsParams, principal *rest_model_zrok.Principal) middleware.Responder { | ||
if !principal.Admin { | ||
logrus.Errorf("invalid admin principal") | ||
return admin.NewGrantsUnauthorized() | ||
} | ||
|
||
edge, err := zrokEdgeSdk.Client(cfg.Ziti) | ||
if err != nil { | ||
logrus.Errorf("error connecting to ziti: %v", err) | ||
return admin.NewGrantsInternalServerError() | ||
} | ||
|
||
trx, err := str.Begin() | ||
if err != nil { | ||
logrus.Errorf("error starting transaction: %v", err) | ||
return admin.NewGrantsInternalServerError() | ||
} | ||
defer func() { _ = trx.Rollback() }() | ||
|
||
acct, err := str.FindAccountWithEmail(params.Body.Email, trx) | ||
if err != nil { | ||
logrus.Errorf("error finding account with email '%v': %v", params.Body.Email, err) | ||
return admin.NewGrantsNotFound() | ||
} | ||
|
||
acctSkipInterstitial, err := str.IsAccountGrantedSkipInterstitial(acct.Id, trx) | ||
if err != nil { | ||
logrus.Errorf("error checking account '%v' granted skip interstitial: %v", acct.Email, err) | ||
} | ||
|
||
envs, err := str.FindEnvironmentsForAccount(acct.Id, trx) | ||
if err != nil { | ||
logrus.Errorf("error finding environments for '%v': %v", acct.Email, err) | ||
return admin.NewGrantsInternalServerError() | ||
} | ||
|
||
for _, env := range envs { | ||
shrs, err := str.FindSharesForEnvironment(env.Id, trx) | ||
if err != nil { | ||
logrus.Errorf("error finding shares for '%v': %v", acct.Email, err) | ||
return admin.NewGrantsInternalServerError() | ||
} | ||
|
||
for _, shr := range shrs { | ||
if shr.ShareMode == string(sdk.PublicShareMode) && shr.BackendMode != string(sdk.DriveBackendMode) { | ||
cfgZId, shrCfg, err := zrokEdgeSdk.GetConfig(shr.Token, edge) | ||
if err != nil { | ||
logrus.Errorf("error getting config for share '%v': %v", shr.Token, err) | ||
return admin.NewGrantsInternalServerError() | ||
} | ||
|
||
if shrCfg.Interstitial != !acctSkipInterstitial { | ||
shrCfg.Interstitial = !acctSkipInterstitial | ||
err := zrokEdgeSdk.UpdateConfig(shr.Token, cfgZId, shrCfg, edge) | ||
if err != nil { | ||
logrus.Errorf("error updating config for '%v': %v", shr.Token, err) | ||
return admin.NewGrantsInternalServerError() | ||
} | ||
} else { | ||
logrus.Infof("skipping config update for '%v'", shr.Token) | ||
} | ||
} else { | ||
logrus.Debugf("skipping share mode %v, backend mode %v", shr.ShareMode, shr.BackendMode) | ||
} | ||
} | ||
} | ||
|
||
return admin.NewGrantsOK() | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.