Skip to content

Commit

Permalink
feat: rename iamspanner.Server to iampanner.IAMServer
Browse files Browse the repository at this point in the history
To make the server more ergonomic for struct embedding into other
servers.
  • Loading branch information
odsod committed May 7, 2021
1 parent 245c982 commit 36f28b6
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion iamexample/authorization.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type Authorization struct {
iam.UnimplementedIAMPolicyServer
admin.UnimplementedIAMServer
Next iamexamplev1.FreightServiceServer
IAM *iamspanner.Server
IAM *iamspanner.IAMServer
}

var _ iamexamplev1.FreightServiceServer = &Authorization{}
Expand Down
2 changes: 1 addition & 1 deletion iamexample/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

// Server implements iamexamplev1.FreightServiceServer.
type Server struct {
IAM *iamspanner.Server
IAM *iamspanner.IAMServer
Spanner *spanner.Client
Config Config
}
Expand Down
38 changes: 19 additions & 19 deletions iamspanner/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
"google.golang.org/protobuf/proto"
)

// Server is a Spanner implementation of the iam.IAMPolicyServer interface.
type Server struct {
// IAMServer is a Spanner implementation of the iam.IAMPolicyServer interface.
type IAMServer struct {
iam.UnimplementedIAMPolicyServer
admin.UnimplementedIAMServer
client *spanner.Client
Expand All @@ -49,8 +49,8 @@ func NewServer(
roles *iamregistry.Roles,
memberResolver iammember.Resolver,
config ServerConfig,
) (*Server, error) {
s := &Server{
) (*IAMServer, error) {
s := &IAMServer{
client: client,
config: config,
roles: roles,
Expand All @@ -60,7 +60,7 @@ func NewServer(
}

// SetIamPolicy implements iam.IAMPolicyServer.
func (s *Server) SetIamPolicy(
func (s *IAMServer) SetIamPolicy(
ctx context.Context,
request *iam.SetIamPolicyRequest,
) (*iam.Policy, error) {
Expand Down Expand Up @@ -96,7 +96,7 @@ func (s *Server) SetIamPolicy(
}

// GetIamPolicy implements iam.IAMPolicyServer.
func (s *Server) GetIamPolicy(
func (s *IAMServer) GetIamPolicy(
ctx context.Context,
request *iam.GetIamPolicyRequest,
) (*iam.Policy, error) {
Expand All @@ -106,7 +106,7 @@ func (s *Server) GetIamPolicy(
}

// TestIamPermissions implements iam.IAMPolicyServer.
func (s *Server) TestIamPermissions(
func (s *IAMServer) TestIamPermissions(
ctx context.Context,
request *iam.TestIamPermissionsRequest,
) (*iam.TestIamPermissionsResponse, error) {
Expand Down Expand Up @@ -145,7 +145,7 @@ func (s *Server) TestIamPermissions(
}

// TestPermissionOnResource tests if the caller has the specified permission on the specified resource.
func (s *Server) TestPermissionOnResource(
func (s *IAMServer) TestPermissionOnResource(
ctx context.Context,
permission string,
resource string,
Expand All @@ -158,7 +158,7 @@ func (s *Server) TestPermissionOnResource(
}

// TestPermissionOnResources tests if the caller has the specified permission on the specified resources.
func (s *Server) TestPermissionOnResources(
func (s *IAMServer) TestPermissionOnResources(
ctx context.Context,
permission string,
resources []string,
Expand Down Expand Up @@ -192,7 +192,7 @@ func (s *Server) TestPermissionOnResources(
}

// ReadRolesBoundToMembersAndResources reads all roles bound to the provided members and resources.
func (s *Server) ReadRolesBoundToMembersAndResources(
func (s *IAMServer) ReadRolesBoundToMembersAndResources(
ctx context.Context,
members []string,
resources []string,
Expand All @@ -206,7 +206,7 @@ func (s *Server) ReadRolesBoundToMembersAndResources(
// ReadRolesBoundToMembersAndResourcesInTransaction reads all roles bound to members and resources
// within the provided Spanner transaction.
// Also considers roles bound to parent resources.
func (s *Server) ReadRolesBoundToMembersAndResourcesInTransaction(
func (s *IAMServer) ReadRolesBoundToMembersAndResourcesInTransaction(
ctx context.Context,
tx ReadTransaction,
members []string,
Expand Down Expand Up @@ -270,7 +270,7 @@ func (s *Server) ReadRolesBoundToMembersAndResourcesInTransaction(
}

// QueryResourcesBoundToMemberAndPermission reads all resources bound to the member and permission.
func (s *Server) QueryResourcesBoundToMemberAndPermission(
func (s *IAMServer) QueryResourcesBoundToMemberAndPermission(
ctx context.Context,
member string,
permission string,
Expand All @@ -282,7 +282,7 @@ func (s *Server) QueryResourcesBoundToMemberAndPermission(

// QueryResourcesBoundToMemberAndPermissionInTransaction reads all resources bound to the member and permission,
// within the provided Spanner transaction.
func (s *Server) QueryResourcesBoundToMemberAndPermissionInTransaction(
func (s *IAMServer) QueryResourcesBoundToMemberAndPermissionInTransaction(
ctx context.Context,
tx ReadTransaction,
member string,
Expand Down Expand Up @@ -320,7 +320,7 @@ func (s *Server) QueryResourcesBoundToMemberAndPermissionInTransaction(
}

// QueryIamPolicyInTransaction queries the IAM policy for a resource within the provided transaction.
func (s *Server) QueryIamPolicyInTransaction(
func (s *IAMServer) QueryIamPolicyInTransaction(
ctx context.Context,
tx ReadTransaction,
resource string,
Expand Down Expand Up @@ -369,7 +369,7 @@ func (s *Server) QueryIamPolicyInTransaction(

// ValidateIamPolicyFreshnessInTransaction validates the freshness of an IAM policy for a resource
// within the provided transaction.
func (s *Server) ValidateIamPolicyFreshnessInTransaction(
func (s *IAMServer) ValidateIamPolicyFreshnessInTransaction(
ctx context.Context,
tx ReadTransaction,
resource string,
Expand Down Expand Up @@ -409,7 +409,7 @@ func insertIAMPolicyMutations(resource string, policy *iam.Policy) []*spanner.Mu
return mutations
}

func (s *Server) validateSetIamPolicyRequest(ctx context.Context, request *iam.SetIamPolicyRequest) error {
func (s *IAMServer) validateSetIamPolicyRequest(ctx context.Context, request *iam.SetIamPolicyRequest) error {
var fieldViolations []*errdetails.BadRequest_FieldViolation
if len(request.Resource) == 0 {
fieldViolations = append(fieldViolations, &errdetails.BadRequest_FieldViolation{
Expand All @@ -434,13 +434,13 @@ func (s *Server) validateSetIamPolicyRequest(ctx context.Context, request *iam.S
return nil
}

func (s *Server) logError(ctx context.Context, err error) {
func (s *IAMServer) logError(ctx context.Context, err error) {
if s.config.ErrorHook != nil {
s.config.ErrorHook(ctx, err)
}
}

func (s *Server) handleStorageError(ctx context.Context, err error) error {
func (s *IAMServer) handleStorageError(ctx context.Context, err error) error {
s.logError(ctx, err)
switch code := status.Code(err); code {
case codes.Aborted, codes.Canceled, codes.DeadlineExceeded, codes.Unavailable:
Expand All @@ -450,7 +450,7 @@ func (s *Server) handleStorageError(ctx context.Context, err error) error {
}
}

func (s *Server) resolveMembers(ctx context.Context) ([]string, error) {
func (s *IAMServer) resolveMembers(ctx context.Context) ([]string, error) {
members, err := s.memberResolver.ResolveIAMMembers(ctx)
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions iamspanner/server_roles_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

// GetRole implements admin.IAMServer.
func (s *Server) GetRole(
func (s *IAMServer) GetRole(
ctx context.Context,
request *admin.GetRoleRequest,
) (*admin.Role, error) {
Expand All @@ -23,7 +23,7 @@ func (s *Server) GetRole(
}

// GetRole implements admin.IAMServer.
func (s *Server) getRole(
func (s *IAMServer) getRole(
_ context.Context,
request *getRoleRequest,
) (*admin.Role, error) {
Expand Down
4 changes: 2 additions & 2 deletions iamspanner/server_roles_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

// ListRoles implements admin.IAMServer.
func (s *Server) ListRoles(
func (s *IAMServer) ListRoles(
ctx context.Context,
request *admin.ListRolesRequest,
) (*admin.ListRolesResponse, error) {
Expand All @@ -22,7 +22,7 @@ func (s *Server) ListRoles(
return s.listRoles(ctx, &parsedRequest)
}

func (s *Server) listRoles(
func (s *IAMServer) listRoles(
_ context.Context,
request *listRolesRequest,
) (*admin.ListRolesResponse, error) {
Expand Down
6 changes: 3 additions & 3 deletions iamtest/fixture.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import (

// Fixture is a test fixture with helper methods for IAM testing.
type Fixture struct {
server *iamspanner.Server
server *iamspanner.IAMServer
}

// NewFixture creates a new Fixture for the provided iamspanner.Server.
func NewFixture(server *iamspanner.Server) *Fixture {
// NewFixture creates a new Fixture for the provided iamspanner.IAMServer.
func NewFixture(server *iamspanner.IAMServer) *Fixture {
return &Fixture{server: server}
}

Expand Down

0 comments on commit 36f28b6

Please sign in to comment.