-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [PLG-2651]: CLI Refactoring + Telemetry setup (#52)
* fix: CLI Refactoring + Telemetry setup * feat: added events for update * fix: added account id as default * fix: reverted drone ui * fix: updated accounts endpoint
- Loading branch information
1 parent
9c9af63
commit 5204237
Showing
25 changed files
with
946 additions
and
560 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package account | ||
|
||
import ( | ||
"fmt" | ||
"github.com/urfave/cli/v2" | ||
"harness/client" | ||
"harness/defaults" | ||
. "harness/shared" | ||
"harness/utils" | ||
) | ||
|
||
func GetAccountDetails(ctx *cli.Context) error { | ||
// Getting the account details | ||
var baseURL = utils.GetNGBaseURL(ctx) | ||
accountsEndpoint := defaults.ACCOUNTS_ENDPOINT + CliCdRequestData.Account | ||
url := utils.GetUrlWithQueryParams("", baseURL, accountsEndpoint, map[string]string{ | ||
"accountIdentifier": CliCdRequestData.Account, | ||
}) | ||
resp, err := client.Get(url, CliCdRequestData.AuthToken) | ||
if err != nil { | ||
fmt.Printf("Response status: %s \n", resp.Status) | ||
fmt.Printf("Response code: %s \n", resp.Code) | ||
fmt.Printf("Response resource: %s \n", resp.Resource) | ||
fmt.Printf("Response messages: %s \n", resp.Messages) | ||
return nil | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package auth | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"github.com/urfave/cli/v2" | ||
"harness/defaults" | ||
. "harness/shared" | ||
"harness/telemetry" | ||
"harness/types" | ||
. "harness/utils" | ||
"os" | ||
) | ||
|
||
func Login(ctx *cli.Context) (err error) { | ||
|
||
fmt.Println("Welcome to Harness CLI!") | ||
PromptAccountDetails(ctx) | ||
SaveCredentials(ctx, true) | ||
loginError := GetAccountDetails(ctx) | ||
|
||
if loginError != nil { | ||
telemetry.Track(telemetry.TrackEventInfoPayload{EventName: telemetry.LOGIN_FAILED, UserId: CliCdRequestData.UserId}, map[string]interface{}{ | ||
"accountId": CliCdRequestData.Account, | ||
"userId": CliCdRequestData.UserId, | ||
}) | ||
return nil | ||
} | ||
GetUserDetails(ctx) | ||
SaveCredentials(ctx, false) | ||
telemetry.Track(telemetry.TrackEventInfoPayload{EventName: telemetry.LOGIN_SUCCESS, UserId: CliCdRequestData.UserId}, map[string]interface{}{ | ||
"accountId": CliCdRequestData.Account, | ||
"userId": CliCdRequestData.UserId, | ||
}) | ||
|
||
return nil | ||
} | ||
|
||
func HydrateCredsFromPersistence(params ...interface{}) { | ||
c := params[0].(*cli.Context) | ||
var hydrateOnlyURL = false | ||
|
||
if len(params) > 1 { | ||
if value, ok := params[1].(bool); ok { | ||
hydrateOnlyURL = value | ||
} | ||
} | ||
if CliCdRequestData.AuthToken != "" && CliCdRequestData.Account != "" && !hydrateOnlyURL { | ||
return | ||
} | ||
|
||
exactFilePath := GetUserHomePath() + "/" + defaults.SECRETS_STORE_PATH | ||
credsJson, err := os.ReadFile(exactFilePath) | ||
if err != nil { | ||
fmt.Println("Error reading creds file:", err) | ||
return | ||
} | ||
var secretstore types.SecretStore | ||
err = json.Unmarshal(credsJson, &secretstore) | ||
if err != nil { | ||
fmt.Println("Error:", err) | ||
Login(c) | ||
return | ||
} | ||
if hydrateOnlyURL { | ||
baseURL := c.String("base-url") | ||
if baseURL == "" { | ||
CliCdRequestData.BaseUrl = secretstore.BaseURL | ||
} else { | ||
CliCdRequestData.BaseUrl = baseURL | ||
} | ||
} else { | ||
CliCdRequestData.AuthToken = secretstore.ApiKey | ||
CliCdRequestData.Account = secretstore.AccountId | ||
CliCdRequestData.BaseUrl = secretstore.BaseURL | ||
CliCdRequestData.UserId = secretstore.UserId | ||
} | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.