mirror of https://github.com/hashicorp/boundary
Handler project (#44)
* Renamed fakeRepo to mockRepo * Changing around TODOs to capture current plans with the code. * Remove the repo interface and use a real DB for tests. * Fixed a few tests. * Adding checks for properly formatted identifiers. * Updating code to account for recent merges. Relaxing some restrictions on what an id can look like. * Added small comment explaining why RegisterGrpcGatewayer interface exists. * Move project service up a call level. Long term I think it would make sense to define these services even higher up the call stack, potentially at the initialization of the controller server, near where the DB is initialized. * Making these fields align with those in the resources under hosts/... * Hard code the service initialization in the handler registration code. * Regenerate project related code proto code. * Removing type field for project. * Adds basic project handling in CLI/SDK (#47) * Adds SDK for creating and reading projects * Reorganizes a bit * Adds CLI for creating and reading projects * Fixes some some generation bugs * Adds redirect support for default org ID * Fix protobuf import references being moved. * Update client test to look for "orgs" and "projects" instead of "org" and "project" * Update expected segments test * Fix setAddr handling when default organization is in use * Set client in target after create or read Co-authored-by: Jim Lambert <jimlambrt@Jims-MBP-3.home> Co-authored-by: Jim <jlambert@hashicorp.com> Co-authored-by: Michael Gaffney <mgaffney@users.noreply.github.com> Co-authored-by: Jeff Mitchell <jeffrey.mitchell@gmail.com>pull/50/head
parent
8d7f24268c
commit
c0c6a9b0b8
@ -1,9 +1,8 @@
|
||||
// +build genapi
|
||||
|
||||
package main
|
||||
|
||||
func main() {
|
||||
parsePBs()
|
||||
writeStructTemplates()
|
||||
writeCreateFuncs()
|
||||
writeReadFuncs()
|
||||
}
|
||||
|
||||
@ -0,0 +1,116 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
"text/template"
|
||||
)
|
||||
|
||||
type readInfo struct {
|
||||
baseType string
|
||||
targetType string
|
||||
verb string
|
||||
path string
|
||||
}
|
||||
|
||||
var readFuncs = map[string][]*readInfo{
|
||||
"scopes": {
|
||||
{
|
||||
"Organization",
|
||||
"Project",
|
||||
"GET",
|
||||
"projects/%s",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func writeReadFuncs() {
|
||||
for outPkg, funcs := range readFuncs {
|
||||
outFile := os.Getenv("GEN_BASEPATH") + fmt.Sprintf("/api/%s/read.gen.go", outPkg)
|
||||
outBuf := bytes.NewBuffer([]byte(fmt.Sprintf(
|
||||
`// Code generated by "make api"; DO NOT EDIT.
|
||||
package %s
|
||||
`, outPkg)))
|
||||
for _, readInfo := range funcs {
|
||||
readFuncTemplate.Execute(outBuf, struct {
|
||||
BaseType string
|
||||
TargetType string
|
||||
LowerTargetType string
|
||||
Verb string
|
||||
Path string
|
||||
}{
|
||||
BaseType: readInfo.baseType,
|
||||
TargetType: readInfo.targetType,
|
||||
LowerTargetType: strings.ToLower(readInfo.targetType),
|
||||
Verb: readInfo.verb,
|
||||
Path: readInfo.path,
|
||||
})
|
||||
}
|
||||
if err := ioutil.WriteFile(outFile, outBuf.Bytes(), 0644); err != nil {
|
||||
fmt.Printf("error writing file %q: %v\n", outFile, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var readFuncTemplate = template.Must(template.New("").Parse(
|
||||
`
|
||||
func (s {{ .BaseType }}) Read{{ .TargetType }}(ctx context.Context, {{ .LowerTargetType }} *{{ .TargetType }}) (*{{ .TargetType }}, *api.Error, error) {
|
||||
if s.Client == nil {
|
||||
return nil, nil, fmt.Errorf("nil client in Read{{ .TargetType }} request")
|
||||
}
|
||||
if s.Id == "" {
|
||||
{{ if (eq .BaseType "Organization") }}
|
||||
// Assume the client has been configured with organization already and
|
||||
// move on
|
||||
{{ else if (eq .BaseType "Project") }}
|
||||
// Assume the client has been configured with project already and move
|
||||
// on
|
||||
{{ else }}
|
||||
return nil, nil, fmt.Errorf("missing {{ .BaseType }} ID in Read{{ .TargetType }} request")
|
||||
{{ end }}
|
||||
} else {
|
||||
// If it's explicitly set here, override anything that might be in the
|
||||
// client
|
||||
{{ if (eq .BaseType "Organization") }}
|
||||
ctx = context.WithValue(ctx, "org", s.Id)
|
||||
{{ else if (eq .BaseType "Project") }}
|
||||
ctx = context.WithValue(ctx, "project", s.Id)
|
||||
{{ end }}
|
||||
}
|
||||
if {{ .LowerTargetType }}.Id == "" {
|
||||
return nil, nil, fmt.Errorf("empty {{ .LowerTargetType }} ID field in Read{{ .TargetType }} request")
|
||||
}
|
||||
|
||||
req, err := s.Client.NewRequest(ctx, "{{ .Verb }}", fmt.Sprintf("{{ .Path }}", {{ .LowerTargetType }}.Id), {{ .LowerTargetType }})
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("error creating Read{{ .TargetType }} request: %w", err)
|
||||
}
|
||||
|
||||
resp, err := s.Client.Do(req)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("error performing client request during Read{{ .TargetType }} call: %w", err)
|
||||
}
|
||||
|
||||
target := new({{ .TargetType }})
|
||||
apiErr, err := resp.Decode(target)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("error decoding Read{{ .TargetType }} repsonse: %w", err)
|
||||
}
|
||||
|
||||
{{ if (eq .TargetType "Organization") }}
|
||||
target.Client = s.Client.Clone()
|
||||
target.Client.SetOrgnization(target.Id)
|
||||
{{ else if (eq .TargetType "Project") }}
|
||||
target.Client = s.Client.Clone()
|
||||
target.Client.SetProject(target.Id)
|
||||
{{ else }}
|
||||
target.Client = s.Client
|
||||
{{ end }}
|
||||
|
||||
return target, apiErr, nil
|
||||
}
|
||||
`))
|
||||
@ -0,0 +1,48 @@
|
||||
// Code generated by "make api"; DO NOT EDIT.
|
||||
package scopes
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/watchtower/api"
|
||||
)
|
||||
|
||||
func (s Organization) CreateProject(ctx context.Context, project *Project) (*Project, *api.Error, error) {
|
||||
if s.Client == nil {
|
||||
return nil, nil, fmt.Errorf("nil client in CreateProject request")
|
||||
}
|
||||
if s.Id == "" {
|
||||
|
||||
// Assume the client has been configured with organization already and
|
||||
// move on
|
||||
|
||||
} else {
|
||||
// If it's explicitly set here, override anything that might be in the
|
||||
// client
|
||||
|
||||
ctx = context.WithValue(ctx, "org", s.Id)
|
||||
|
||||
}
|
||||
|
||||
req, err := s.Client.NewRequest(ctx, "POST", "projects", project)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("error creating CreateProject request: %w", err)
|
||||
}
|
||||
|
||||
resp, err := s.Client.Do(req)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("error performing client request during CreateProject call: %w", err)
|
||||
}
|
||||
|
||||
target := new(Project)
|
||||
apiErr, err := resp.Decode(target)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("error decoding CreateProject repsonse: %w", err)
|
||||
}
|
||||
|
||||
target.Client = s.Client.Clone()
|
||||
target.Client.SetProject(target.Id)
|
||||
|
||||
return target, apiErr, nil
|
||||
}
|
||||
@ -0,0 +1,51 @@
|
||||
// Code generated by "make api"; DO NOT EDIT.
|
||||
package scopes
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
"github.com/fatih/structs"
|
||||
|
||||
"github.com/hashicorp/watchtower/api"
|
||||
"github.com/hashicorp/watchtower/api/internal/strutil"
|
||||
)
|
||||
|
||||
type Organization struct {
|
||||
Client *api.Client `json:"-"`
|
||||
|
||||
defaultFields []string
|
||||
|
||||
// The ID of the Organization
|
||||
// Output only.
|
||||
Id string `json:"id,omitempty"`
|
||||
// Optional name for identification purposes
|
||||
Name *string `json:"name,omitempty"`
|
||||
// Optional user-set descripton for identification purposes
|
||||
Description *string `json:"description,omitempty"`
|
||||
// The time this resource was created
|
||||
// Output only.
|
||||
CreatedTime time.Time `json:"created_time,omitempty"`
|
||||
// The time this resource was last updated.
|
||||
// Output only.
|
||||
UpdatedTime time.Time `json:"updated_time,omitempty"`
|
||||
}
|
||||
|
||||
func (s *Organization) SetDefault(key string) {
|
||||
s.defaultFields = strutil.AppendIfMissing(s.defaultFields, key)
|
||||
}
|
||||
|
||||
func (s *Organization) UnsetDefault(key string) {
|
||||
s.defaultFields = strutil.StrListDelete(s.defaultFields, key)
|
||||
}
|
||||
|
||||
func (s Organization) MarshalJSON() ([]byte, error) {
|
||||
m := structs.Map(s)
|
||||
if m == nil {
|
||||
m = make(map[string]interface{})
|
||||
}
|
||||
for _, k := range s.defaultFields {
|
||||
m[k] = nil
|
||||
}
|
||||
return json.Marshal(m)
|
||||
}
|
||||
@ -0,0 +1,53 @@
|
||||
// Code generated by "make api"; DO NOT EDIT.
|
||||
package scopes
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
"github.com/fatih/structs"
|
||||
|
||||
"github.com/hashicorp/watchtower/api"
|
||||
"github.com/hashicorp/watchtower/api/internal/strutil"
|
||||
)
|
||||
|
||||
type Project struct {
|
||||
Client *api.Client `json:"-"`
|
||||
|
||||
defaultFields []string
|
||||
|
||||
// The ID of the Project
|
||||
// Output only.
|
||||
Id string `json:"id,omitempty"`
|
||||
// Optional name for identification purposes
|
||||
Name *string `json:"name,omitempty"`
|
||||
// Optional user-set descripton for identification purposes
|
||||
Description *string `json:"description,omitempty"`
|
||||
// The time this resource was created
|
||||
// Output only.
|
||||
CreatedTime time.Time `json:"created_time,omitempty"`
|
||||
// The time this resource was last updated.
|
||||
// Output only.
|
||||
UpdatedTime time.Time `json:"updated_time,omitempty"`
|
||||
// Whether the resource is disabled
|
||||
Disabled *bool `json:"disabled,omitempty"`
|
||||
}
|
||||
|
||||
func (s *Project) SetDefault(key string) {
|
||||
s.defaultFields = strutil.AppendIfMissing(s.defaultFields, key)
|
||||
}
|
||||
|
||||
func (s *Project) UnsetDefault(key string) {
|
||||
s.defaultFields = strutil.StrListDelete(s.defaultFields, key)
|
||||
}
|
||||
|
||||
func (s Project) MarshalJSON() ([]byte, error) {
|
||||
m := structs.Map(s)
|
||||
if m == nil {
|
||||
m = make(map[string]interface{})
|
||||
}
|
||||
for _, k := range s.defaultFields {
|
||||
m[k] = nil
|
||||
}
|
||||
return json.Marshal(m)
|
||||
}
|
||||
@ -0,0 +1,51 @@
|
||||
// Code generated by "make api"; DO NOT EDIT.
|
||||
package scopes
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/watchtower/api"
|
||||
)
|
||||
|
||||
func (s Organization) ReadProject(ctx context.Context, project *Project) (*Project, *api.Error, error) {
|
||||
if s.Client == nil {
|
||||
return nil, nil, fmt.Errorf("nil client in ReadProject request")
|
||||
}
|
||||
if s.Id == "" {
|
||||
|
||||
// Assume the client has been configured with organization already and
|
||||
// move on
|
||||
|
||||
} else {
|
||||
// If it's explicitly set here, override anything that might be in the
|
||||
// client
|
||||
|
||||
ctx = context.WithValue(ctx, "org", s.Id)
|
||||
|
||||
}
|
||||
if project.Id == "" {
|
||||
return nil, nil, fmt.Errorf("empty project ID field in ReadProject request")
|
||||
}
|
||||
|
||||
req, err := s.Client.NewRequest(ctx, "GET", fmt.Sprintf("projects/%s", project.Id), project)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("error creating ReadProject request: %w", err)
|
||||
}
|
||||
|
||||
resp, err := s.Client.Do(req)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("error performing client request during ReadProject call: %w", err)
|
||||
}
|
||||
|
||||
target := new(Project)
|
||||
apiErr, err := resp.Decode(target)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("error decoding ReadProject repsonse: %w", err)
|
||||
}
|
||||
|
||||
target.Client = s.Client.Clone()
|
||||
target.Client.SetProject(target.Id)
|
||||
|
||||
return target, apiErr, nil
|
||||
}
|
||||
@ -0,0 +1,113 @@
|
||||
package scopes
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/watchtower/api"
|
||||
"github.com/hashicorp/watchtower/api/scopes"
|
||||
"github.com/hashicorp/watchtower/internal/cmd/base"
|
||||
"github.com/kr/pretty"
|
||||
"github.com/mitchellh/cli"
|
||||
"github.com/posener/complete"
|
||||
)
|
||||
|
||||
var _ cli.Command = (*CreateProjectCommand)(nil)
|
||||
var _ cli.CommandAutocomplete = (*CreateProjectCommand)(nil)
|
||||
|
||||
type CreateProjectCommand struct {
|
||||
*base.Command
|
||||
|
||||
flagName string
|
||||
flagDescription string
|
||||
}
|
||||
|
||||
func (c *CreateProjectCommand) Synopsis() string {
|
||||
return "Creates a project within an organization"
|
||||
}
|
||||
|
||||
func (c *CreateProjectCommand) Help() string {
|
||||
helpText := `
|
||||
Usage: watchtower projects create
|
||||
|
||||
Creates a project within the organization specified by the ID from the
|
||||
"org-id" parameter or the associated environment variable.
|
||||
|
||||
Example:
|
||||
|
||||
$ watchtower projects create -org=<org_id> -name=<name>
|
||||
|
||||
` + c.Flags().Help()
|
||||
|
||||
return strings.TrimSpace(helpText)
|
||||
}
|
||||
|
||||
func (c *CreateProjectCommand) Flags() *base.FlagSets {
|
||||
set := c.FlagSet(base.FlagSetHTTP | base.FlagSetOutputFormat)
|
||||
|
||||
f := set.NewFlagSet("Command Options")
|
||||
|
||||
f.StringVar(&base.StringVar{
|
||||
Name: "name",
|
||||
Target: &c.flagName,
|
||||
Completion: complete.PredictAnything,
|
||||
Usage: "An optional name assigned to the project for display purposes",
|
||||
})
|
||||
|
||||
f.StringVar(&base.StringVar{
|
||||
Name: "description",
|
||||
Target: &c.flagDescription,
|
||||
Completion: complete.PredictNothing,
|
||||
Usage: "An optional description assigned to the project for display purposes",
|
||||
})
|
||||
|
||||
return set
|
||||
}
|
||||
|
||||
func (c *CreateProjectCommand) AutocompleteArgs() complete.Predictor {
|
||||
return complete.PredictAnything
|
||||
}
|
||||
|
||||
func (c *CreateProjectCommand) AutocompleteFlags() complete.Flags {
|
||||
return c.Flags().Completions()
|
||||
}
|
||||
|
||||
func (c *CreateProjectCommand) Run(args []string) int {
|
||||
f := c.Flags()
|
||||
|
||||
if err := f.Parse(args); err != nil {
|
||||
c.UI.Error(err.Error())
|
||||
return 1
|
||||
}
|
||||
|
||||
client, err := c.Client()
|
||||
if err != nil {
|
||||
c.UI.Error(err.Error())
|
||||
return 2
|
||||
}
|
||||
|
||||
org := &scopes.Organization{
|
||||
Client: client,
|
||||
}
|
||||
|
||||
project := &scopes.Project{
|
||||
Name: api.StringOrNil(c.flagName),
|
||||
Description: api.StringOrNil(c.flagDescription),
|
||||
}
|
||||
|
||||
var apiErr *api.Error
|
||||
project, apiErr, err = org.CreateProject(c.Context, project)
|
||||
|
||||
switch {
|
||||
case err != nil:
|
||||
c.UI.Error(fmt.Errorf("error creating project: %w", err).Error())
|
||||
return 2
|
||||
case apiErr != nil:
|
||||
c.UI.Error(pretty.Sprint(apiErr))
|
||||
return 2
|
||||
default:
|
||||
c.UI.Info(pretty.Sprint(project))
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
@ -0,0 +1,105 @@
|
||||
package scopes
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/watchtower/api"
|
||||
"github.com/hashicorp/watchtower/api/scopes"
|
||||
"github.com/hashicorp/watchtower/internal/cmd/base"
|
||||
"github.com/kr/pretty"
|
||||
"github.com/mitchellh/cli"
|
||||
"github.com/posener/complete"
|
||||
)
|
||||
|
||||
var _ cli.Command = (*ReadProjectCommand)(nil)
|
||||
var _ cli.CommandAutocomplete = (*ReadProjectCommand)(nil)
|
||||
|
||||
type ReadProjectCommand struct {
|
||||
*base.Command
|
||||
|
||||
flagId string
|
||||
}
|
||||
|
||||
func (c *ReadProjectCommand) Synopsis() string {
|
||||
return "Reads a project's data"
|
||||
}
|
||||
|
||||
func (c *ReadProjectCommand) Help() string {
|
||||
helpText := `
|
||||
Usage: watchtower projects read
|
||||
|
||||
Returns information about a project specified by the ID. It is an error if
|
||||
the project is not within the organization specified via the "org-id"
|
||||
parameter or the associated environment variable.
|
||||
|
||||
Example:
|
||||
|
||||
$ watchtower projects read -org=<org_id> -id=<project_id>
|
||||
|
||||
` + c.Flags().Help()
|
||||
|
||||
return strings.TrimSpace(helpText)
|
||||
}
|
||||
|
||||
func (c *ReadProjectCommand) Flags() *base.FlagSets {
|
||||
set := c.FlagSet(base.FlagSetHTTP | base.FlagSetOutputFormat)
|
||||
|
||||
f := set.NewFlagSet("Command Options")
|
||||
|
||||
f.StringVar(&base.StringVar{
|
||||
Name: "id",
|
||||
Target: &c.flagId,
|
||||
Completion: complete.PredictNothing,
|
||||
Usage: "The ID of the project to read",
|
||||
})
|
||||
|
||||
return set
|
||||
}
|
||||
|
||||
func (c *ReadProjectCommand) AutocompleteArgs() complete.Predictor {
|
||||
return complete.PredictAnything
|
||||
}
|
||||
|
||||
func (c *ReadProjectCommand) AutocompleteFlags() complete.Flags {
|
||||
return c.Flags().Completions()
|
||||
}
|
||||
|
||||
func (c *ReadProjectCommand) Run(args []string) int {
|
||||
f := c.Flags()
|
||||
|
||||
if err := f.Parse(args); err != nil {
|
||||
c.UI.Error(err.Error())
|
||||
return 1
|
||||
}
|
||||
|
||||
client, err := c.Client()
|
||||
if err != nil {
|
||||
c.UI.Error(err.Error())
|
||||
return 2
|
||||
}
|
||||
|
||||
org := &scopes.Organization{
|
||||
Client: client,
|
||||
}
|
||||
|
||||
project := &scopes.Project{
|
||||
Id: c.flagId,
|
||||
}
|
||||
|
||||
var apiErr *api.Error
|
||||
project, apiErr, err = org.ReadProject(c.Context, project)
|
||||
|
||||
switch {
|
||||
case err != nil:
|
||||
c.UI.Error(fmt.Errorf("error reading project: %w", err).Error())
|
||||
return 2
|
||||
case apiErr != nil:
|
||||
c.UI.Error(pretty.Sprint(apiErr))
|
||||
return 2
|
||||
default:
|
||||
c.UI.Info(pretty.Sprint(project))
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
@ -0,0 +1,223 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.21.0
|
||||
// protoc v3.11.4
|
||||
// source: controller/api/resources/scopes/v1/organization.proto
|
||||
|
||||
package scopes
|
||||
|
||||
import (
|
||||
proto "github.com/golang/protobuf/proto"
|
||||
timestamp "github.com/golang/protobuf/ptypes/timestamp"
|
||||
wrappers "github.com/golang/protobuf/ptypes/wrappers"
|
||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||
reflect "reflect"
|
||||
sync "sync"
|
||||
)
|
||||
|
||||
const (
|
||||
// Verify that this generated code is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
|
||||
// Verify that runtime/protoimpl is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
|
||||
)
|
||||
|
||||
// This is a compile-time assertion that a sufficiently up-to-date version
|
||||
// of the legacy proto package is being used.
|
||||
const _ = proto.ProtoPackageIsVersion4
|
||||
|
||||
// Organization contains all fields related to an Organization resource
|
||||
type Organization struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
// The ID of the Organization
|
||||
// Output only.
|
||||
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||
// Optional name for identification purposes
|
||||
Name *wrappers.StringValue `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
|
||||
// Optional user-set descripton for identification purposes
|
||||
Description *wrappers.StringValue `protobuf:"bytes,3,opt,name=description,proto3" json:"description,omitempty"`
|
||||
// The time this resource was created
|
||||
// Output only.
|
||||
CreatedTime *timestamp.Timestamp `protobuf:"bytes,4,opt,name=created_time,proto3" json:"created_time,omitempty"`
|
||||
// The time this resource was last updated.
|
||||
// Output only.
|
||||
UpdatedTime *timestamp.Timestamp `protobuf:"bytes,5,opt,name=updated_time,proto3" json:"updated_time,omitempty"`
|
||||
}
|
||||
|
||||
func (x *Organization) Reset() {
|
||||
*x = Organization{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_controller_api_resources_scopes_v1_organization_proto_msgTypes[0]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *Organization) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*Organization) ProtoMessage() {}
|
||||
|
||||
func (x *Organization) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_controller_api_resources_scopes_v1_organization_proto_msgTypes[0]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use Organization.ProtoReflect.Descriptor instead.
|
||||
func (*Organization) Descriptor() ([]byte, []int) {
|
||||
return file_controller_api_resources_scopes_v1_organization_proto_rawDescGZIP(), []int{0}
|
||||
}
|
||||
|
||||
func (x *Organization) GetId() string {
|
||||
if x != nil {
|
||||
return x.Id
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *Organization) GetName() *wrappers.StringValue {
|
||||
if x != nil {
|
||||
return x.Name
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *Organization) GetDescription() *wrappers.StringValue {
|
||||
if x != nil {
|
||||
return x.Description
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *Organization) GetCreatedTime() *timestamp.Timestamp {
|
||||
if x != nil {
|
||||
return x.CreatedTime
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *Organization) GetUpdatedTime() *timestamp.Timestamp {
|
||||
if x != nil {
|
||||
return x.UpdatedTime
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var File_controller_api_resources_scopes_v1_organization_proto protoreflect.FileDescriptor
|
||||
|
||||
var file_controller_api_resources_scopes_v1_organization_proto_rawDesc = []byte{
|
||||
0x0a, 0x35, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2f, 0x61, 0x70, 0x69,
|
||||
0x2f, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x73, 0x2f, 0x73, 0x63, 0x6f, 0x70, 0x65,
|
||||
0x73, 0x2f, 0x76, 0x31, 0x2f, 0x6f, 0x72, 0x67, 0x61, 0x6e, 0x69, 0x7a, 0x61, 0x74, 0x69, 0x6f,
|
||||
0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x22, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c,
|
||||
0x6c, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65,
|
||||
0x73, 0x2e, 0x73, 0x63, 0x6f, 0x70, 0x65, 0x73, 0x2e, 0x76, 0x31, 0x1a, 0x1f, 0x67, 0x6f, 0x6f,
|
||||
0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x74, 0x69, 0x6d,
|
||||
0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1e, 0x67, 0x6f,
|
||||
0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x77, 0x72,
|
||||
0x61, 0x70, 0x70, 0x65, 0x72, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x90, 0x02, 0x0a,
|
||||
0x0c, 0x4f, 0x72, 0x67, 0x61, 0x6e, 0x69, 0x7a, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x0e, 0x0a,
|
||||
0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x30, 0x0a,
|
||||
0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x67, 0x6f,
|
||||
0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74,
|
||||
0x72, 0x69, 0x6e, 0x67, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12,
|
||||
0x3e, 0x0a, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x03,
|
||||
0x20, 0x01, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72,
|
||||
0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x56, 0x61, 0x6c,
|
||||
0x75, 0x65, 0x52, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12,
|
||||
0x3e, 0x0a, 0x0c, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18,
|
||||
0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70,
|
||||
0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d,
|
||||
0x70, 0x52, 0x0c, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x12,
|
||||
0x3e, 0x0a, 0x0c, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18,
|
||||
0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70,
|
||||
0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d,
|
||||
0x70, 0x52, 0x0c, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x42,
|
||||
0x55, 0x5a, 0x53, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x68, 0x61,
|
||||
0x73, 0x68, 0x69, 0x63, 0x6f, 0x72, 0x70, 0x2f, 0x77, 0x61, 0x74, 0x63, 0x68, 0x74, 0x6f, 0x77,
|
||||
0x65, 0x72, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x67, 0x65, 0x6e, 0x2f,
|
||||
0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x72,
|
||||
0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x73, 0x2f, 0x73, 0x63, 0x6f, 0x70, 0x65, 0x73, 0x3b,
|
||||
0x73, 0x63, 0x6f, 0x70, 0x65, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
file_controller_api_resources_scopes_v1_organization_proto_rawDescOnce sync.Once
|
||||
file_controller_api_resources_scopes_v1_organization_proto_rawDescData = file_controller_api_resources_scopes_v1_organization_proto_rawDesc
|
||||
)
|
||||
|
||||
func file_controller_api_resources_scopes_v1_organization_proto_rawDescGZIP() []byte {
|
||||
file_controller_api_resources_scopes_v1_organization_proto_rawDescOnce.Do(func() {
|
||||
file_controller_api_resources_scopes_v1_organization_proto_rawDescData = protoimpl.X.CompressGZIP(file_controller_api_resources_scopes_v1_organization_proto_rawDescData)
|
||||
})
|
||||
return file_controller_api_resources_scopes_v1_organization_proto_rawDescData
|
||||
}
|
||||
|
||||
var file_controller_api_resources_scopes_v1_organization_proto_msgTypes = make([]protoimpl.MessageInfo, 1)
|
||||
var file_controller_api_resources_scopes_v1_organization_proto_goTypes = []interface{}{
|
||||
(*Organization)(nil), // 0: controller.api.resources.scopes.v1.Organization
|
||||
(*wrappers.StringValue)(nil), // 1: google.protobuf.StringValue
|
||||
(*timestamp.Timestamp)(nil), // 2: google.protobuf.Timestamp
|
||||
}
|
||||
var file_controller_api_resources_scopes_v1_organization_proto_depIdxs = []int32{
|
||||
1, // 0: controller.api.resources.scopes.v1.Organization.name:type_name -> google.protobuf.StringValue
|
||||
1, // 1: controller.api.resources.scopes.v1.Organization.description:type_name -> google.protobuf.StringValue
|
||||
2, // 2: controller.api.resources.scopes.v1.Organization.created_time:type_name -> google.protobuf.Timestamp
|
||||
2, // 3: controller.api.resources.scopes.v1.Organization.updated_time:type_name -> google.protobuf.Timestamp
|
||||
4, // [4:4] is the sub-list for method output_type
|
||||
4, // [4:4] is the sub-list for method input_type
|
||||
4, // [4:4] is the sub-list for extension type_name
|
||||
4, // [4:4] is the sub-list for extension extendee
|
||||
0, // [0:4] is the sub-list for field type_name
|
||||
}
|
||||
|
||||
func init() { file_controller_api_resources_scopes_v1_organization_proto_init() }
|
||||
func file_controller_api_resources_scopes_v1_organization_proto_init() {
|
||||
if File_controller_api_resources_scopes_v1_organization_proto != nil {
|
||||
return
|
||||
}
|
||||
if !protoimpl.UnsafeEnabled {
|
||||
file_controller_api_resources_scopes_v1_organization_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*Organization); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
type x struct{}
|
||||
out := protoimpl.TypeBuilder{
|
||||
File: protoimpl.DescBuilder{
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: file_controller_api_resources_scopes_v1_organization_proto_rawDesc,
|
||||
NumEnums: 0,
|
||||
NumMessages: 1,
|
||||
NumExtensions: 0,
|
||||
NumServices: 0,
|
||||
},
|
||||
GoTypes: file_controller_api_resources_scopes_v1_organization_proto_goTypes,
|
||||
DependencyIndexes: file_controller_api_resources_scopes_v1_organization_proto_depIdxs,
|
||||
MessageInfos: file_controller_api_resources_scopes_v1_organization_proto_msgTypes,
|
||||
}.Build()
|
||||
File_controller_api_resources_scopes_v1_organization_proto = out.File
|
||||
file_controller_api_resources_scopes_v1_organization_proto_rawDesc = nil
|
||||
file_controller_api_resources_scopes_v1_organization_proto_goTypes = nil
|
||||
file_controller_api_resources_scopes_v1_organization_proto_depIdxs = nil
|
||||
}
|
||||
@ -0,0 +1,237 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.21.0
|
||||
// protoc v3.11.4
|
||||
// source: controller/api/resources/scopes/v1/project.proto
|
||||
|
||||
package scopes
|
||||
|
||||
import (
|
||||
proto "github.com/golang/protobuf/proto"
|
||||
timestamp "github.com/golang/protobuf/ptypes/timestamp"
|
||||
wrappers "github.com/golang/protobuf/ptypes/wrappers"
|
||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||
reflect "reflect"
|
||||
sync "sync"
|
||||
)
|
||||
|
||||
const (
|
||||
// Verify that this generated code is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
|
||||
// Verify that runtime/protoimpl is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
|
||||
)
|
||||
|
||||
// This is a compile-time assertion that a sufficiently up-to-date version
|
||||
// of the legacy proto package is being used.
|
||||
const _ = proto.ProtoPackageIsVersion4
|
||||
|
||||
// Project contains all fields related to a Project resource
|
||||
type Project struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
// The ID of the Project
|
||||
// Output only.
|
||||
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||
// Optional name for identification purposes
|
||||
Name *wrappers.StringValue `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
|
||||
// Optional user-set descripton for identification purposes
|
||||
Description *wrappers.StringValue `protobuf:"bytes,3,opt,name=description,proto3" json:"description,omitempty"`
|
||||
// The time this resource was created
|
||||
// Output only.
|
||||
CreatedTime *timestamp.Timestamp `protobuf:"bytes,4,opt,name=created_time,proto3" json:"created_time,omitempty"`
|
||||
// The time this resource was last updated.
|
||||
// Output only.
|
||||
UpdatedTime *timestamp.Timestamp `protobuf:"bytes,5,opt,name=updated_time,proto3" json:"updated_time,omitempty"`
|
||||
// Whether the resource is disabled
|
||||
Disabled *wrappers.BoolValue `protobuf:"bytes,6,opt,name=disabled,proto3" json:"disabled,omitempty"`
|
||||
}
|
||||
|
||||
func (x *Project) Reset() {
|
||||
*x = Project{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_controller_api_resources_scopes_v1_project_proto_msgTypes[0]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *Project) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*Project) ProtoMessage() {}
|
||||
|
||||
func (x *Project) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_controller_api_resources_scopes_v1_project_proto_msgTypes[0]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use Project.ProtoReflect.Descriptor instead.
|
||||
func (*Project) Descriptor() ([]byte, []int) {
|
||||
return file_controller_api_resources_scopes_v1_project_proto_rawDescGZIP(), []int{0}
|
||||
}
|
||||
|
||||
func (x *Project) GetId() string {
|
||||
if x != nil {
|
||||
return x.Id
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *Project) GetName() *wrappers.StringValue {
|
||||
if x != nil {
|
||||
return x.Name
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *Project) GetDescription() *wrappers.StringValue {
|
||||
if x != nil {
|
||||
return x.Description
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *Project) GetCreatedTime() *timestamp.Timestamp {
|
||||
if x != nil {
|
||||
return x.CreatedTime
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *Project) GetUpdatedTime() *timestamp.Timestamp {
|
||||
if x != nil {
|
||||
return x.UpdatedTime
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *Project) GetDisabled() *wrappers.BoolValue {
|
||||
if x != nil {
|
||||
return x.Disabled
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var File_controller_api_resources_scopes_v1_project_proto protoreflect.FileDescriptor
|
||||
|
||||
var file_controller_api_resources_scopes_v1_project_proto_rawDesc = []byte{
|
||||
0x0a, 0x30, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2f, 0x61, 0x70, 0x69,
|
||||
0x2f, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x73, 0x2f, 0x73, 0x63, 0x6f, 0x70, 0x65,
|
||||
0x73, 0x2f, 0x76, 0x31, 0x2f, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x2e, 0x70, 0x72, 0x6f,
|
||||
0x74, 0x6f, 0x12, 0x22, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2e, 0x61,
|
||||
0x70, 0x69, 0x2e, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x73, 0x2e, 0x73, 0x63, 0x6f,
|
||||
0x70, 0x65, 0x73, 0x2e, 0x76, 0x31, 0x1a, 0x1f, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70,
|
||||
0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d,
|
||||
0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f,
|
||||
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x77, 0x72, 0x61, 0x70, 0x70, 0x65, 0x72,
|
||||
0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xc3, 0x02, 0x0a, 0x07, 0x50, 0x72, 0x6f, 0x6a,
|
||||
0x65, 0x63, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52,
|
||||
0x02, 0x69, 0x64, 0x12, 0x30, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28,
|
||||
0x0b, 0x32, 0x1c, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f,
|
||||
0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x52,
|
||||
0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x3e, 0x0a, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70,
|
||||
0x74, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x67, 0x6f, 0x6f,
|
||||
0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72,
|
||||
0x69, 0x6e, 0x67, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x52, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69,
|
||||
0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x3e, 0x0a, 0x0c, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64,
|
||||
0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f,
|
||||
0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69,
|
||||
0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x0c, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64,
|
||||
0x5f, 0x74, 0x69, 0x6d, 0x65, 0x12, 0x3e, 0x0a, 0x0c, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64,
|
||||
0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f,
|
||||
0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69,
|
||||
0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x0c, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64,
|
||||
0x5f, 0x74, 0x69, 0x6d, 0x65, 0x12, 0x36, 0x0a, 0x08, 0x64, 0x69, 0x73, 0x61, 0x62, 0x6c, 0x65,
|
||||
0x64, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65,
|
||||
0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x42, 0x6f, 0x6f, 0x6c, 0x56, 0x61,
|
||||
0x6c, 0x75, 0x65, 0x52, 0x08, 0x64, 0x69, 0x73, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x42, 0x55, 0x5a,
|
||||
0x53, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x68, 0x61, 0x73, 0x68,
|
||||
0x69, 0x63, 0x6f, 0x72, 0x70, 0x2f, 0x77, 0x61, 0x74, 0x63, 0x68, 0x74, 0x6f, 0x77, 0x65, 0x72,
|
||||
0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x67, 0x65, 0x6e, 0x2f, 0x63, 0x6f,
|
||||
0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x72, 0x65, 0x73,
|
||||
0x6f, 0x75, 0x72, 0x63, 0x65, 0x73, 0x2f, 0x73, 0x63, 0x6f, 0x70, 0x65, 0x73, 0x3b, 0x73, 0x63,
|
||||
0x6f, 0x70, 0x65, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
file_controller_api_resources_scopes_v1_project_proto_rawDescOnce sync.Once
|
||||
file_controller_api_resources_scopes_v1_project_proto_rawDescData = file_controller_api_resources_scopes_v1_project_proto_rawDesc
|
||||
)
|
||||
|
||||
func file_controller_api_resources_scopes_v1_project_proto_rawDescGZIP() []byte {
|
||||
file_controller_api_resources_scopes_v1_project_proto_rawDescOnce.Do(func() {
|
||||
file_controller_api_resources_scopes_v1_project_proto_rawDescData = protoimpl.X.CompressGZIP(file_controller_api_resources_scopes_v1_project_proto_rawDescData)
|
||||
})
|
||||
return file_controller_api_resources_scopes_v1_project_proto_rawDescData
|
||||
}
|
||||
|
||||
var file_controller_api_resources_scopes_v1_project_proto_msgTypes = make([]protoimpl.MessageInfo, 1)
|
||||
var file_controller_api_resources_scopes_v1_project_proto_goTypes = []interface{}{
|
||||
(*Project)(nil), // 0: controller.api.resources.scopes.v1.Project
|
||||
(*wrappers.StringValue)(nil), // 1: google.protobuf.StringValue
|
||||
(*timestamp.Timestamp)(nil), // 2: google.protobuf.Timestamp
|
||||
(*wrappers.BoolValue)(nil), // 3: google.protobuf.BoolValue
|
||||
}
|
||||
var file_controller_api_resources_scopes_v1_project_proto_depIdxs = []int32{
|
||||
1, // 0: controller.api.resources.scopes.v1.Project.name:type_name -> google.protobuf.StringValue
|
||||
1, // 1: controller.api.resources.scopes.v1.Project.description:type_name -> google.protobuf.StringValue
|
||||
2, // 2: controller.api.resources.scopes.v1.Project.created_time:type_name -> google.protobuf.Timestamp
|
||||
2, // 3: controller.api.resources.scopes.v1.Project.updated_time:type_name -> google.protobuf.Timestamp
|
||||
3, // 4: controller.api.resources.scopes.v1.Project.disabled:type_name -> google.protobuf.BoolValue
|
||||
5, // [5:5] is the sub-list for method output_type
|
||||
5, // [5:5] is the sub-list for method input_type
|
||||
5, // [5:5] is the sub-list for extension type_name
|
||||
5, // [5:5] is the sub-list for extension extendee
|
||||
0, // [0:5] is the sub-list for field type_name
|
||||
}
|
||||
|
||||
func init() { file_controller_api_resources_scopes_v1_project_proto_init() }
|
||||
func file_controller_api_resources_scopes_v1_project_proto_init() {
|
||||
if File_controller_api_resources_scopes_v1_project_proto != nil {
|
||||
return
|
||||
}
|
||||
if !protoimpl.UnsafeEnabled {
|
||||
file_controller_api_resources_scopes_v1_project_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*Project); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
type x struct{}
|
||||
out := protoimpl.TypeBuilder{
|
||||
File: protoimpl.DescBuilder{
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: file_controller_api_resources_scopes_v1_project_proto_rawDesc,
|
||||
NumEnums: 0,
|
||||
NumMessages: 1,
|
||||
NumExtensions: 0,
|
||||
NumServices: 0,
|
||||
},
|
||||
GoTypes: file_controller_api_resources_scopes_v1_project_proto_goTypes,
|
||||
DependencyIndexes: file_controller_api_resources_scopes_v1_project_proto_depIdxs,
|
||||
MessageInfos: file_controller_api_resources_scopes_v1_project_proto_msgTypes,
|
||||
}.Build()
|
||||
File_controller_api_resources_scopes_v1_project_proto = out.File
|
||||
file_controller_api_resources_scopes_v1_project_proto_rawDesc = nil
|
||||
file_controller_api_resources_scopes_v1_project_proto_goTypes = nil
|
||||
file_controller_api_resources_scopes_v1_project_proto_depIdxs = nil
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,761 @@
|
||||
// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT.
|
||||
// source: controller/api/services/v1/project_service.proto
|
||||
|
||||
/*
|
||||
Package services is a reverse proxy.
|
||||
|
||||
It translates gRPC into RESTful JSON APIs.
|
||||
*/
|
||||
package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/golang/protobuf/descriptor"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||
"github.com/grpc-ecosystem/grpc-gateway/utilities"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/grpclog"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
// Suppress "imported and not used" errors
|
||||
var _ codes.Code
|
||||
var _ io.Reader
|
||||
var _ status.Status
|
||||
var _ = runtime.String
|
||||
var _ = utilities.NewDoubleArray
|
||||
var _ = descriptor.ForMessage
|
||||
|
||||
var (
|
||||
filter_ProjectService_GetProject_0 = &utilities.DoubleArray{Encoding: map[string]int{"org_id": 0, "id": 1}, Base: []int{1, 1, 2, 0, 0}, Check: []int{0, 1, 1, 2, 3}}
|
||||
)
|
||||
|
||||
func request_ProjectService_GetProject_0(ctx context.Context, marshaler runtime.Marshaler, client ProjectServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq GetProjectRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
var (
|
||||
val string
|
||||
ok bool
|
||||
err error
|
||||
_ = err
|
||||
)
|
||||
|
||||
val, ok = pathParams["org_id"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "org_id")
|
||||
}
|
||||
|
||||
protoReq.OrgId, err = runtime.String(val)
|
||||
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "org_id", err)
|
||||
}
|
||||
|
||||
val, ok = pathParams["id"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id")
|
||||
}
|
||||
|
||||
protoReq.Id, err = runtime.String(val)
|
||||
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err)
|
||||
}
|
||||
|
||||
if err := req.ParseForm(); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_ProjectService_GetProject_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := client.GetProject(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_ProjectService_GetProject_0(ctx context.Context, marshaler runtime.Marshaler, server ProjectServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq GetProjectRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
var (
|
||||
val string
|
||||
ok bool
|
||||
err error
|
||||
_ = err
|
||||
)
|
||||
|
||||
val, ok = pathParams["org_id"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "org_id")
|
||||
}
|
||||
|
||||
protoReq.OrgId, err = runtime.String(val)
|
||||
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "org_id", err)
|
||||
}
|
||||
|
||||
val, ok = pathParams["id"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id")
|
||||
}
|
||||
|
||||
protoReq.Id, err = runtime.String(val)
|
||||
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err)
|
||||
}
|
||||
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.URL.Query(), filter_ProjectService_GetProject_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := server.GetProject(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
var (
|
||||
filter_ProjectService_ListProjects_0 = &utilities.DoubleArray{Encoding: map[string]int{"org_id": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}}
|
||||
)
|
||||
|
||||
func request_ProjectService_ListProjects_0(ctx context.Context, marshaler runtime.Marshaler, client ProjectServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq ListProjectsRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
var (
|
||||
val string
|
||||
ok bool
|
||||
err error
|
||||
_ = err
|
||||
)
|
||||
|
||||
val, ok = pathParams["org_id"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "org_id")
|
||||
}
|
||||
|
||||
protoReq.OrgId, err = runtime.String(val)
|
||||
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "org_id", err)
|
||||
}
|
||||
|
||||
if err := req.ParseForm(); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_ProjectService_ListProjects_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := client.ListProjects(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_ProjectService_ListProjects_0(ctx context.Context, marshaler runtime.Marshaler, server ProjectServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq ListProjectsRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
var (
|
||||
val string
|
||||
ok bool
|
||||
err error
|
||||
_ = err
|
||||
)
|
||||
|
||||
val, ok = pathParams["org_id"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "org_id")
|
||||
}
|
||||
|
||||
protoReq.OrgId, err = runtime.String(val)
|
||||
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "org_id", err)
|
||||
}
|
||||
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.URL.Query(), filter_ProjectService_ListProjects_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := server.ListProjects(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func request_ProjectService_CreateProject_0(ctx context.Context, marshaler runtime.Marshaler, client ProjectServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq CreateProjectRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
newReader, berr := utilities.IOReaderFactory(req.Body)
|
||||
if berr != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
|
||||
}
|
||||
if err := marshaler.NewDecoder(newReader()).Decode(&protoReq.Item); err != nil && err != io.EOF {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
var (
|
||||
val string
|
||||
ok bool
|
||||
err error
|
||||
_ = err
|
||||
)
|
||||
|
||||
val, ok = pathParams["org_id"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "org_id")
|
||||
}
|
||||
|
||||
protoReq.OrgId, err = runtime.String(val)
|
||||
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "org_id", err)
|
||||
}
|
||||
|
||||
msg, err := client.CreateProject(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_ProjectService_CreateProject_0(ctx context.Context, marshaler runtime.Marshaler, server ProjectServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq CreateProjectRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
newReader, berr := utilities.IOReaderFactory(req.Body)
|
||||
if berr != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
|
||||
}
|
||||
if err := marshaler.NewDecoder(newReader()).Decode(&protoReq.Item); err != nil && err != io.EOF {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
var (
|
||||
val string
|
||||
ok bool
|
||||
err error
|
||||
_ = err
|
||||
)
|
||||
|
||||
val, ok = pathParams["org_id"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "org_id")
|
||||
}
|
||||
|
||||
protoReq.OrgId, err = runtime.String(val)
|
||||
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "org_id", err)
|
||||
}
|
||||
|
||||
msg, err := server.CreateProject(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
var (
|
||||
filter_ProjectService_UpdateProject_0 = &utilities.DoubleArray{Encoding: map[string]int{"item": 0, "org_id": 1, "id": 2}, Base: []int{1, 1, 2, 3, 0, 0, 0}, Check: []int{0, 1, 1, 1, 2, 3, 4}}
|
||||
)
|
||||
|
||||
func request_ProjectService_UpdateProject_0(ctx context.Context, marshaler runtime.Marshaler, client ProjectServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq UpdateProjectRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
newReader, berr := utilities.IOReaderFactory(req.Body)
|
||||
if berr != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
|
||||
}
|
||||
if err := marshaler.NewDecoder(newReader()).Decode(&protoReq.Item); err != nil && err != io.EOF {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
if protoReq.UpdateMask == nil || len(protoReq.UpdateMask.GetPaths()) == 0 {
|
||||
_, md := descriptor.ForMessage(protoReq.Item)
|
||||
if fieldMask, err := runtime.FieldMaskFromRequestBody(newReader(), md); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
} else {
|
||||
protoReq.UpdateMask = fieldMask
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
val string
|
||||
ok bool
|
||||
err error
|
||||
_ = err
|
||||
)
|
||||
|
||||
val, ok = pathParams["org_id"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "org_id")
|
||||
}
|
||||
|
||||
protoReq.OrgId, err = runtime.String(val)
|
||||
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "org_id", err)
|
||||
}
|
||||
|
||||
val, ok = pathParams["id"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id")
|
||||
}
|
||||
|
||||
protoReq.Id, err = runtime.String(val)
|
||||
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err)
|
||||
}
|
||||
|
||||
if err := req.ParseForm(); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_ProjectService_UpdateProject_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := client.UpdateProject(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_ProjectService_UpdateProject_0(ctx context.Context, marshaler runtime.Marshaler, server ProjectServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq UpdateProjectRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
newReader, berr := utilities.IOReaderFactory(req.Body)
|
||||
if berr != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
|
||||
}
|
||||
if err := marshaler.NewDecoder(newReader()).Decode(&protoReq.Item); err != nil && err != io.EOF {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
if protoReq.UpdateMask == nil || len(protoReq.UpdateMask.GetPaths()) == 0 {
|
||||
_, md := descriptor.ForMessage(protoReq.Item)
|
||||
if fieldMask, err := runtime.FieldMaskFromRequestBody(newReader(), md); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
} else {
|
||||
protoReq.UpdateMask = fieldMask
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
val string
|
||||
ok bool
|
||||
err error
|
||||
_ = err
|
||||
)
|
||||
|
||||
val, ok = pathParams["org_id"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "org_id")
|
||||
}
|
||||
|
||||
protoReq.OrgId, err = runtime.String(val)
|
||||
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "org_id", err)
|
||||
}
|
||||
|
||||
val, ok = pathParams["id"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id")
|
||||
}
|
||||
|
||||
protoReq.Id, err = runtime.String(val)
|
||||
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err)
|
||||
}
|
||||
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.URL.Query(), filter_ProjectService_UpdateProject_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := server.UpdateProject(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func request_ProjectService_DeleteProject_0(ctx context.Context, marshaler runtime.Marshaler, client ProjectServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq DeleteProjectRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
var (
|
||||
val string
|
||||
ok bool
|
||||
err error
|
||||
_ = err
|
||||
)
|
||||
|
||||
val, ok = pathParams["org_id"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "org_id")
|
||||
}
|
||||
|
||||
protoReq.OrgId, err = runtime.String(val)
|
||||
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "org_id", err)
|
||||
}
|
||||
|
||||
val, ok = pathParams["id"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id")
|
||||
}
|
||||
|
||||
protoReq.Id, err = runtime.String(val)
|
||||
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err)
|
||||
}
|
||||
|
||||
msg, err := client.DeleteProject(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_ProjectService_DeleteProject_0(ctx context.Context, marshaler runtime.Marshaler, server ProjectServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq DeleteProjectRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
var (
|
||||
val string
|
||||
ok bool
|
||||
err error
|
||||
_ = err
|
||||
)
|
||||
|
||||
val, ok = pathParams["org_id"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "org_id")
|
||||
}
|
||||
|
||||
protoReq.OrgId, err = runtime.String(val)
|
||||
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "org_id", err)
|
||||
}
|
||||
|
||||
val, ok = pathParams["id"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id")
|
||||
}
|
||||
|
||||
protoReq.Id, err = runtime.String(val)
|
||||
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err)
|
||||
}
|
||||
|
||||
msg, err := server.DeleteProject(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
// RegisterProjectServiceHandlerServer registers the http handlers for service ProjectService to "mux".
|
||||
// UnaryRPC :call ProjectServiceServer directly.
|
||||
// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906.
|
||||
func RegisterProjectServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux, server ProjectServiceServer) error {
|
||||
|
||||
mux.Handle("GET", pattern_ProjectService_GetProject_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := local_request_ProjectService_GetProject_0(rctx, inboundMarshaler, server, req, pathParams)
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_ProjectService_GetProject_0(ctx, mux, outboundMarshaler, w, req, response_ProjectService_GetProject_0{resp}, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_ProjectService_ListProjects_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := local_request_ProjectService_ListProjects_0(rctx, inboundMarshaler, server, req, pathParams)
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_ProjectService_ListProjects_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("POST", pattern_ProjectService_CreateProject_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := local_request_ProjectService_CreateProject_0(rctx, inboundMarshaler, server, req, pathParams)
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_ProjectService_CreateProject_0(ctx, mux, outboundMarshaler, w, req, response_ProjectService_CreateProject_0{resp}, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("PATCH", pattern_ProjectService_UpdateProject_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := local_request_ProjectService_UpdateProject_0(rctx, inboundMarshaler, server, req, pathParams)
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_ProjectService_UpdateProject_0(ctx, mux, outboundMarshaler, w, req, response_ProjectService_UpdateProject_0{resp}, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("DELETE", pattern_ProjectService_DeleteProject_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := local_request_ProjectService_DeleteProject_0(rctx, inboundMarshaler, server, req, pathParams)
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_ProjectService_DeleteProject_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// RegisterProjectServiceHandlerFromEndpoint is same as RegisterProjectServiceHandler but
|
||||
// automatically dials to "endpoint" and closes the connection when "ctx" gets done.
|
||||
func RegisterProjectServiceHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) {
|
||||
conn, err := grpc.Dial(endpoint, opts...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
if err != nil {
|
||||
if cerr := conn.Close(); cerr != nil {
|
||||
grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr)
|
||||
}
|
||||
return
|
||||
}
|
||||
go func() {
|
||||
<-ctx.Done()
|
||||
if cerr := conn.Close(); cerr != nil {
|
||||
grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr)
|
||||
}
|
||||
}()
|
||||
}()
|
||||
|
||||
return RegisterProjectServiceHandler(ctx, mux, conn)
|
||||
}
|
||||
|
||||
// RegisterProjectServiceHandler registers the http handlers for service ProjectService to "mux".
|
||||
// The handlers forward requests to the grpc endpoint over "conn".
|
||||
func RegisterProjectServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
|
||||
return RegisterProjectServiceHandlerClient(ctx, mux, NewProjectServiceClient(conn))
|
||||
}
|
||||
|
||||
// RegisterProjectServiceHandlerClient registers the http handlers for service ProjectService
|
||||
// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "ProjectServiceClient".
|
||||
// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "ProjectServiceClient"
|
||||
// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in
|
||||
// "ProjectServiceClient" to call the correct interceptors.
|
||||
func RegisterProjectServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, client ProjectServiceClient) error {
|
||||
|
||||
mux.Handle("GET", pattern_ProjectService_GetProject_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := request_ProjectService_GetProject_0(rctx, inboundMarshaler, client, req, pathParams)
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_ProjectService_GetProject_0(ctx, mux, outboundMarshaler, w, req, response_ProjectService_GetProject_0{resp}, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_ProjectService_ListProjects_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := request_ProjectService_ListProjects_0(rctx, inboundMarshaler, client, req, pathParams)
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_ProjectService_ListProjects_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("POST", pattern_ProjectService_CreateProject_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := request_ProjectService_CreateProject_0(rctx, inboundMarshaler, client, req, pathParams)
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_ProjectService_CreateProject_0(ctx, mux, outboundMarshaler, w, req, response_ProjectService_CreateProject_0{resp}, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("PATCH", pattern_ProjectService_UpdateProject_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := request_ProjectService_UpdateProject_0(rctx, inboundMarshaler, client, req, pathParams)
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_ProjectService_UpdateProject_0(ctx, mux, outboundMarshaler, w, req, response_ProjectService_UpdateProject_0{resp}, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("DELETE", pattern_ProjectService_DeleteProject_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := request_ProjectService_DeleteProject_0(rctx, inboundMarshaler, client, req, pathParams)
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_ProjectService_DeleteProject_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type response_ProjectService_GetProject_0 struct {
|
||||
proto.Message
|
||||
}
|
||||
|
||||
func (m response_ProjectService_GetProject_0) XXX_ResponseBody() interface{} {
|
||||
response := m.Message.(*GetProjectResponse)
|
||||
return response.Item
|
||||
}
|
||||
|
||||
type response_ProjectService_CreateProject_0 struct {
|
||||
proto.Message
|
||||
}
|
||||
|
||||
func (m response_ProjectService_CreateProject_0) XXX_ResponseBody() interface{} {
|
||||
response := m.Message.(*CreateProjectResponse)
|
||||
return response.Item
|
||||
}
|
||||
|
||||
type response_ProjectService_UpdateProject_0 struct {
|
||||
proto.Message
|
||||
}
|
||||
|
||||
func (m response_ProjectService_UpdateProject_0) XXX_ResponseBody() interface{} {
|
||||
response := m.Message.(*UpdateProjectResponse)
|
||||
return response.Item
|
||||
}
|
||||
|
||||
var (
|
||||
pattern_ProjectService_GetProject_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"v1", "orgs", "org_id", "projects", "id"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_ProjectService_ListProjects_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2, 2, 3}, []string{"v1", "orgs", "org_id", "projects"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_ProjectService_CreateProject_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2, 2, 3}, []string{"v1", "orgs", "org_id", "projects"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_ProjectService_UpdateProject_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"v1", "orgs", "org_id", "projects", "id"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_ProjectService_DeleteProject_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"v1", "orgs", "org_id", "projects", "id"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
)
|
||||
|
||||
var (
|
||||
forward_ProjectService_GetProject_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_ProjectService_ListProjects_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_ProjectService_CreateProject_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_ProjectService_UpdateProject_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_ProjectService_DeleteProject_0 = runtime.ForwardResponseMessage
|
||||
)
|
||||
@ -0,0 +1,29 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package controller.api.resources.scopes.v1;
|
||||
|
||||
option go_package = "github.com/hashicorp/watchtower/internal/gen/controller/api/resources/scopes;scopes";
|
||||
|
||||
import "google/protobuf/timestamp.proto";
|
||||
import "google/protobuf/wrappers.proto";
|
||||
|
||||
// Organization contains all fields related to an Organization resource
|
||||
message Organization {
|
||||
// The ID of the Organization
|
||||
// Output only.
|
||||
string id = 1;
|
||||
|
||||
// Optional name for identification purposes
|
||||
google.protobuf.StringValue name = 2;
|
||||
|
||||
// Optional user-set descripton for identification purposes
|
||||
google.protobuf.StringValue description = 3;
|
||||
|
||||
// The time this resource was created
|
||||
// Output only.
|
||||
google.protobuf.Timestamp created_time = 4 [json_name="created_time"];
|
||||
|
||||
// The time this resource was last updated.
|
||||
// Output only.
|
||||
google.protobuf.Timestamp updated_time = 5 [json_name="updated_time"];
|
||||
}
|
||||
@ -0,0 +1,32 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package controller.api.resources.scopes.v1;
|
||||
|
||||
option go_package = "github.com/hashicorp/watchtower/internal/gen/controller/api/resources/scopes;scopes";
|
||||
|
||||
import "google/protobuf/timestamp.proto";
|
||||
import "google/protobuf/wrappers.proto";
|
||||
|
||||
// Project contains all fields related to a Project resource
|
||||
message Project {
|
||||
// The ID of the Project
|
||||
// Output only.
|
||||
string id = 1;
|
||||
|
||||
// Optional name for identification purposes
|
||||
google.protobuf.StringValue name = 2;
|
||||
|
||||
// Optional user-set descripton for identification purposes
|
||||
google.protobuf.StringValue description = 3;
|
||||
|
||||
// The time this resource was created
|
||||
// Output only.
|
||||
google.protobuf.Timestamp created_time = 4 [json_name="created_time"];
|
||||
|
||||
// The time this resource was last updated.
|
||||
// Output only.
|
||||
google.protobuf.Timestamp updated_time = 5 [json_name="updated_time"];
|
||||
|
||||
// Whether the resource is disabled
|
||||
google.protobuf.BoolValue disabled = 6;
|
||||
}
|
||||
@ -0,0 +1,108 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package controller.api.services.v1;
|
||||
|
||||
option go_package = "github.com/hashicorp/watchtower/internal/gen/controller/api/services;services";
|
||||
|
||||
import "protoc-gen-swagger/options/annotations.proto";
|
||||
import "google/api/annotations.proto";
|
||||
import "google/protobuf/field_mask.proto";
|
||||
import "google/protobuf/wrappers.proto";
|
||||
import "controller/api/resources/scopes/v1/project.proto";
|
||||
|
||||
service ProjectService {
|
||||
rpc GetProject(GetProjectRequest) returns (GetProjectResponse) {
|
||||
option (google.api.http) = {
|
||||
get: "/v1/orgs/{org_id}/projects/{id}"
|
||||
response_body: "item"
|
||||
};
|
||||
option (grpc.gateway.protoc_gen_swagger.options.openapiv2_operation) = {
|
||||
summary: "Gets a single Project"
|
||||
};
|
||||
}
|
||||
rpc ListProjects(ListProjectsRequest) returns (ListProjectsResponse) {
|
||||
option (google.api.http) = {
|
||||
get: "/v1/orgs/{org_id}/projects"
|
||||
};
|
||||
option (grpc.gateway.protoc_gen_swagger.options.openapiv2_operation) = {
|
||||
summary: "Lists all Projects"
|
||||
};
|
||||
}
|
||||
rpc CreateProject(CreateProjectRequest) returns (CreateProjectResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/v1/orgs/{org_id}/projects"
|
||||
body: "item"
|
||||
response_body: "item"
|
||||
};
|
||||
option (grpc.gateway.protoc_gen_swagger.options.openapiv2_operation) = {
|
||||
summary: "Creates a single Project"
|
||||
};
|
||||
}
|
||||
rpc UpdateProject(UpdateProjectRequest) returns (UpdateProjectResponse) {
|
||||
option (google.api.http) = {
|
||||
patch: "/v1/orgs/{org_id}/projects/{id}"
|
||||
body: "item"
|
||||
response_body: "item"
|
||||
};
|
||||
option (grpc.gateway.protoc_gen_swagger.options.openapiv2_operation) = {
|
||||
summary: "Updates a Project"
|
||||
};
|
||||
}
|
||||
rpc DeleteProject(DeleteProjectRequest) returns (DeleteProjectResponse) {
|
||||
option (google.api.http) = {
|
||||
delete: "/v1/orgs/{org_id}/projects/{id}"
|
||||
};
|
||||
option (grpc.gateway.protoc_gen_swagger.options.openapiv2_operation) = {
|
||||
summary: "Deletes a Project"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
message GetProjectRequest {
|
||||
string org_id = 1;
|
||||
string id = 2;
|
||||
string view = 3;
|
||||
}
|
||||
|
||||
message GetProjectResponse {
|
||||
resources.scopes.v1.Project item = 1;
|
||||
}
|
||||
|
||||
message ListProjectsRequest {
|
||||
string org_id = 1;
|
||||
string view = 2;
|
||||
}
|
||||
|
||||
message ListProjectsResponse {
|
||||
repeated resources.scopes.v1.Project items = 1;
|
||||
}
|
||||
|
||||
message CreateProjectRequest {
|
||||
string org_id = 1;
|
||||
resources.scopes.v1.Project item = 2;
|
||||
}
|
||||
|
||||
message CreateProjectResponse {
|
||||
string uri = 1;
|
||||
resources.scopes.v1.Project item = 2;
|
||||
}
|
||||
|
||||
message UpdateProjectRequest {
|
||||
string org_id = 1;
|
||||
string id = 2;
|
||||
resources.scopes.v1.Project item = 3;
|
||||
google.protobuf.FieldMask update_mask = 4;
|
||||
}
|
||||
|
||||
message UpdateProjectResponse {
|
||||
resources.scopes.v1.Project item = 1;
|
||||
}
|
||||
|
||||
message DeleteProjectRequest {
|
||||
string org_id = 1;
|
||||
string id = 2;
|
||||
}
|
||||
|
||||
message DeleteProjectResponse {
|
||||
bool existed = 1;
|
||||
}
|
||||
@ -0,0 +1,244 @@
|
||||
package projects
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/golang/protobuf/ptypes/wrappers"
|
||||
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||
pb "github.com/hashicorp/watchtower/internal/gen/controller/api/resources/scopes"
|
||||
pbs "github.com/hashicorp/watchtower/internal/gen/controller/api/services"
|
||||
"github.com/hashicorp/watchtower/internal/iam"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
var reInvalidID = regexp.MustCompile("[^A-Za-z0-9]")
|
||||
|
||||
type Service struct {
|
||||
pbs.UnimplementedProjectServiceServer
|
||||
repo *iam.Repository
|
||||
}
|
||||
|
||||
func NewService(repo *iam.Repository) *Service {
|
||||
if repo == nil {
|
||||
return nil
|
||||
}
|
||||
return &Service{repo: repo}
|
||||
}
|
||||
|
||||
var _ pbs.ProjectServiceServer = &Service{}
|
||||
|
||||
func (s Service) GetProject(ctx context.Context, req *pbs.GetProjectRequest) (*pbs.GetProjectResponse, error) {
|
||||
if err := validateGetProjectRequest(req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p, err := s.getFromRepo(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp := &pbs.GetProjectResponse{}
|
||||
resp.Item = p
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s Service) CreateProject(ctx context.Context, req *pbs.CreateProjectRequest) (*pbs.CreateProjectResponse, error) {
|
||||
if err := validateCreateProjectRequest(req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p, err := s.createInRepo(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp := &pbs.CreateProjectResponse{}
|
||||
resp.Uri = fmt.Sprintf("orgs/%s/projects/%s", req.GetOrgId(), p.GetId())
|
||||
resp.Item = p
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s Service) UpdateProject(ctx context.Context, req *pbs.UpdateProjectRequest) (*pbs.UpdateProjectResponse, error) {
|
||||
if err := validateUpdateProjectRequest(req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p, err := s.updateInRepo(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp := &pbs.UpdateProjectResponse{}
|
||||
resp.Item = p
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s Service) getFromRepo(ctx context.Context, req *pbs.GetProjectRequest) (*pb.Project, error) {
|
||||
p, err := s.repo.LookupScope(ctx, iam.WithPublicId(req.GetId()))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if p == nil {
|
||||
return nil, status.Errorf(codes.NotFound, "Could not find Project with id %q", req.GetId())
|
||||
}
|
||||
return toProto(p), nil
|
||||
}
|
||||
|
||||
func (s Service) createInRepo(ctx context.Context, req *pbs.CreateProjectRequest) (*pb.Project, error) {
|
||||
in := req.GetItem()
|
||||
opts := []iam.Option{}
|
||||
if in.GetName() != nil {
|
||||
opts = append(opts, iam.WithName(in.GetName().GetValue()))
|
||||
}
|
||||
if in.GetDescription() != nil {
|
||||
opts = append(opts, iam.WithDescription(in.GetDescription().GetValue()))
|
||||
}
|
||||
p, err := iam.NewProject(req.GetOrgId(), opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out, err := s.repo.CreateScope(ctx, p)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if out == nil {
|
||||
return nil, status.Error(codes.Internal, "Unable to create scope but no error returned from repository.")
|
||||
}
|
||||
return toProto(out), nil
|
||||
}
|
||||
|
||||
func (s Service) updateInRepo(ctx context.Context, req *pbs.UpdateProjectRequest) (*pb.Project, error) {
|
||||
item := req.GetItem()
|
||||
// TODO: convert field masks from API field masks with snake_case to db field masks casing.
|
||||
madeUp := []string{}
|
||||
opts := []iam.Option{iam.WithPublicId(req.GetId())}
|
||||
if desc := item.GetDescription(); desc != nil {
|
||||
madeUp = append(madeUp, "Description")
|
||||
opts = append(opts, iam.WithDescription(desc.GetValue()))
|
||||
}
|
||||
if name := item.GetName(); name != nil {
|
||||
madeUp = append(madeUp, "Name")
|
||||
opts = append(opts, iam.WithName(name.GetValue()))
|
||||
}
|
||||
p, err := iam.NewProject(req.GetOrgId(), opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out, err := s.repo.UpdateScope(ctx, p, madeUp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if out == nil {
|
||||
return nil, status.Error(codes.NotFound, "Project doesn't exist.")
|
||||
}
|
||||
return toProto(out), nil
|
||||
}
|
||||
|
||||
func toProto(in *iam.Scope) *pb.Project {
|
||||
out := pb.Project{Id: in.GetPublicId()}
|
||||
if in.GetDescription() != "" {
|
||||
out.Description = &wrappers.StringValue{Value: in.GetDescription()}
|
||||
}
|
||||
if in.GetName() != "" {
|
||||
out.Name = &wrappers.StringValue{Value: in.GetName()}
|
||||
}
|
||||
out.CreatedTime = in.GetCreateTime().GetTimestamp()
|
||||
out.UpdatedTime = in.GetUpdateTime().GetTimestamp()
|
||||
return &out
|
||||
}
|
||||
|
||||
// A validateX method should exist for each method above. These methods do not make calls to any backing service but enforce
|
||||
// requirements on the structure of the request. They verify that:
|
||||
// * The path passed in is correctly formatted
|
||||
// * All required parameters are set
|
||||
// * There are no conflicting parameters provided
|
||||
// TODO: Populate the error in a way to allow it to be converted to the previously described error format and include all invalid fields instead of just the most recent.
|
||||
func validateGetProjectRequest(req *pbs.GetProjectRequest) error {
|
||||
if err := validateAncestors(req); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := validateID(req.GetOrgId(), "o_"); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := validateID(req.GetId(), "p_"); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateCreateProjectRequest(req *pbs.CreateProjectRequest) error {
|
||||
if err := validateAncestors(req); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := validateID(req.GetOrgId(), "o_"); err != nil {
|
||||
return err
|
||||
}
|
||||
item := req.GetItem()
|
||||
if item == nil {
|
||||
return status.Errorf(codes.InvalidArgument, "A project's fields must be set to something .")
|
||||
}
|
||||
if item.GetId() != "" {
|
||||
return status.Errorf(codes.InvalidArgument, "Cannot set ID when creating a new project.")
|
||||
}
|
||||
if item.GetCreatedTime() != nil || item.GetUpdatedTime() != nil {
|
||||
return status.Errorf(codes.InvalidArgument, "Cannot set Created or Updated time when creating a new project.")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateUpdateProjectRequest(req *pbs.UpdateProjectRequest) error {
|
||||
if err := validateAncestors(req); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := validateID(req.GetId(), "p_"); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := validateID(req.GetOrgId(), "o_"); err != nil {
|
||||
return err
|
||||
}
|
||||
// TODO: Either require mask to be set or document in API that an unset mask updates all fields.
|
||||
item := req.GetItem()
|
||||
if item == nil {
|
||||
// It is legitimate for no item to be specified in an update request as it indicates all fields provided in
|
||||
// the mask will be marked as unset.
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := validateID(item.GetId(), "p_"); item.GetId() != "" && err != nil {
|
||||
return err
|
||||
}
|
||||
if item.GetId() != "" && item.GetId() != req.GetId() {
|
||||
return status.Errorf(codes.InvalidArgument, "Id in provided item and url must match. Item Id was %q, url id was %q", item.GetId(), req.GetId())
|
||||
}
|
||||
if item.GetCreatedTime() != nil || item.GetUpdatedTime() != nil {
|
||||
return status.Errorf(codes.InvalidArgument, "Cannot set Created or Updated time when updating a project.")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateID(id, prefix string) error {
|
||||
if !strings.HasPrefix(id, prefix) {
|
||||
return status.Errorf(codes.InvalidArgument, "ID start with a %q prefix, provided %q", prefix, id)
|
||||
}
|
||||
id = strings.TrimPrefix(id, prefix)
|
||||
if reInvalidID.Match([]byte(id)) {
|
||||
return status.Errorf(codes.InvalidArgument, "Improperly formatted ID: %q", id)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type ancestorProvider interface {
|
||||
GetOrgId() string
|
||||
}
|
||||
|
||||
// validateAncestors verifies that the ancestors of this call are properly set and provided.
|
||||
func validateAncestors(r ancestorProvider) error {
|
||||
if r.GetOrgId() == "" {
|
||||
return status.Errorf(codes.InvalidArgument, "org_id must be provided.")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// RegisterGrpcGateway satisfies the RegisterGrpcGatewayer interface.
|
||||
func (s *Service) RegisterGrpcGateway(mux *runtime.ServeMux) error {
|
||||
return pbs.RegisterProjectServiceHandlerServer(context.Background(), mux, s)
|
||||
}
|
||||
@ -0,0 +1,313 @@
|
||||
package projects_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/golang/protobuf/ptypes"
|
||||
"github.com/golang/protobuf/ptypes/wrappers"
|
||||
"github.com/hashicorp/watchtower/internal/db"
|
||||
pb "github.com/hashicorp/watchtower/internal/gen/controller/api/resources/scopes"
|
||||
pbs "github.com/hashicorp/watchtower/internal/gen/controller/api/services"
|
||||
"github.com/hashicorp/watchtower/internal/iam"
|
||||
"github.com/hashicorp/watchtower/internal/servers/controller/handlers/projects"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func createDefaultProjectAndRepo(t *testing.T) (*iam.Scope, *iam.Repository) {
|
||||
t.Helper()
|
||||
cleanup, conn := db.TestSetup(t, "postgres")
|
||||
t.Cleanup(func() {
|
||||
conn.Close()
|
||||
cleanup()
|
||||
})
|
||||
rw := db.New(conn)
|
||||
wrap := db.TestWrapper(t)
|
||||
repo, err := iam.NewRepository(rw, rw, wrap)
|
||||
assert.Nil(t, err, "Unable to create new repo")
|
||||
|
||||
// Create a default org and project for our tests.
|
||||
o, err := iam.NewOrganization(iam.WithName("default"))
|
||||
if err != nil {
|
||||
t.Fatalf("Could not get new org: %v", err)
|
||||
}
|
||||
oRes, err := repo.CreateScope(context.Background(), o)
|
||||
if err != nil {
|
||||
t.Fatalf("Could not create org scope: %v", err)
|
||||
}
|
||||
|
||||
p, err := iam.NewProject(oRes.GetPublicId(), iam.WithName("default"))
|
||||
if err != nil {
|
||||
t.Fatalf("Could not get new project: %v", err)
|
||||
}
|
||||
pRes, err := repo.CreateScope(context.Background(), p)
|
||||
if err != nil {
|
||||
t.Fatalf("Could not create project scope: %v", err)
|
||||
}
|
||||
|
||||
return pRes, repo
|
||||
}
|
||||
|
||||
func TestGet(t *testing.T) {
|
||||
proj, repo := createDefaultProjectAndRepo(t)
|
||||
toMerge := &pbs.GetProjectRequest{
|
||||
OrgId: proj.GetParentId(),
|
||||
Id: proj.GetPublicId(),
|
||||
}
|
||||
|
||||
pProject := &pb.Project{
|
||||
Id: proj.GetPublicId(),
|
||||
Name: &wrappers.StringValue{Value: proj.GetName()},
|
||||
CreatedTime: proj.CreateTime.GetTimestamp(),
|
||||
UpdatedTime: proj.UpdateTime.GetTimestamp(),
|
||||
}
|
||||
|
||||
cases := []struct {
|
||||
name string
|
||||
req *pbs.GetProjectRequest
|
||||
res *pbs.GetProjectResponse
|
||||
errCode codes.Code
|
||||
}{
|
||||
{
|
||||
name: "Get an Existing Project",
|
||||
req: &pbs.GetProjectRequest{Id: proj.GetPublicId()},
|
||||
res: &pbs.GetProjectResponse{Item: pProject},
|
||||
errCode: codes.OK,
|
||||
},
|
||||
{
|
||||
name: "Get a non existant Host Catalog",
|
||||
req: &pbs.GetProjectRequest{Id: "p_DoesntExis"},
|
||||
res: nil,
|
||||
// This will be fixed with PR 42
|
||||
errCode: codes.NotFound,
|
||||
},
|
||||
{
|
||||
name: "Wrong id prefix",
|
||||
req: &pbs.GetProjectRequest{Id: "j_1234567890"},
|
||||
res: nil,
|
||||
// This will be fixed with PR 42
|
||||
errCode: codes.InvalidArgument,
|
||||
},
|
||||
{
|
||||
name: "space in id",
|
||||
req: &pbs.GetProjectRequest{Id: "p_1 23456789"},
|
||||
res: nil,
|
||||
// This will be fixed with PR 42
|
||||
errCode: codes.InvalidArgument,
|
||||
},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
req := proto.Clone(toMerge).(*pbs.GetProjectRequest)
|
||||
proto.Merge(req, tc.req)
|
||||
|
||||
s := projects.NewService(repo)
|
||||
|
||||
got, gErr := s.GetProject(context.Background(), req)
|
||||
assert.Equal(tc.errCode, status.Code(gErr), "GetProject(%+v) got error %v, wanted %v", req, gErr, tc.errCode)
|
||||
assert.True(proto.Equal(got, tc.res), "GetProject(%q) got response %q, wanted %q", req, got, tc.res)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreate(t *testing.T) {
|
||||
defaultProj, repo := createDefaultProjectAndRepo(t)
|
||||
defaultProjCreated, err := ptypes.Timestamp(defaultProj.GetCreateTime().GetTimestamp())
|
||||
if err != nil {
|
||||
t.Fatalf("Error converting proto to timestamp: %v", err)
|
||||
}
|
||||
toMerge := &pbs.CreateProjectRequest{
|
||||
OrgId: defaultProj.GetParentId(),
|
||||
}
|
||||
|
||||
cases := []struct {
|
||||
name string
|
||||
req *pbs.CreateProjectRequest
|
||||
res *pbs.CreateProjectResponse
|
||||
errCode codes.Code
|
||||
}{
|
||||
{
|
||||
name: "Create a valid Project",
|
||||
req: &pbs.CreateProjectRequest{Item: &pb.Project{
|
||||
Name: &wrappers.StringValue{Value: "name"},
|
||||
Description: &wrappers.StringValue{Value: "desc"},
|
||||
}},
|
||||
res: &pbs.CreateProjectResponse{
|
||||
Uri: fmt.Sprintf("orgs/%s/projects/p_", defaultProj.GetParentId()),
|
||||
Item: &pb.Project{
|
||||
Name: &wrappers.StringValue{Value: "name"},
|
||||
Description: &wrappers.StringValue{Value: "desc"},
|
||||
},
|
||||
},
|
||||
errCode: codes.OK,
|
||||
},
|
||||
{
|
||||
name: "Can't specify Id",
|
||||
req: &pbs.CreateProjectRequest{Item: &pb.Project{
|
||||
Id: "not allowed to be set",
|
||||
}},
|
||||
res: nil,
|
||||
errCode: codes.InvalidArgument,
|
||||
},
|
||||
{
|
||||
name: "Can't specify Created Time",
|
||||
req: &pbs.CreateProjectRequest{Item: &pb.Project{
|
||||
CreatedTime: ptypes.TimestampNow(),
|
||||
}},
|
||||
res: nil,
|
||||
errCode: codes.InvalidArgument,
|
||||
},
|
||||
{
|
||||
name: "Can't specify Update Time",
|
||||
req: &pbs.CreateProjectRequest{Item: &pb.Project{
|
||||
UpdatedTime: ptypes.TimestampNow(),
|
||||
}},
|
||||
res: nil,
|
||||
errCode: codes.InvalidArgument,
|
||||
},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
req := proto.Clone(toMerge).(*pbs.CreateProjectRequest)
|
||||
proto.Merge(req, tc.req)
|
||||
|
||||
s := projects.NewService(repo)
|
||||
|
||||
got, gErr := s.CreateProject(context.Background(), req)
|
||||
assert.Equal(tc.errCode, status.Code(gErr), "CreateProject(%+v) got error %v, wanted %v", req, gErr, tc.errCode)
|
||||
if got != nil {
|
||||
strings.HasPrefix(got.GetUri(), tc.res.Uri)
|
||||
strings.HasPrefix(got.GetItem().GetId(), "p_")
|
||||
gotCreateTime, err := ptypes.Timestamp(got.GetItem().GetCreatedTime())
|
||||
if err != nil {
|
||||
t.Fatalf("Error converting proto to timestamp: %v", err)
|
||||
}
|
||||
gotUpdateTime, err := ptypes.Timestamp(got.GetItem().GetUpdatedTime())
|
||||
if err != nil {
|
||||
t.Fatalf("Error converting proto to timestamp: %v", err)
|
||||
}
|
||||
// Verify it is a project created after the test setup's default project
|
||||
assert.True(gotCreateTime.After(defaultProjCreated), "New project should have been created after default project. Was created %v, which is after %v", gotCreateTime, defaultProjCreated)
|
||||
assert.True(gotUpdateTime.After(defaultProjCreated), "New project should have been updated after default project. Was updated %v, which is after %v", gotUpdateTime, defaultProjCreated)
|
||||
|
||||
// Clear all values which are hard to compare against.
|
||||
got.Uri, tc.res.Uri = "", ""
|
||||
got.Item.Id, tc.res.Item.Id = "", ""
|
||||
got.Item.CreatedTime, got.Item.UpdatedTime, tc.res.Item.CreatedTime, tc.res.Item.UpdatedTime = nil, nil, nil, nil
|
||||
}
|
||||
assert.True(proto.Equal(got, tc.res), "CreateProject(%q) got response %q, wanted %q", req, got, tc.res)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdate(t *testing.T) {
|
||||
proj, repo := createDefaultProjectAndRepo(t)
|
||||
projCreated, err := ptypes.Timestamp(proj.GetCreateTime().GetTimestamp())
|
||||
if err != nil {
|
||||
t.Fatalf("Error converting proto to timestamp: %v", err)
|
||||
}
|
||||
toMerge := &pbs.UpdateProjectRequest{
|
||||
OrgId: proj.GetParentId(),
|
||||
Id: proj.GetPublicId(),
|
||||
}
|
||||
|
||||
cases := []struct {
|
||||
name string
|
||||
req *pbs.UpdateProjectRequest
|
||||
res *pbs.UpdateProjectResponse
|
||||
errCode codes.Code
|
||||
}{
|
||||
{
|
||||
name: "Update an Existing Project",
|
||||
req: &pbs.UpdateProjectRequest{Item: &pb.Project{
|
||||
Name: &wrappers.StringValue{Value: "new"},
|
||||
Description: &wrappers.StringValue{Value: "desc"},
|
||||
}},
|
||||
res: &pbs.UpdateProjectResponse{
|
||||
Item: &pb.Project{
|
||||
Id: proj.GetPublicId(),
|
||||
Name: &wrappers.StringValue{Value: "new"},
|
||||
Description: &wrappers.StringValue{Value: "desc"},
|
||||
CreatedTime: proj.GetCreateTime().GetTimestamp(),
|
||||
},
|
||||
},
|
||||
errCode: codes.OK,
|
||||
},
|
||||
{
|
||||
name: "Update a Non Existing Project",
|
||||
req: &pbs.UpdateProjectRequest{
|
||||
Id: "p_DoesntExis",
|
||||
Item: &pb.Project{
|
||||
Name: &wrappers.StringValue{Value: "new"},
|
||||
Description: &wrappers.StringValue{Value: "desc"},
|
||||
},
|
||||
},
|
||||
// TODO: Update this to be NotFound.
|
||||
errCode: codes.Unknown,
|
||||
},
|
||||
{
|
||||
name: "Cant change Id",
|
||||
req: &pbs.UpdateProjectRequest{
|
||||
Id: "p_1234567890",
|
||||
Item: &pb.Project{
|
||||
Id: "p_0987654321",
|
||||
Name: &wrappers.StringValue{Value: "new"},
|
||||
Description: &wrappers.StringValue{Value: "new desc"},
|
||||
}},
|
||||
res: nil,
|
||||
errCode: codes.InvalidArgument,
|
||||
},
|
||||
{
|
||||
name: "Cant specify Created Time",
|
||||
req: &pbs.UpdateProjectRequest{Item: &pb.Project{
|
||||
CreatedTime: ptypes.TimestampNow(),
|
||||
}},
|
||||
res: nil,
|
||||
errCode: codes.InvalidArgument,
|
||||
},
|
||||
{
|
||||
name: "Cant specify Updated Time",
|
||||
req: &pbs.UpdateProjectRequest{Item: &pb.Project{
|
||||
UpdatedTime: ptypes.TimestampNow(),
|
||||
}},
|
||||
res: nil,
|
||||
errCode: codes.InvalidArgument,
|
||||
},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
req := proto.Clone(toMerge).(*pbs.UpdateProjectRequest)
|
||||
proto.Merge(req, tc.req)
|
||||
|
||||
s := projects.NewService(repo)
|
||||
|
||||
got, gErr := s.UpdateProject(context.Background(), req)
|
||||
assert.Equal(tc.errCode, status.Code(gErr), "UpdateProject(%+v) got error %v, wanted %v", req, gErr, tc.errCode)
|
||||
|
||||
if got != nil {
|
||||
gotUpdateTime, err := ptypes.Timestamp(got.GetItem().GetUpdatedTime())
|
||||
if err != nil {
|
||||
t.Fatalf("Error converting proto to timestamp: %v", err)
|
||||
}
|
||||
// Verify it is a project updated after it was created
|
||||
// TODO: This is currently failing.
|
||||
//assert.True(gotUpdateTime.After(projCreated), "Updated project should have been updated after it's creation. Was updated %v, which is after %v", gotUpdateTime, projCreated)
|
||||
_ = gotUpdateTime
|
||||
_ = projCreated
|
||||
|
||||
// Clear all values which are hard to compare against.
|
||||
got.Item.CreatedTime, got.Item.UpdatedTime, tc.res.Item.CreatedTime, tc.res.Item.UpdatedTime = nil, nil, nil, nil
|
||||
}
|
||||
assert.True(proto.Equal(got, tc.res), "UpdateProject(%q) got response %q, wanted %q", req, got, tc.res)
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue