Skip to content

Commit

Permalink
refactor: replace map with session params struct
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaud-dfns committed Oct 28, 2024
1 parent 80c8615 commit 86f305f
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions internal/ssm/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ type TunnelConfig struct {
LocalPort string
}

type SessionParams struct {
SessionId string
TokenValue string
StreamUrl string
}

func CreateSessionInput(cfg TunnelConfig) ssm.StartSessionInput {
reqParams := make(map[string][]string)
reqParams["portNumber"] = []string{cfg.TargetPort}
Expand All @@ -31,11 +37,11 @@ func CreateSessionInput(cfg TunnelConfig) ssm.StartSessionInput {
}
}

func StartTunnelSession(ctx context.Context, cfg TunnelConfig) (map[string]string, error) {
func StartTunnelSession(ctx context.Context, cfg TunnelConfig) (SessionParams, error) {
// Load AWS SDK config
awsCfg, err := config.LoadDefaultConfig(ctx)
if err != nil {
return nil, err
return SessionParams{}, err
}
awsCfg.Region = cfg.SSMRegion

Expand All @@ -46,13 +52,12 @@ func StartTunnelSession(ctx context.Context, cfg TunnelConfig) (map[string]strin
sessionInput := CreateSessionInput(cfg)
sessionResponse, err := ssmClient.StartSession(ctx, &sessionInput)
if err != nil {
return nil, err
return SessionParams{}, err
}

resParams := make(map[string]string)
resParams["SessionId"] = *sessionResponse.SessionId
resParams["TokenValue"] = *sessionResponse.TokenValue
resParams["StreamUrl"] = *sessionResponse.StreamUrl

return resParams, nil
return SessionParams{
SessionId: *sessionResponse.SessionId,
TokenValue: *sessionResponse.TokenValue,
StreamUrl: *sessionResponse.StreamUrl,
}, nil
}

0 comments on commit 86f305f

Please sign in to comment.