Skip to content

[protoc-gen-policy] oneof type is not properly generates policy hepler  #3575

Open
@kvivek1115

Description

@kvivek1115

Describe the bug

  • proto3 oneof type not fully supported by the protoc-gen-policy tool.
  • seems it is calling oneof message attributes directly instead it should get inverted to the interface.

To Reproduce

Steps to reproduce the behavior:

  • Add oneof message types in sample requests.
    eg.
message UpdateOrg {
    string id = 1;
    oneof test {
        string name = 2;
        string admin_key = 3;
    };
    string admin_user = 4;
    string server_id = 5;
    repeated string projects = 6;
}
  • hit compile_go_protobuf_component api.
  • wired & implement all request gateway functions.
  • try rebuild components/automate-gateway
  • it raises any error:
# github.com/chef/automate/api/external/infra_proxy
/src/api/external/infra_proxy/infra_proxy.pb.policy.go:166:14: m.Name undefined (type *request.UpdateOrg has no field or method Name)
/src/api/external/infra_proxy/infra_proxy.pb.policy.go:168:14: m.AdminKey undefined (type *request.UpdateOrg has no field or method AdminKey)
   automate-gateway: Build time: 0m3s
   automate-gateway: Exiting on error

Expected behavior

  • it should simply rebuild the automate-gateway.

Versions (please complete the following information):

  • OS: ubuntu
  • Automate: latest master

Additional context

Add any other context about the problem here.

  • policy code generated for this type:
policy.MapMethodTo("/chef.automate.api.infra_proxy.InfraProxy/UpdateOrg", "infra:infraServers:{server_id}:orgs:{id}", "infra:infraServers:update", "PUT", "/api/v0/infra/servers/{server_id}/orgs/{id}", func(unexpandedResource string, input interface{}) string {
		if m, ok := input.(*request.UpdateOrg); ok {
			return policy.ExpandParameterizedResource(unexpandedResource, func(want string) string {
				switch want {
				case "id":
					return m.Id
				case "name":
					return m.Name
				case "admin_key":
					return m.AdminKey
				case "admin_user":
					return m.AdminUser
				case "server_id":
					return m.ServerId
				default:
					return ""
				}
			})
		}
		return ""

it should be something like

policy.MapMethodTo("/chef.automate.api.infra_proxy.InfraProxy/UpdateOrg", "infra:infraServers:{server_id}:orgs:{id}", "infra:infraServers:update", "PUT", "/api/v0/infra/servers/{server_id}/orgs/{id}", func(unexpandedResource string, input interface{}) string {
		if m, ok := input.(*request.UpdateOrg); ok {
			return policy.ExpandParameterizedResource(unexpandedResource, func(want string) string {
				switch want {
				case "id":
					return m.Id
				case "name":
					return m.GetTest().(*request.UpdateOrg_Name).Name
				case "admin_key":
					return m.GetTest().(*request.UpdateOrg_AdminKey).AdminKey
				case "admin_user":
					return m.AdminUser
				case "server_id":
					return m.ServerId
				default:
					return ""
				}
			})
		}
		return ""
	})

Metadata

Metadata

Assignees

No one assigned

    Labels

    auth-teamanything that needs to be on the auth team boardbug 🐛Something isn't workingneeds-triage

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions