Skip to content

Commit

Permalink
Add generated CLI for provisioning service to the registry tool (apig…
Browse files Browse the repository at this point in the history
…ee#570)

* Add proto for provisioning service
* Add generated code and CLI support for provisioning API.
  • Loading branch information
timburks authored May 18, 2022
1 parent 3a332c9 commit f7ebf29
Show file tree
Hide file tree
Showing 62 changed files with 2,322 additions and 79 deletions.
19 changes: 1 addition & 18 deletions cmd/registry/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,6 @@ func Command() *cobra.Command {
cmd.AddCommand(list.Command())
cmd.AddCommand(upload.Command())
cmd.AddCommand(vocabulary.Command())
cmd.AddCommand(RPCCommand())
return cmd
}

func RPCCommand() *cobra.Command {
cmd := rpc.RegistryServiceCmd
cmd.Use = "rpc"
cmd.Short = "Make direct calls to RPC methods"
cmd.Long = cmd.Short
cmd.PersistentFlags().BoolVarP(&rpc.Verbose, "verbose", "v", false, "Print verbose output")
cmd.PersistentFlags().BoolVarP(&rpc.OutputJSON, "json", "j", false, "Print JSON output")

rpc.AdminServiceCmd.Use = "admin"
rpc.AdminServiceCmd.Short = "Make direct calls to Admin RPC methods (self-hosted installations only)"
rpc.AdminServiceCmd.Long = rpc.AdminServiceCmd.Short
rpc.AdminServiceCmd.Hidden = true
cmd.AddCommand(rpc.AdminServiceCmd)

cmd.AddCommand(rpc.Command())
return cmd
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Code generated. DO NOT EDIT.

package rpc
package generated

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Code generated. DO NOT EDIT.

package rpc
package generated

import (
"bytes"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Code generated. DO NOT EDIT.

package rpc
package generated

import (
"os"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Code generated. DO NOT EDIT.

package rpc
package generated

import (
"github.com/spf13/cobra"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Code generated. DO NOT EDIT.

package rpc
package generated

import (
"github.com/spf13/cobra"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Code generated. DO NOT EDIT.

package rpc
package generated

import (
"github.com/spf13/cobra"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Code generated. DO NOT EDIT.

package rpc
package generated

import (
"github.com/spf13/cobra"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Code generated. DO NOT EDIT.

package rpc
package generated

import (
"github.com/spf13/cobra"
Expand Down
163 changes: 163 additions & 0 deletions cmd/registry/cmd/rpc/generated/create-instance.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
// Code generated. DO NOT EDIT.

package generated

import (
"github.com/spf13/cobra"

"fmt"

"github.com/golang/protobuf/jsonpb"

"os"

rpcpb "github.com/apigee/registry/rpc"
)

var CreateInstanceInput rpcpb.CreateInstanceRequest

var CreateInstanceFromFile string

var CreateInstanceFollow bool

var CreateInstancePollOperation string

func init() {
ProvisioningServiceCmd.AddCommand(CreateInstanceCmd)

CreateInstanceInput.Instance = new(rpcpb.Instance)

CreateInstanceInput.Instance.Config = new(rpcpb.Instance_Config)

CreateInstanceCmd.Flags().StringVar(&CreateInstanceInput.Parent, "parent", "", "Required. Parent resource of the Instance, of the...")

CreateInstanceCmd.Flags().StringVar(&CreateInstanceInput.InstanceId, "instance_id", "", "Required. Identifier to assign to the Instance....")

CreateInstanceCmd.Flags().StringVar(&CreateInstanceInput.Instance.Name, "instance.name", "", "Format: `projects/*/locations/*/instance`. ...")

CreateInstanceCmd.Flags().StringVar(&CreateInstanceInput.Instance.Config.CmekKeyName, "instance.config.cmek_key_name", "", "Required. The Customer Managed Encryption Key...")

CreateInstanceCmd.Flags().StringVar(&CreateInstanceFromFile, "from_file", "", "Absolute path to JSON file containing request payload")

CreateInstanceCmd.Flags().BoolVar(&CreateInstanceFollow, "follow", false, "Block until the long running operation completes")

ProvisioningServiceCmd.AddCommand(CreateInstancePollCmd)

CreateInstancePollCmd.Flags().BoolVar(&CreateInstanceFollow, "follow", false, "Block until the long running operation completes")

CreateInstancePollCmd.Flags().StringVar(&CreateInstancePollOperation, "operation", "", "Required. Operation name to poll for")

CreateInstancePollCmd.MarkFlagRequired("operation")

}

var CreateInstanceCmd = &cobra.Command{
Use: "create-instance",
Short: "Provisions instance resources for the Registry.",
Long: "Provisions instance resources for the Registry.",
PreRun: func(cmd *cobra.Command, args []string) {

if CreateInstanceFromFile == "" {

cmd.MarkFlagRequired("parent")

cmd.MarkFlagRequired("instance_id")

cmd.MarkFlagRequired("instance.config.cmek_key_name")

}

},
RunE: func(cmd *cobra.Command, args []string) (err error) {

in := os.Stdin
if CreateInstanceFromFile != "" {
in, err = os.Open(CreateInstanceFromFile)
if err != nil {
return err
}
defer in.Close()

err = jsonpb.Unmarshal(in, &CreateInstanceInput)
if err != nil {
return err
}

}

if Verbose {
printVerboseInput("Provisioning", "CreateInstance", &CreateInstanceInput)
}
resp, err := ProvisioningClient.CreateInstance(ctx, &CreateInstanceInput)
if err != nil {
return err
}

if !CreateInstanceFollow {
var s interface{}
s = resp.Name()

if OutputJSON {
d := make(map[string]string)
d["operation"] = resp.Name()
s = d
}

printMessage(s)
return err
}

result, err := resp.Wait(ctx)
if err != nil {
return err
}

if Verbose {
fmt.Print("Output: ")
}
printMessage(result)

return err
},
}

var CreateInstancePollCmd = &cobra.Command{
Use: "poll-create-instance",
Short: "Poll the status of a CreateInstanceOperation by name",
RunE: func(cmd *cobra.Command, args []string) (err error) {
op := ProvisioningClient.CreateInstanceOperation(CreateInstancePollOperation)

if CreateInstanceFollow {
resp, err := op.Wait(ctx)
if err != nil {
return err
}

if Verbose {
fmt.Print("Output: ")
}
printMessage(resp)
return err
}

resp, err := op.Poll(ctx)
if err != nil {
return err
} else if resp != nil {
if Verbose {
fmt.Print("Output: ")
}

printMessage(resp)
return
}

if op.Done() {
fmt.Println(fmt.Sprintf("Operation %s is done", op.Name()))
} else {
fmt.Println(fmt.Sprintf("Operation %s not done", op.Name()))
}

return err
},
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Code generated. DO NOT EDIT.

package rpc
package generated

import (
"github.com/spf13/cobra"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Code generated. DO NOT EDIT.

package rpc
package generated

import (
"github.com/spf13/cobra"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Code generated. DO NOT EDIT.

package rpc
package generated

import (
"github.com/spf13/cobra"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Code generated. DO NOT EDIT.

package rpc
package generated

import (
"github.com/spf13/cobra"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Code generated. DO NOT EDIT.

package rpc
package generated

import (
"github.com/spf13/cobra"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Code generated. DO NOT EDIT.

package rpc
package generated

import (
"github.com/spf13/cobra"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Code generated. DO NOT EDIT.

package rpc
package generated

import (
"github.com/spf13/cobra"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Code generated. DO NOT EDIT.

package rpc
package generated

import (
"github.com/spf13/cobra"
Expand Down
Loading

0 comments on commit f7ebf29

Please sign in to comment.