Skip to content

Commit

Permalink
Allow hosted projects to be exported with registry export (#970)
Browse files Browse the repository at this point in the history
  • Loading branch information
timburks authored Jan 25, 2023
1 parent 989942a commit 20a0551
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cmd/registry/cmd/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (h *deleteHandler) traverse() error {
}

if project, err := names.ParseProject(name); err == nil {
return core.GetProject(ctx, adminClient, project, h.projectHandler())
return core.GetProject(ctx, adminClient, project, false, h.projectHandler())
} else if api, err := names.ParseApi(name); err == nil {
return core.GetAPI(ctx, client, api, h.apiHandler())
} else if deployment, err := names.ParseDeployment(name); err == nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/registry/cmd/export/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (h *exportHandler) traverse() error {
}

if project, err := names.ParseProject(pattern); err == nil {
return core.GetProject(ctx, adminClient, project, h.projectHandler())
return core.GetProject(ctx, adminClient, project, true, h.projectHandler())
} else if api, err := names.ParseApi(pattern); err == nil {
return core.GetAPI(ctx, client, api, h.apiHandler())
} else if deployment, err := names.ParseDeployment(pattern); err == nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/registry/cmd/get/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (h *getHandler) traverse() error {
}

if project, err := names.ParseProject(name); err == nil {
return core.GetProject(ctx, adminClient, project, h.projectHandler())
return core.GetProject(ctx, adminClient, project, false, h.projectHandler())
} else if api, err := names.ParseApi(name); err == nil {
return core.GetAPI(ctx, client, api, h.apiHandler())
} else if deployment, err := names.ParseDeployment(name); err == nil {
Expand Down
9 changes: 8 additions & 1 deletion cmd/registry/core/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,24 @@ import (
"github.com/apigee/registry/gapic"
"github.com/apigee/registry/rpc"
"github.com/apigee/registry/server/registry/names"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"
)

func GetProject(ctx context.Context,
client *gapic.AdminClient,
name names.Project,
allowUnavailable bool,
handler ProjectHandler) error {
project, err := client.GetProject(ctx, &rpc.GetProjectRequest{
Name: name.String(),
})
if err != nil {
if err != nil && status.Code(err) == codes.Unimplemented && allowUnavailable {
// If the admin service is unavailable, provide a placeholder project.
// If the project is invalid, downstream actions will fail.
project = &rpc.Project{Name: name.String()}
} else if err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/registry/patch/patch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func TestProjectPatches(t *testing.T) {
protocmp.Transform(),
protocmp.IgnoreFields(new(rpc.Project), "create_time", "update_time"),
}
err = core.GetProject(ctx, adminClient, projectName,
err = core.GetProject(ctx, adminClient, projectName, false,
func(project *rpc.Project) error {
if !cmp.Equal(test.message, project, opts) {
t.Errorf("GetDiff returned unexpected diff (-want +got):\n%s", cmp.Diff(test.message, project, opts))
Expand Down

0 comments on commit 20a0551

Please sign in to comment.