Skip to content

Commit 1fa9990

Browse files
committed
chore: lint fix
1 parent 455804d commit 1fa9990

2 files changed

Lines changed: 52 additions & 84 deletions

File tree

internal/auth0/quickstart.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -553,9 +553,9 @@ var QuickstartConfigs = map[string]AppConfig{
553553
Strategy: FileOutputStrategy{Path: ".env", Format: "dotenv"},
554554
},
555555

556-
// ==========================================
556+
// ==========================================.
557557
// Native / Mobile Applications
558-
// ==========================================
558+
// ==========================================.
559559
"native:flutter:none": {
560560
EnvValues: map[string]string{
561561
"domain": DetectionSub,

internal/cli/quickstarts.go

Lines changed: 50 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ func setupQuickstartCmdExperimental(cli *cli) *cobra.Command {
705705
return fmt.Errorf("failed to get quickstart configuration: %w", err)
706706
}
707707

708-
// Validate the input type against QuickstartConfigs
708+
// Validate the input type against QuickstartConfigs.
709709
config, exists := auth0.QuickstartConfigs[qsConfigKey]
710710
if !exists {
711711
return fmt.Errorf("unsupported quickstart arguments: %s. Supported types: %v", qsConfigKey, getSupportedQuickstartTypes())
@@ -732,7 +732,7 @@ func setupQuickstartCmdExperimental(cli *cli) *cobra.Command {
732732
if err != nil {
733733
return fmt.Errorf("failed to get tenant: %w", err)
734734
}
735-
// Generate the .env file
735+
// Generate the .env file.
736736
envFileName, _, err := GenerateAndWriteQuickstartConfig(&config.Strategy, config.EnvValues, tenant.Domain, client)
737737
if err != nil {
738738
return fmt.Errorf("failed to generate .env file: %w", err)
@@ -753,20 +753,20 @@ func setupQuickstartCmdExperimental(cli *cli) *cobra.Command {
753753

754754
func printClientDetails(client *management.Client, port int, configFileLocation string, isAPI bool) {
755755
if isAPI {
756-
// Print API-related messages
756+
// Print API-related messages.
757757
fmt.Printf(" An API application \"%s\" has been created and registered\n\n", *client.Name)
758758
fmt.Println(" You can manage your API from here:")
759759
fmt.Printf(" https://manage.auth0.com/dashboard/#/apis/%s/settings\n", client.GetClientID())
760760
} else {
761-
// Print application-related messages
761+
// Print application-related messages.
762762
fmt.Printf(" An application \"%s\" has been created in the management console\n", *client.Name)
763763
fmt.Printf(" Client ID: %s\n\n", client.GetClientID())
764764

765-
// Print management console link
765+
// Print management console link.
766766
fmt.Println(" You can manage your application from here:")
767767
fmt.Printf(" https://manage.auth0.com/dashboard/#/applications/%s/settings\n\n", client.GetClientID())
768768

769-
// Print callback URLs
769+
// Print callback URLs.
770770
if client.Callbacks != nil && len(client.GetCallbacks()) > 0 {
771771
fmt.Println(" Callback URLs registered in Auth0 Dashboard:")
772772
for _, callback := range client.GetCallbacks() {
@@ -775,7 +775,7 @@ func printClientDetails(client *management.Client, port int, configFileLocation
775775
fmt.Println()
776776
}
777777

778-
// Print logout URLs
778+
// Print logout URLs.
779779
if client.AllowedLogoutURLs != nil && len(client.GetAllowedLogoutURLs()) > 0 {
780780
fmt.Println("✓ Logout URLs registered:")
781781
for _, logoutURL := range client.GetAllowedLogoutURLs() {
@@ -784,12 +784,12 @@ func printClientDetails(client *management.Client, port int, configFileLocation
784784
fmt.Println()
785785
}
786786

787-
// Print config file location
787+
// Print config file location.
788788
fmt.Printf("✓ Config file created: %s\n\n", configFileLocation)
789789
}
790790
}
791791

792-
// Helper function to get supported quickstart types
792+
// Helper function to get supported quickstart types.
793793
func getSupportedQuickstartTypes() []string {
794794
var types []string
795795
for key := range auth0.QuickstartConfigs {
@@ -798,7 +798,7 @@ func getSupportedQuickstartTypes() []string {
798798
return types
799799
}
800800

801-
// For cleaner readability, you might consider extracting this anonymous struct into a named type (e.g., type SetupInputs struct {...})
801+
// For cleaner readability, you might consider extracting this anonymous struct into a named type (e.g., type SetupInputs struct {...}).
802802
func getQuickstartConfigKey(inputs struct {
803803
Name string
804804
App bool
@@ -864,9 +864,9 @@ func getQuickstartConfigKey(inputs struct {
864864
}
865865
}
866866

867-
// Handle application creation inputs
867+
// Handle application creation inputs.
868868
if inputs.App {
869-
// Prompt for --type if not provided
869+
// Prompt for --type if not provided.
870870
if inputs.Type == "" {
871871
types := []string{"spa", "regular", "native", "m2m"}
872872
q := prompt.SelectInput("type", "Select the application type", "", types, "m2m", true)
@@ -875,7 +875,7 @@ func getQuickstartConfigKey(inputs struct {
875875
}
876876
}
877877

878-
// Prompt for --framework if not provided
878+
// Prompt for --framework if not provided.
879879
if inputs.Framework == "" {
880880
frameworks := []string{"react", "angular", "vue", "svelte", "nextjs", "nuxt", "flutter", "express", "django", "spring-boot", "none"}
881881
q := prompt.SelectInput("framework", "Select the framework", "", frameworks, "none", true)
@@ -884,50 +884,33 @@ func getQuickstartConfigKey(inputs struct {
884884
}
885885
}
886886

887-
// Prompt for --build-tool if not provided (optional)
887+
// Prompt for --build-tool if not provided (optional).
888888
if inputs.BuildTool == "" {
889889
buildTools := []string{"vite", "webpack", "cra", "none"}
890890
q := prompt.SelectInput("build-tool", "Select the build tool (optional)", "", buildTools, "none", false)
891891
if err := prompt.AskOne(q, &inputs.BuildTool); err != nil {
892892
return "", inputs, fmt.Errorf("failed to select build tool: %v", err)
893893
}
894894
}
895-
896-
// // Set default values
897-
// if inputs.Name == "" {
898-
// inputs.Name = "My App"
899-
// }
900-
// if inputs.Port == 0 {
901-
// inputs.Port = 3000
902-
// }
903-
// if inputs.CallbackURL == "" {
904-
// inputs.CallbackURL = fmt.Sprintf("http://localhost:%d/callback", inputs.Port)
905-
// }
906-
// if inputs.LogoutURL == "" {
907-
// inputs.LogoutURL = fmt.Sprintf("http://localhost:%d/logout", inputs.Port)
908-
// }
909-
// if inputs.WebOriginURL == "" {
910-
// inputs.WebOriginURL = fmt.Sprintf("http://localhost:%d", inputs.Port)
911-
// }
912895
}
913896

914-
// Handle API creation inputs
897+
// Handle API creation inputs.
915898
if inputs.API {
916-
// Prompt for --identifier or --audience if not provided
899+
// Prompt for --identifier or --audience if not provided.
917900
if inputs.Identifier == "" && inputs.Audience == "" {
918-
// name, message, help, defaultValue, required
901+
// Name, message, help, defaultValue, required.
919902
q := prompt.TextInput("identifier", "Enter the API identifier (or audience)", "", "", true)
920903
if err := prompt.AskOne(q, &inputs.Identifier); err != nil {
921904
return "", inputs, fmt.Errorf("failed to enter API identifier: %v", err)
922905
}
923906
}
924907

925-
// Use --audience as an alias for --identifier if provided
908+
// Use --audience as an alias for --identifier if provided.
926909
if inputs.Identifier == "" {
927910
inputs.Identifier = inputs.Audience
928911
}
929912

930-
// Prompt for --signing-alg if not provided
913+
// Prompt for --signing-alg if not provided.
931914
if inputs.SigningAlg == "" {
932915
signingAlgs := []string{"RS256", "PS256", "HS256"}
933916
q := prompt.SelectInput("signing-alg", "Select the signing algorithm", "", signingAlgs, "RS256", true)
@@ -936,15 +919,15 @@ func getQuickstartConfigKey(inputs struct {
936919
}
937920
}
938921

939-
// Prompt for --scopes if not provided
922+
// Prompt for --scopes if not provided.
940923
if inputs.Scopes == "" {
941924
q := prompt.TextInput("scopes", "Enter the scopes (comma-separated)", "", "", false)
942925
if err := prompt.AskOne(q, &inputs.Scopes); err != nil {
943926
return "", inputs, fmt.Errorf("failed to enter scopes: %v", err)
944927
}
945928
}
946929

947-
// Prompt for --token-lifetime if not provided
930+
// Prompt for --token-lifetime if not provided.
948931
if inputs.TokenLifetime == "" {
949932
q := prompt.TextInput("token-lifetime", "Enter the token lifetime (in seconds)", "", "86400", true)
950933
if err := prompt.AskOne(q, &inputs.TokenLifetime); err != nil {
@@ -957,8 +940,7 @@ func getQuickstartConfigKey(inputs struct {
957940
}
958941
}
959942

960-
// Construct the key to query QuickstartConfigs
961-
// Fallback to "none" if build tool wasn't asked/selected to match the config map keys
943+
// Fallback to "none" if build tool wasn't asked/selected to match the config map keys.
962944
buildToolKey := inputs.BuildTool
963945
if buildToolKey == "" {
964946
buildToolKey = "none"
@@ -987,7 +969,7 @@ func generateClients(input struct {
987969
OfflineAccess bool
988970
MetaData map[string]interface{}
989971
}, reqParams auth0.RequestParams) ([]*management.Client, error) {
990-
// Prompt for the Name field if missing
972+
// Prompt for the Name field if missing.
991973

992974
if input.Name == "" {
993975
input.Name = "My App"
@@ -998,7 +980,7 @@ func generateClients(input struct {
998980
return nil, fmt.Errorf("failed to enter application name: %v", err)
999981
}
1000982

1001-
// Default values for the client
983+
// Default values for the client.
1002984
input.SigningAlg = "RS256"
1003985
if input.MetaData == nil {
1004986
input.MetaData = map[string]interface{}{
@@ -1007,7 +989,7 @@ func generateClients(input struct {
1007989
}
1008990

1009991
oidcConformant := true
1010-
// Create the base client
992+
// Create the base client.
1011993
baseClient := &management.Client{
1012994
Name: &input.Name,
1013995
AppType: &reqParams.AppType,
@@ -1020,11 +1002,11 @@ func generateClients(input struct {
10201002
ClientMetadata: &input.MetaData,
10211003
}
10221004

1023-
// Generate the list of clients
1005+
// Generate the list of clients.
10241006
var clients []*management.Client
10251007
clients = append(clients, baseClient)
10261008

1027-
// Add an additional client if both App and Api are true
1009+
// Add an additional client if both App and Api are true.
10281010
if input.API {
10291011
resourceServerAppType := "resource_server"
10301012
q := prompt.TextInput("api_identifier", "Enter API identifier(audience)", "", "", true)
@@ -1049,72 +1031,59 @@ func generateClients(input struct {
10491031
}
10501032

10511033
func replaceDetectionSub(envValues map[string]string, tenantDomain string, client *management.Client) map[string]string {
1052-
// Create a new map to store the updated values
1034+
// Create a new map to store the updated values.
10531035
updatedEnvValues := make(map[string]string)
10541036

10551037
for key, value := range envValues {
1056-
// If the value is not DETECTION_SUB, keep it as is and continue
1038+
// If the value is not DETECTION_SUB, keep it as is and continue.
10571039
if value != "DETECTION_SUB" {
10581040
updatedEnvValues[key] = value
10591041
continue
10601042
}
10611043

1062-
// Group keys by the type of replacement they require
1044+
// Group keys by the type of replacement they require.
10631045
switch key {
1064-
1065-
// ==========================================
1066-
// Tenant Domain Replacements
1067-
// ==========================================
1046+
// ==========================================.
10681047
case "VITE_AUTH0_DOMAIN", "AUTH0_DOMAIN", "domain", "NUXT_AUTH0_DOMAIN",
10691048
"auth0.domain", "Auth0:Domain", "auth0:Domain", "auth0_domain",
10701049
"EXPO_PUBLIC_AUTH0_DOMAIN":
10711050
updatedEnvValues[key] = tenantDomain
10721051

1073-
// Express SDK specifically requires the https:// prefix
1052+
// Express SDK specifically requires the https:// prefix.
10741053
case "ISSUER_BASE_URL":
10751054
updatedEnvValues[key] = "https://" + tenantDomain
10761055

1077-
// Spring Boot okta issuer specifically requires https:// and a trailing slash
1056+
// Spring Boot okta issuer specifically requires https:// and a trailing slash.
10781057
case "okta.oauth2.issuer":
10791058
updatedEnvValues[key] = "https://" + tenantDomain + "/"
10801059

1081-
// ==========================================
1082-
// Client ID Replacements
1083-
// ==========================================
1060+
// ==========================================.
10841061
case "VITE_AUTH0_CLIENT_ID", "AUTH0_CLIENT_ID", "clientId", "NUXT_AUTH0_CLIENT_ID",
10851062
"CLIENT_ID", "auth0.clientId", "okta.oauth2.client-id", "Auth0:ClientId",
10861063
"auth0:ClientId", "auth0_client_id", "EXPO_PUBLIC_AUTH0_CLIENT_ID":
10871064
updatedEnvValues[key] = client.GetClientID()
10881065

1089-
// ==========================================
1090-
// Client Secret Replacements
1091-
// ==========================================
1066+
// ==========================================.
10921067
case "AUTH0_CLIENT_SECRET", "NUXT_AUTH0_CLIENT_SECRET", "auth0.clientSecret",
10931068
"okta.oauth2.client-secret", "Auth0:ClientSecret", "auth0:ClientSecret",
10941069
"auth0_client_secret":
10951070
updatedEnvValues[key] = client.GetClientSecret()
10961071

1097-
// ==========================================
1098-
// App Secrets / Session Cookies (Placeholders)
1099-
// ==========================================
1072+
// ==========================================.
11001073
case "AUTH0_SECRET", "NUXT_AUTH0_SESSION_SECRET", "SESSION_SECRET",
11011074
"SECRET", "AUTH0_SESSION_ENCRYPTION_KEY", "AUTH0_COOKIE_SECRET":
11021075
// Inject a dummy secret placeholder for the user to replace,
11031076
// or replace this string with a crypto/rand generator if preferred.
11041077
updatedEnvValues[key] = "a_long_random_secret_string_replace_me"
11051078

1106-
// ==========================================
1107-
// App Base URLs and Redirect URIs
1108-
// ==========================================
1079+
// ==========================================.
11091080
case "APP_BASE_URL", "NUXT_AUTH0_APP_BASE_URL", "BASE_URL":
1110-
updatedEnvValues[key] = "http://localhost:3000" // Default backend port
1081+
updatedEnvValues[key] = "http://localhost:3000" updatedEnvValues[key] = "http://localhost:3000" // Default backend port.
11111082

11121083
case "AUTH0_REDIRECT_URI", "AUTH0_CALLBACK_URL":
11131084
updatedEnvValues[key] = "http://localhost:3000/callback"
11141085

1115-
// ==========================================
1116-
// Fallback
1117-
// ==========================================
1086+
// ==========================================.
11181087
default:
11191088
updatedEnvValues[key] = value
11201089
}
@@ -1123,33 +1092,32 @@ func replaceDetectionSub(envValues map[string]string, tenantDomain string, clien
11231092
return updatedEnvValues
11241093
}
11251094

1126-
// FileOutputStrategy defines where and how a config file should be written
1127-
// Map the config keys to their required file output definitions based on the matrix
1095+
// Map the config keys to their required file output definitions based on the matrix.
11281096

11291097
// GenerateAndWriteQuickstartConfig takes the selected stack, resolves the dynamic values,
11301098
// and writes them to the appropriate file in the Current Working Directory (CWD).
11311099
// GenerateAndWriteQuickstartConfig takes the selected stack, resolves the dynamic values,
11321100
// and writes them to the appropriate file in the Current Working Directory (CWD).
11331101
// It returns the generated file name, the file path, and an error (if any).
11341102
func GenerateAndWriteQuickstartConfig(strategy *auth0.FileOutputStrategy, envValues map[string]string, tenantDomain string, client *management.Client) (string, string, error) {
1135-
// 1. Resolve the environment variables using the previously defined function
1103+
// 1. Resolve the environment variables using the previously defined function.
11361104
resolvedEnv := replaceDetectionSub(envValues, tenantDomain, client)
11371105

1138-
// 2. Determine output file path and format
1106+
// 2. Determine output file path and format.
11391107
if strategy == nil {
1140-
// Fallback to a standard .env in the project root if for some reason it's missing
1108+
// Fallback to a standard .env in the project root if for some reason it's missing.
11411109
strategy = &auth0.FileOutputStrategy{Path: ".env", Format: "dotenv"}
11421110
}
11431111

1144-
// 3. Ensure the directory path exists (e.g., creating src/environments/ if it doesn't exist)
1112+
// 3. Ensure the directory path exists (e.g., creating src/environments/ if it doesn't exist).
11451113
dir := filepath.Dir(strategy.Path)
11461114
if dir != "." {
11471115
if err := os.MkdirAll(dir, 0755); err != nil {
11481116
return "", "", fmt.Errorf("failed to create directory structure %s: %w", dir, err)
11491117
}
11501118
}
11511119

1152-
// 4. Format the file content based on the target framework's requirement
1120+
// 4. Format the file content based on the target framework's requirement.
11531121
var contentBuilder strings.Builder
11541122

11551123
switch strategy.Format {
@@ -1178,10 +1146,10 @@ func GenerateAndWriteQuickstartConfig(strategy *auth0.FileOutputStrategy, envVal
11781146
contentBuilder.WriteString("};\n")
11791147

11801148
case "json":
1181-
// C# appsettings.json expects nested JSON: {"Auth0": {"Domain": "...", "ClientId": "..."}}
1149+
// C# appsettings.json expects nested JSON: {"Auth0": {"Domain": "...", "ClientId": "..."}}.
11821150
auth0Section := make(map[string]string)
11831151
for key, val := range resolvedEnv {
1184-
// Strip the "Auth0:" prefix used in the map to create clean JSON keys
1152+
// Strip the "Auth0:" prefix used in the map to create clean JSON keys.
11851153
cleanKey := strings.TrimPrefix(key, "Auth0:")
11861154
auth0Section[cleanKey] = val
11871155
}
@@ -1197,7 +1165,7 @@ func GenerateAndWriteQuickstartConfig(strategy *auth0.FileOutputStrategy, envVal
11971165
contentBuilder.Write(bytes)
11981166

11991167
case "xml":
1200-
// ASP.NET OWIN Web.config
1168+
// ASP.NET OWIN Web.config.
12011169
contentBuilder.WriteString("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
12021170
contentBuilder.WriteString("<configuration>\n")
12031171
contentBuilder.WriteString(" <appSettings>\n")
@@ -1208,12 +1176,12 @@ func GenerateAndWriteQuickstartConfig(strategy *auth0.FileOutputStrategy, envVal
12081176
contentBuilder.WriteString("</configuration>\n")
12091177
}
12101178

1211-
// 5. Write the generated content to disk
1179+
// 5. Write the generated content to disk.
12121180
if err := os.WriteFile(strategy.Path, []byte(contentBuilder.String()), 0600); err != nil {
12131181
return "", "", fmt.Errorf("failed to write config file %s: %w", strategy.Path, err)
12141182
}
12151183

1216-
// 6. Extract the base file name from the path and return both
1184+
// 6. Extract the base file name from the path and return both.
12171185
fileName := filepath.Base(strategy.Path)
12181186

12191187
return fileName, strategy.Path, nil

0 commit comments

Comments
 (0)