Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Tuan Dang committed Nov 21, 2022
2 parents 8967609 + 11b7309 commit d8b2398
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 120 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,6 @@ yarn-error.log*
.env.production.local
.vercel
.env.infisical

# Infisical init
.infisical.json
102 changes: 0 additions & 102 deletions cli/README.md

This file was deleted.

14 changes: 5 additions & 9 deletions cli/packages/cmd/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ var loginCmd = &cobra.Command{
PreRun: toggleDebug,
Run: func(cmd *cobra.Command, args []string) {
hasUserLoggedInbefore, currentLoggedInUserEmail, err := util.IsUserLoggedIn()

if err != nil {
log.Debugln(err)
log.Debugln("Unable to get current logged in user.", err)
}

if hasUserLoggedInbefore {
Expand All @@ -45,12 +46,6 @@ var loginCmd = &cobra.Command{
}
}

if err != nil {
log.Errorln("Unable to get current logged in user.")
log.Debugln(err)
return
}

email, password, err := askForLoginCredentials()
if err != nil {
log.Errorln("Unable to parse email and password for authentication")
Expand Down Expand Up @@ -160,6 +155,7 @@ func askForLoginCredentials() (email string, password string, err error) {
}

func getFreshUserCredentials(email string, password string) (*models.LoginTwoResponse, error) {
log.Debugln("getFreshUserCredentials:", "email", email, "password", password)
httpClient := resty.New()
httpClient.SetRetryCount(5)

Expand All @@ -180,7 +176,7 @@ func getFreshUserCredentials(email string, password string) (*models.LoginTwoRes
R().
SetBody(loginOneRequest).
SetResult(&loginOneResponseResult).
Post(fmt.Sprintf("%v/%v", util.INFISICAL_URL, "login1"))
Post(fmt.Sprintf("%v/v1/auth/login1", util.INFISICAL_URL))

if err != nil {
return nil, err
Expand Down Expand Up @@ -216,7 +212,7 @@ func getFreshUserCredentials(email string, password string) (*models.LoginTwoRes
R().
SetBody(LoginTwoRequest).
SetResult(&loginTwoResponseResult).
Post(fmt.Sprintf("%v/%v", util.INFISICAL_URL, "login2"))
Post(fmt.Sprintf("%v/v1/auth/login2", util.INFISICAL_URL))

if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions cli/packages/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var rootCmd = &cobra.Command{
Short: "Infisical CLI is used to inject environment variables into any process",
Long: `Infisical is a simple, end-to-end encrypted service that enables teams to sync and manage their environment variables across their development life cycle.`,
CompletionOptions: cobra.CompletionOptions{DisableDefaultCmd: true},
Version: "1.0.0",
Version: "1.0.1",
}

// Execute adds all child commands to the root command and sets flags appropriately.
Expand All @@ -30,5 +30,5 @@ func Execute() {
func init() {
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
rootCmd.PersistentFlags().BoolVarP(&debugLogging, "debug", "d", false, "Enable verbose logging")
rootCmd.PersistentFlags().StringVar(&util.INFISICAL_URL, "domain", "http://localhost:4000", "Point the CLI to your own backend")
rootCmd.PersistentFlags().StringVar(&util.INFISICAL_URL, "domain", "https://app.infisical.com/api", "Point the CLI to your own backend")
}
2 changes: 1 addition & 1 deletion cli/packages/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var runCmd = &cobra.Command{
}

var envsFromApi []models.SingleEnvironmentVariable
infisicalToken := os.Getenv(util.INFISICAL_SERVICE_TOKEN)
infisicalToken := os.Getenv(util.INFISICAL_TOKEN_NAME)
if infisicalToken == "" {
hasUserLoggedInbefore, loggedInUserEmail, err := util.IsUserLoggedIn()
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cli/packages/util/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ const (
CONFIG_FILE_NAME = "infisical-config.json"
CONFIG_FOLDER_NAME = ".infisical"
INFISICAL_WORKSPACE_CONFIG_FILE_NAME = ".infisical.json"
INFISICAL_SERVICE_TOKEN = "INFISICAL_SERVICE_TOKEN"
INFISICAL_TOKEN_NAME = "INFISICAL_TOKEN"
)

var INFISICAL_URL = "https://api.infisical.com"
var INFISICAL_URL = "https://app.infisical.com/api"

func GetHomeDir() (string, error) {
directory, err := os.UserHomeDir()
Expand Down
2 changes: 1 addition & 1 deletion cli/packages/util/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func IsUserLoggedIn() (hasUserLoggedIn bool, theUsersEmail string, err error) {

response, err := httpClient.
R().
Post(fmt.Sprintf("%v/%v", INFISICAL_URL, "checkAuth"))
Post(fmt.Sprintf("%v/v1/auth/checkAuth", INFISICAL_URL))

if err != nil {
return false, "", err
Expand Down
8 changes: 5 additions & 3 deletions cli/packages/util/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ func GetSecretsFromAPIUsingCurrentLoggedInUser(envName string, userCreds models.
SetQueryParam("environment", envName).
SetQueryParam("channel", "cli").
SetResult(&pullSecretsRequestResponse).
Get(fmt.Sprintf("%v/%v/%v", INFISICAL_URL, "secret", workspace.WorkspaceId)) // need to change workspace id
Get(fmt.Sprintf("%v/v1/secret/%v", INFISICAL_URL, workspace.WorkspaceId)) // need to change workspace id

log.Debugln("Response from get secrets:", response)

if err != nil {
return nil, err
Expand Down Expand Up @@ -116,7 +118,7 @@ func GetSecretsFromAPIUsingInfisicalToken(infisicalToken string, envName string,
SetQueryParam("environment", envName).
SetQueryParam("channel", "cli").
SetResult(&pullSecretsByInfisicalTokenResponse).
Get(fmt.Sprintf("%v/secret/%v/service-token", INFISICAL_URL, projectId))
Get(fmt.Sprintf("%v/v1/secret/%v/service-token", INFISICAL_URL, projectId))

if err != nil {
return nil, err
Expand Down Expand Up @@ -191,7 +193,7 @@ func GetWorkSpacesFromAPI(userCreds models.UserCredentials) (workspaces []models
response, err := httpClient.
R().
SetResult(&getWorkSpacesResponse).
Get(fmt.Sprintf("%v/%v", INFISICAL_URL, "workspace"))
Get(fmt.Sprintf("%v/v1/workspace", INFISICAL_URL))

if err != nil {
return nil, err
Expand Down

0 comments on commit d8b2398

Please sign in to comment.