-
Notifications
You must be signed in to change notification settings - Fork 21
feat: add oasis rofl set-admin #692
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,107 @@ | ||
| package rofl | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| "github.com/spf13/cobra" | ||
|
|
||
| "github.com/oasisprotocol/oasis-sdk/client-sdk/go/connection" | ||
| "github.com/oasisprotocol/oasis-sdk/client-sdk/go/modules/rofl" | ||
|
|
||
| buildRofl "github.com/oasisprotocol/cli/build/rofl" | ||
| "github.com/oasisprotocol/cli/cmd/common" | ||
| roflCommon "github.com/oasisprotocol/cli/cmd/rofl/common" | ||
| cliConfig "github.com/oasisprotocol/cli/config" | ||
| ) | ||
|
|
||
| var setAdminCmd = &cobra.Command{ | ||
| Use: "set-admin <new-admin>", | ||
| Short: "Change the administrator of the application in ROFL", | ||
| Aliases: []string{"change-admin"}, | ||
| Args: cobra.ExactArgs(1), | ||
| Run: func(_ *cobra.Command, args []string) { | ||
| txCfg := common.GetTransactionConfig() | ||
|
|
||
| manifest, deployment, npa := roflCommon.LoadManifestAndSetNPA(&roflCommon.ManifestOptions{ | ||
| NeedAppID: true, | ||
| NeedAdmin: true, | ||
| }) | ||
|
|
||
| var appID rofl.AppID | ||
| if err := appID.UnmarshalText([]byte(deployment.AppID)); err != nil { | ||
| cobra.CheckErr(fmt.Errorf("malformed ROFL app ID: %w", err)) | ||
| } | ||
|
|
||
| npa.MustHaveAccount() | ||
| npa.MustHaveParaTime() | ||
|
|
||
| if deployment.Policy == nil { | ||
| cobra.CheckErr("no policy configured in the manifest") | ||
| } | ||
|
|
||
| oldAdminAddr, _, err := common.ResolveLocalAccountOrAddress(npa.Network, deployment.Admin) | ||
| if err != nil { | ||
| cobra.CheckErr(fmt.Errorf("bad current administrator address: %w", err)) | ||
| } | ||
|
|
||
| newAdminAddr, newAdminEthAddr, err := common.ResolveLocalAccountOrAddress(npa.Network, args[0]) | ||
| if err != nil { | ||
| cobra.CheckErr(fmt.Errorf("invalid new admin address: %w", err)) | ||
| } | ||
|
|
||
| if *oldAdminAddr == *newAdminAddr { | ||
| fmt.Println("New admin is the same as the current admin, nothing to do.") | ||
| return | ||
| } | ||
|
|
||
| // When not in offline mode, connect to the given network endpoint. | ||
| ctx := context.Background() | ||
| var conn connection.Connection | ||
| if !txCfg.Offline { | ||
| conn, err = connection.Connect(ctx, npa.Network) | ||
| cobra.CheckErr(err) | ||
| } | ||
|
|
||
| newAdminStr := newAdminAddr.String() | ||
| if newAdminEthAddr != nil { | ||
| newAdminStr = newAdminEthAddr.Hex() | ||
| } | ||
|
|
||
| fmt.Printf("App ID: %s\n", deployment.AppID) | ||
| fmt.Printf("Old admin: %s\n", common.PrettyAddress(oldAdminAddr.String())) | ||
| fmt.Printf("New admin: %s\n", common.PrettyAddress(newAdminStr)) | ||
|
|
||
| secrets := buildRofl.PrepareSecrets(deployment.Secrets) | ||
|
|
||
| tx := rofl.NewUpdateTx(nil, &rofl.Update{ | ||
| ID: appID, | ||
| Policy: *deployment.Policy.AsDescriptor(), | ||
| Admin: newAdminAddr, | ||
| Metadata: manifest.GetMetadata(roflCommon.DeploymentName), | ||
| Secrets: secrets, | ||
| }) | ||
|
|
||
| acc := common.LoadAccount(cliConfig.Global(), npa.AccountName) | ||
| sigTx, meta, err := common.SignParaTimeTransaction(ctx, npa, acc, conn, tx, nil) | ||
| cobra.CheckErr(err) | ||
|
|
||
| if !common.BroadcastOrExportTransaction(ctx, npa, conn, sigTx, meta, nil) { | ||
| return | ||
| } | ||
|
|
||
| // Transaction succeeded — update the manifest with the new admin. | ||
| deployment.Admin = args[0] | ||
| if err = manifest.Save(); err != nil { | ||
| cobra.CheckErr(fmt.Errorf("failed to update manifest: %w", err)) | ||
| } | ||
|
|
||
| fmt.Printf("ROFL admin changed to %s.\n", common.PrettyAddress(newAdminStr)) | ||
| }, | ||
| } | ||
|
|
||
| func init() { | ||
| common.AddAccountFlag(setAdminCmd) | ||
| setAdminCmd.Flags().AddFlagSet(common.RuntimeTxFlags) | ||
| setAdminCmd.Flags().AddFlagSet(roflCommon.DeploymentFlags) | ||
| } |
This file contains hidden or 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 hidden or 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 @@ | ||
| oasis rofl machine set-admin [<machine-name> | <provider-address>:<machine-id>] <new-admin> | ||
This file contains hidden or 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 @@ | ||
| oasis rofl set-admin <new-admin> | ||
uniyalabhishek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.