Skip to content

Commit 9175597

Browse files
committed
remove unnecesary pointers
1 parent ee20670 commit 9175597

File tree

3 files changed

+31
-49
lines changed

3 files changed

+31
-49
lines changed

internal/tiger/cmd/service.go

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -618,12 +618,8 @@ Examples:
618618
// OutputService represents a service with computed fields for output
619619
type OutputService struct {
620620
api.Service
621-
ConnectionString *string `json:"connection_string,omitempty" yaml:"connection_string,omitempty"`
622-
Password *string `json:"password,omitempty" yaml:"password,omitempty"`
623-
Role *string `json:"role,omitempty" yaml:"role,omitempty"`
624-
Host *string `json:"host,omitempty" yaml:"host,omitempty"`
625-
Port *int `json:"port,omitempty" yaml:"port,omitempty"`
626-
Database *string `json:"database,omitempty" yaml:"database,omitempty"`
621+
password.ConnectionDetails
622+
ConnectionString string `json:"connection_string,omitempty" yaml:"connection_string,omitempty"`
627623
}
628624

629625
// Convert to JSON to respect omitempty tags, then unmarshal
@@ -693,20 +689,12 @@ func outputServices(cmd *cobra.Command, services []api.Service, format string, w
693689

694690
// outputServiceEnv outputs service details in environment variable format
695691
func outputServiceEnv(service OutputService, output io.Writer) error {
696-
if service.Host != nil {
697-
fmt.Fprintf(output, "PGHOST=%s\n", *service.Host)
698-
}
699-
if service.Role != nil {
700-
fmt.Fprintf(output, "PGUSER=%s\n", *service.Role)
701-
}
702-
if service.Password != nil {
703-
fmt.Fprintf(output, "PGPASSWORD=%s\n", *service.Password)
704-
}
705-
if service.Database != nil {
706-
fmt.Fprintf(output, "PGDATABASE=%s\n", *service.Database)
707-
}
708-
if service.Port != nil {
709-
fmt.Fprintf(output, "PGPORT=%d\n", *service.Port)
692+
fmt.Fprintf(output, "PGHOST=%s\n", service.Host)
693+
fmt.Fprintf(output, "PGPORT=%d\n", service.Port)
694+
fmt.Fprintf(output, "PGDATABASE=%s\n", service.Database)
695+
fmt.Fprintf(output, "PGUSER=%s\n", service.Role)
696+
if service.Password != "" {
697+
fmt.Fprintf(output, "PGPASSWORD=%s\n", service.Password)
710698
}
711699
return nil
712700
}
@@ -788,13 +776,13 @@ func outputServiceTable(service OutputService, output io.Writer) error {
788776
}
789777

790778
// Output password if available
791-
if service.Password != nil {
792-
table.Append("Password", *service.Password)
779+
if service.Password != "" {
780+
table.Append("Password", service.Password)
793781
}
794782

795783
// Output connection string if available
796-
if service.ConnectionString != nil {
797-
table.Append("Connection String", *service.ConnectionString)
784+
if service.ConnectionString != "" {
785+
table.Append("Connection String", service.ConnectionString)
798786
}
799787

800788
return table.Render()
@@ -813,7 +801,7 @@ func outputServicesTable(services []OutputService, output io.Writer) error {
813801
util.DerefStr(service.ServiceType),
814802
util.Deref(service.RegionCode),
815803
formatTimePtr(service.Created),
816-
util.Deref(service.ConnectionString),
804+
service.ConnectionString,
817805
)
818806
}
819807

@@ -844,21 +832,15 @@ func prepareServiceForOutput(service api.Service, withPassword bool, output io.W
844832
fmt.Fprintf(output, "⚠️ Warning: Failed to get connection details: %v\n", err)
845833
}
846834
} else {
847-
outputSvc.Role = &connectionDetails.Role
848-
outputSvc.Host = &connectionDetails.Host
849-
outputSvc.Port = &connectionDetails.Port
850-
outputSvc.Database = &connectionDetails.Database
851-
if connectionDetails.Password != "" {
852-
outputSvc.Password = &connectionDetails.Password
853-
}
835+
outputSvc.ConnectionDetails = *connectionDetails
854836
}
855837

856838
if connectionString, err := password.BuildConnectionString(service, opts); err != nil {
857839
if output != nil {
858840
fmt.Fprintf(output, "⚠️ Warning: Failed to get connection string: %v\n", err)
859841
}
860842
} else {
861-
outputSvc.ConnectionString = &connectionString
843+
outputSvc.ConnectionString = connectionString
862844
}
863845

864846
return outputSvc

internal/tiger/cmd/service_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -867,18 +867,18 @@ func TestPrepareServiceForOutput_WithoutPassword(t *testing.T) {
867867
outputSvc := prepareServiceForOutput(service, false, cmd.ErrOrStderr())
868868

869869
// Verify that password is removed
870-
if outputSvc.Service.InitialPassword != nil {
870+
if outputSvc.InitialPassword != nil {
871871
t.Error("Expected InitialPassword to be nil when withPassword=false")
872872
}
873-
if outputSvc.Password != nil {
874-
t.Error("Expected Password to be nil when withPassword=false")
873+
if outputSvc.Password != "" {
874+
t.Error("Expected Password to be empty when withPassword=false")
875875
}
876876

877877
// Verify that other fields are preserved
878-
if outputSvc.Service.ServiceId == nil || *outputSvc.Service.ServiceId != serviceID {
878+
if outputSvc.ServiceId == nil || *outputSvc.ServiceId != serviceID {
879879
t.Error("Expected service_id to be preserved")
880880
}
881-
if outputSvc.Service.Name == nil || *outputSvc.Service.Name != serviceName {
881+
if outputSvc.Name == nil || *outputSvc.Name != serviceName {
882882
t.Error("Expected name to be preserved")
883883
}
884884
}
@@ -911,18 +911,18 @@ func TestPrepareServiceForOutput_WithPassword(t *testing.T) {
911911
outputSvc := prepareServiceForOutput(service, true, cmd.ErrOrStderr())
912912

913913
// Verify that password is preserved
914-
if outputSvc.Service.InitialPassword != nil {
914+
if outputSvc.InitialPassword != nil {
915915
t.Error("Expected InitialPassword to be nil when withPassword=true")
916916
}
917-
if outputSvc.Password == nil || *outputSvc.Password != initialPassword {
917+
if outputSvc.Password == "" || outputSvc.Password != initialPassword {
918918
t.Error("Expected Password to be preserved when withPassword=true")
919919
}
920920

921921
// Verify that other fields are preserved
922-
if outputSvc.Service.ServiceId == nil || *outputSvc.Service.ServiceId != serviceID {
922+
if outputSvc.ServiceId == nil || *outputSvc.ServiceId != serviceID {
923923
t.Error("Expected service_id to be preserved")
924924
}
925-
if outputSvc.Service.Name == nil || *outputSvc.Service.Name != serviceName {
925+
if outputSvc.Name == nil || *outputSvc.Name != serviceName {
926926
t.Error("Expected name to be preserved")
927927
}
928928
}
@@ -963,8 +963,8 @@ func TestSanitizeServicesForOutput(t *testing.T) {
963963
if service.InitialPassword != nil {
964964
t.Errorf("Expected InitialPassword to be nil in sanitized service %d", i)
965965
}
966-
if service.Password != nil {
967-
t.Errorf("Expected Password to be nil in sanitized service %d", i)
966+
if service.Password != "" {
967+
t.Errorf("Expected Password to be empty in sanitized service %d", i)
968968
}
969969

970970
// Verify that other fields are preserved

internal/tiger/password/connection.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ type ConnectionDetailsOptions struct {
4444
}
4545

4646
type ConnectionDetails struct {
47-
Role string
48-
Password string
49-
Host string
50-
Port int
51-
Database string
47+
Role string `json:"role,omitempty" yaml:"role,omitempty"`
48+
Password string `json:"password,omitempty" yaml:"password,omitempty"`
49+
Host string `json:"host,omitempty" yaml:"host,omitempty"`
50+
Port int `json:"port,omitempty" yaml:"port,omitempty"`
51+
Database string `json:"database,omitempty" yaml:"database,omitempty"`
5252
}
5353

5454
func GetConnectionDetails(service api.Service, opts ConnectionDetailsOptions) (*ConnectionDetails, error) {

0 commit comments

Comments
 (0)