Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,44 @@ kfutil --help
All the variables listed below need to be set in your environment. The `kfutil` command will look for these variables
and use them if they are set. If they are not set, the utility will fail to connect to Keyfactor.

Linux/MacOS:
```bash
export KEYFACTOR_HOSTNAME=<mykeyfactorhost.mydomain.com>
export KEYFACTOR_USERNAME=<myusername> # Do not include domain
export KEYFACTOR_PASSWORD=<mypassword>
export KEYFACTOR_DOMAIN=<mykeyfactordomain>
```

Windows Powershell
```powershell
$env:KEYFACTOR_HOSTNAME="<mykeyfactorhost.mydomain.com>"
$env:KEYFACTOR_USERNAME="<myusername>" # Do not include domain
$env:KEYFACTOR_PASSWORD="<mypassword>"
$env:KEYFACTOR_DOMAIN="<mykeyfactordomain>"
```

## Commands

### Login
For full documentation on the `login` command, see the [login](docs/kfutil_login.md) documentation.

*WARNING* - The `login` command will store your Keyfactor credentials in a file on your local machine. This file is not
encrypted and is not secure. It is recommended that you use the `login` command only on your local machine and not on a
shared machine. Instead of using the `login` command, you can set the environmental variables listed above.

```bash
kfutil login
```

### Logout
For full documentation on the `logout` command, see the [logout](docs/kfutil_logout.md) documentation.

*WARNING* - This will delete the file containing your Keyfactor credentials at `$HOME/.keyfactor/command_config.json`.

```bash
kfutil logout
```

## Commands

### Bulk operations
Expand Down
25 changes: 18 additions & 7 deletions cmd/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@ const DefaultConfigFileName = "command_config.json"
// loginCmd represents the login command
var loginCmd = &cobra.Command{
Use: "login",
Short: "User interactive login to Keyfactor.",
Short: "User interactive login to Keyfactor. Stores the credentials in the config file '$HOME/.keyfactor/command_config.json'.",
Long: `Will prompt the user for a username and password and then attempt to login to Keyfactor.
You can provide the --config flag to specify a config file to use. If not provided, the default
config file will be used. The default config file is located at $HOME/.keyfactor/command_config.json.
To prevent the prompt for username and password, use the --no-prompt flag. If this flag is provided then
the CLI will default to using the environment variables: KEYFACTOR_HOSTNAME, KEYFACTOR_USERNAME,
KEYFACTOR_PASSWORD and KEYFACTOR_DOMAIN.

WARNING: The username and password will be stored in the config file in plain text at:
'$HOME/.keyfactor/command_config.json.'
`,
Run: func(cmd *cobra.Command, args []string) {
log.SetOutput(io.Discard)
Expand Down Expand Up @@ -100,8 +103,11 @@ func authConfigFile(configFile string, noPrompt bool) bool {
fmt.Printf("Enter Keyfactor Command host URL [%s]: \n", envHostName)
_, phErr := fmt.Scanln(&host)
if phErr != nil {
fmt.Println("Error getting hostname: ", phErr)
log.Fatal("[ERROR] getting hostname: ", phErr)
if phErr.Error() != "unexpected newline" {
fmt.Println("Error getting hostname: ", phErr)
log.Println("[ERROR] getting hostname: ", phErr)
}

}
if len(host) == 0 {
host = envHostName
Expand All @@ -128,8 +134,10 @@ func authConfigFile(configFile string, noPrompt bool) bool {
fmt.Printf("Enter your Keyfactor Command username [%s]: \n", envUserName)
_, puErr := fmt.Scanln(&username)
if puErr != nil {
fmt.Println("Error getting username: ", puErr)
log.Fatal("[ERROR] getting username: ", puErr)
if puErr.Error() != "unexpected newline" {
fmt.Println("Error getting username: ", puErr)
log.Println("[ERROR] getting username: ", puErr)
}
}
}
if len(username) == 0 {
Expand Down Expand Up @@ -189,8 +197,11 @@ func authConfigFile(configFile string, noPrompt bool) bool {
fmt.Printf("Enter your Keyfactor Command AD domain [%s]: \n", envDomain)
_, sdErr := fmt.Scanln(&domain)
if sdErr != nil {
fmt.Println("Error getting domain: ", sdErr)
log.Fatal("[ERROR] getting domain: ", sdErr)
if sdErr.Error() != "unexpected newline" {
fmt.Println("Error getting domain: ", sdErr)
log.Println("[ERROR] getting domain: ", sdErr)
}

}
if len(domain) == 0 {
domain = envDomain
Expand Down
36 changes: 36 additions & 0 deletions cmd/logout.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Package cmd Copyright 2022 Keyfactor
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
package cmd

import (
"fmt"
"io"
"log"
"os"

"github.com/spf13/cobra"
)

// logoutCmd represents the logout command
var logoutCmd = &cobra.Command{
Use: "logout",
Short: "Removes the credentials file '$HOME/.keyfactor/command_config.json'.",
Long: `Removes the credentials file '$HOME/.keyfactor/command_config.json'.`,
Run: func(cmd *cobra.Command, args []string) {
log.SetOutput(io.Discard)
err := os.Remove(fmt.Sprintf("%s/.keyfactor/%s", os.Getenv("HOME"), DefaultConfigFileName))
if err != nil {
fmt.Println("Error removing config file: ", err)
log.Fatal("[ERROR] removing config file: ", err)
}
fmt.Println("Logged out successfully!")
},
}

func init() {
RootCmd.AddCommand(logoutCmd)
}
5 changes: 3 additions & 2 deletions docs/kfutil.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ A CLI wrapper around the Keyfactor Platform API.
### SEE ALSO

* [kfutil containers](kfutil_containers.md) - Keyfactor certificate store container API and utilities.
* [kfutil login](kfutil_login.md) - User interactive login to Keyfactor.
* [kfutil login](kfutil_login.md) - User interactive login to Keyfactor. Stores the credentials in the config file '$HOME/.keyfactor/command_config.json'.
* [kfutil logout](kfutil_logout.md) - Removes the credentials file '$HOME/.keyfactor/command_config.json'.
* [kfutil orchs](kfutil_orchs.md) - Keyfactor agents/orchestrators APIs and utilities.
* [kfutil status](kfutil_status.md) - List the status of Keyfactor services.
* [kfutil store-types](kfutil_store-types.md) - Keyfactor certificate store types APIs and utilities.
* [kfutil stores](kfutil_stores.md) - Keyfactor certificate stores APIs and utilities.
* [kfutil version](kfutil_version.md) - Shows version of kfutil

###### Auto generated by spf13/cobra on 29-Nov-2022
###### Auto generated by spf13/cobra on 1-Dec-2022
2 changes: 1 addition & 1 deletion docs/kfutil_containers.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ A collections of APIs and utilities for interacting with Keyfactor certificate s
* [kfutil containers get](kfutil_containers_get.md) - Get certificate store container by ID or name.
* [kfutil containers list](kfutil_containers_list.md) - List certificate store containers.

###### Auto generated by spf13/cobra on 29-Nov-2022
###### Auto generated by spf13/cobra on 1-Dec-2022
2 changes: 1 addition & 1 deletion docs/kfutil_containers_get.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ kfutil containers get [flags]

* [kfutil containers](kfutil_containers.md) - Keyfactor certificate store container API and utilities.

###### Auto generated by spf13/cobra on 29-Nov-2022
###### Auto generated by spf13/cobra on 1-Dec-2022
2 changes: 1 addition & 1 deletion docs/kfutil_containers_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ kfutil containers list [flags]

* [kfutil containers](kfutil_containers.md) - Keyfactor certificate store container API and utilities.

###### Auto generated by spf13/cobra on 29-Nov-2022
###### Auto generated by spf13/cobra on 1-Dec-2022
7 changes: 5 additions & 2 deletions docs/kfutil_login.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## kfutil login

User interactive login to Keyfactor.
User interactive login to Keyfactor. Stores the credentials in the config file '$HOME/.keyfactor/command_config.json'.

### Synopsis

Expand All @@ -11,6 +11,9 @@ To prevent the prompt for username and password, use the --no-prompt flag. If th
the CLI will default to using the environment variables: KEYFACTOR_HOSTNAME, KEYFACTOR_USERNAME,
KEYFACTOR_PASSWORD and KEYFACTOR_DOMAIN.

WARNING: The username and password will be stored in the config file in plain text at:
'$HOME/.keyfactor/command_config.json.'


```
kfutil login [flags]
Expand All @@ -28,4 +31,4 @@ kfutil login [flags]

* [kfutil](kfutil.md) - Keyfactor CLI utilities

###### Auto generated by spf13/cobra on 29-Nov-2022
###### Auto generated by spf13/cobra on 1-Dec-2022
23 changes: 23 additions & 0 deletions docs/kfutil_logout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
## kfutil logout

Removes the credentials file '$HOME/.keyfactor/command_config.json'.

### Synopsis

Removes the credentials file '$HOME/.keyfactor/command_config.json'.

```
kfutil logout [flags]
```

### Options

```
-h, --help help for logout
```

### SEE ALSO

* [kfutil](kfutil.md) - Keyfactor CLI utilities

###### Auto generated by spf13/cobra on 1-Dec-2022
2 changes: 1 addition & 1 deletion docs/kfutil_orchs.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ A collections of APIs and utilities for interacting with Keyfactor orchestrators
* [kfutil orchs logs](kfutil_orchs_logs.md) - Get orchestrator logs by ID or machine/client name.
* [kfutil orchs reset](kfutil_orchs_reset.md) - Reset orchestrator by ID or machine/client name.

###### Auto generated by spf13/cobra on 29-Nov-2022
###### Auto generated by spf13/cobra on 1-Dec-2022
2 changes: 1 addition & 1 deletion docs/kfutil_orchs_approve.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ kfutil orchs approve [flags]

* [kfutil orchs](kfutil_orchs.md) - Keyfactor agents/orchestrators APIs and utilities.

###### Auto generated by spf13/cobra on 29-Nov-2022
###### Auto generated by spf13/cobra on 1-Dec-2022
2 changes: 1 addition & 1 deletion docs/kfutil_orchs_disapprove.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ kfutil orchs disapprove [flags]

* [kfutil orchs](kfutil_orchs.md) - Keyfactor agents/orchestrators APIs and utilities.

###### Auto generated by spf13/cobra on 29-Nov-2022
###### Auto generated by spf13/cobra on 1-Dec-2022
2 changes: 1 addition & 1 deletion docs/kfutil_orchs_get.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ kfutil orchs get [flags]

* [kfutil orchs](kfutil_orchs.md) - Keyfactor agents/orchestrators APIs and utilities.

###### Auto generated by spf13/cobra on 29-Nov-2022
###### Auto generated by spf13/cobra on 1-Dec-2022
2 changes: 1 addition & 1 deletion docs/kfutil_orchs_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ kfutil orchs list [flags]

* [kfutil orchs](kfutil_orchs.md) - Keyfactor agents/orchestrators APIs and utilities.

###### Auto generated by spf13/cobra on 29-Nov-2022
###### Auto generated by spf13/cobra on 1-Dec-2022
2 changes: 1 addition & 1 deletion docs/kfutil_orchs_logs.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ kfutil orchs logs [flags]

* [kfutil orchs](kfutil_orchs.md) - Keyfactor agents/orchestrators APIs and utilities.

###### Auto generated by spf13/cobra on 29-Nov-2022
###### Auto generated by spf13/cobra on 1-Dec-2022
2 changes: 1 addition & 1 deletion docs/kfutil_orchs_reset.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ kfutil orchs reset [flags]

* [kfutil orchs](kfutil_orchs.md) - Keyfactor agents/orchestrators APIs and utilities.

###### Auto generated by spf13/cobra on 29-Nov-2022
###### Auto generated by spf13/cobra on 1-Dec-2022
2 changes: 1 addition & 1 deletion docs/kfutil_status.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ kfutil status [flags]

* [kfutil](kfutil.md) - Keyfactor CLI utilities

###### Auto generated by spf13/cobra on 29-Nov-2022
###### Auto generated by spf13/cobra on 1-Dec-2022
2 changes: 1 addition & 1 deletion docs/kfutil_store-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ A collections of APIs and utilities for interacting with Keyfactor certificate s
* [kfutil store-types templates-fetch](kfutil_store-types_templates-fetch.md) - Fetches store type templates from Keyfactor's Github.
* [kfutil store-types update](kfutil_store-types_update.md) - Update a certificate store type in Keyfactor.

###### Auto generated by spf13/cobra on 29-Nov-2022
###### Auto generated by spf13/cobra on 1-Dec-2022
2 changes: 1 addition & 1 deletion docs/kfutil_store-types_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ kfutil store-types create [flags]

* [kfutil store-types](kfutil_store-types.md) - Keyfactor certificate store types APIs and utilities.

###### Auto generated by spf13/cobra on 29-Nov-2022
###### Auto generated by spf13/cobra on 1-Dec-2022
2 changes: 1 addition & 1 deletion docs/kfutil_store-types_delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ kfutil store-types delete [flags]

* [kfutil store-types](kfutil_store-types.md) - Keyfactor certificate store types APIs and utilities.

###### Auto generated by spf13/cobra on 29-Nov-2022
###### Auto generated by spf13/cobra on 1-Dec-2022
2 changes: 1 addition & 1 deletion docs/kfutil_store-types_get.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ kfutil store-types get [flags]

* [kfutil store-types](kfutil_store-types.md) - Keyfactor certificate store types APIs and utilities.

###### Auto generated by spf13/cobra on 29-Nov-2022
###### Auto generated by spf13/cobra on 1-Dec-2022
2 changes: 1 addition & 1 deletion docs/kfutil_store-types_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ kfutil store-types list [flags]

* [kfutil store-types](kfutil_store-types.md) - Keyfactor certificate store types APIs and utilities.

###### Auto generated by spf13/cobra on 29-Nov-2022
###### Auto generated by spf13/cobra on 1-Dec-2022
2 changes: 1 addition & 1 deletion docs/kfutil_store-types_templates-fetch.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ kfutil store-types templates-fetch [flags]

* [kfutil store-types](kfutil_store-types.md) - Keyfactor certificate store types APIs and utilities.

###### Auto generated by spf13/cobra on 29-Nov-2022
###### Auto generated by spf13/cobra on 1-Dec-2022
2 changes: 1 addition & 1 deletion docs/kfutil_store-types_update.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ kfutil store-types update [flags]

* [kfutil store-types](kfutil_store-types.md) - Keyfactor certificate store types APIs and utilities.

###### Auto generated by spf13/cobra on 29-Nov-2022
###### Auto generated by spf13/cobra on 1-Dec-2022
2 changes: 1 addition & 1 deletion docs/kfutil_stores.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ A collections of APIs and utilities for interacting with Keyfactor certificate s
* [kfutil stores list](kfutil_stores_list.md) - List certificate stores.
* [kfutil stores rot](kfutil_stores_rot.md) - Root of trust utility

###### Auto generated by spf13/cobra on 29-Nov-2022
###### Auto generated by spf13/cobra on 1-Dec-2022
2 changes: 1 addition & 1 deletion docs/kfutil_stores_get.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ kfutil stores get [flags]

* [kfutil stores](kfutil_stores.md) - Keyfactor certificate stores APIs and utilities.

###### Auto generated by spf13/cobra on 29-Nov-2022
###### Auto generated by spf13/cobra on 1-Dec-2022
2 changes: 1 addition & 1 deletion docs/kfutil_stores_import.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ Tools for generating import templates and importing certificate stores
* [kfutil stores import create](kfutil_stores_import_create.md) - Create certificate stores
* [kfutil stores import generate-template](kfutil_stores_import_generate-template.md) - For generating a CSV template with headers for bulk store creation.

###### Auto generated by spf13/cobra on 29-Nov-2022
###### Auto generated by spf13/cobra on 1-Dec-2022
2 changes: 1 addition & 1 deletion docs/kfutil_stores_import_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ kfutil stores import create --file <file name to import> --store-type-id <store

* [kfutil stores import](kfutil_stores_import.md) - Import a file with certificate store parameters and create them in keyfactor.

###### Auto generated by spf13/cobra on 29-Nov-2022
###### Auto generated by spf13/cobra on 1-Dec-2022
2 changes: 1 addition & 1 deletion docs/kfutil_stores_import_generate-template.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ kfutil stores import generate-template --store-type-id <store type id> --store-t

* [kfutil stores import](kfutil_stores_import.md) - Import a file with certificate store parameters and create them in keyfactor.

###### Auto generated by spf13/cobra on 29-Nov-2022
###### Auto generated by spf13/cobra on 1-Dec-2022
2 changes: 1 addition & 1 deletion docs/kfutil_stores_inventory.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ Commands related to certificate store inventory management
* [kfutil stores inventory remove](kfutil_stores_inventory_remove.md) - Removes a certificate from the certificate store inventory.
* [kfutil stores inventory show](kfutil_stores_inventory_show.md) - Show the inventory of a certificate store.

###### Auto generated by spf13/cobra on 29-Nov-2022
###### Auto generated by spf13/cobra on 1-Dec-2022
2 changes: 1 addition & 1 deletion docs/kfutil_stores_inventory_add.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ kfutil stores inventory add [flags]

* [kfutil stores inventory](kfutil_stores_inventory.md) - Commands related to certificate store inventory management

###### Auto generated by spf13/cobra on 29-Nov-2022
###### Auto generated by spf13/cobra on 1-Dec-2022
2 changes: 1 addition & 1 deletion docs/kfutil_stores_inventory_clear.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ kfutil stores inventory clear [flags]

* [kfutil stores inventory](kfutil_stores_inventory.md) - Commands related to certificate store inventory management

###### Auto generated by spf13/cobra on 29-Nov-2022
###### Auto generated by spf13/cobra on 1-Dec-2022
2 changes: 1 addition & 1 deletion docs/kfutil_stores_inventory_remove.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ kfutil stores inventory remove [flags]

* [kfutil stores inventory](kfutil_stores_inventory.md) - Commands related to certificate store inventory management

###### Auto generated by spf13/cobra on 29-Nov-2022
###### Auto generated by spf13/cobra on 1-Dec-2022
2 changes: 1 addition & 1 deletion docs/kfutil_stores_inventory_show.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ kfutil stores inventory show [flags]

* [kfutil stores inventory](kfutil_stores_inventory.md) - Commands related to certificate store inventory management

###### Auto generated by spf13/cobra on 29-Nov-2022
###### Auto generated by spf13/cobra on 1-Dec-2022
2 changes: 1 addition & 1 deletion docs/kfutil_stores_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ kfutil stores list [flags]

* [kfutil stores](kfutil_stores.md) - Keyfactor certificate stores APIs and utilities.

###### Auto generated by spf13/cobra on 29-Nov-2022
###### Auto generated by spf13/cobra on 1-Dec-2022
2 changes: 1 addition & 1 deletion docs/kfutil_stores_rot.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ kfutil stores rot reconcile --import-csv <audit-file>
* [kfutil stores rot generate-template](kfutil_stores_rot_generate-template.md) - For generating Root Of Trust template(s)
* [kfutil stores rot reconcile](kfutil_stores_rot_reconcile.md) - Reconcile either takes in or will generate an audit report and then add/remove certs as needed.

###### Auto generated by spf13/cobra on 29-Nov-2022
###### Auto generated by spf13/cobra on 1-Dec-2022
2 changes: 1 addition & 1 deletion docs/kfutil_stores_rot_audit.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ kfutil stores rot audit [flags]

* [kfutil stores rot](kfutil_stores_rot.md) - Root of trust utility

###### Auto generated by spf13/cobra on 29-Nov-2022
###### Auto generated by spf13/cobra on 1-Dec-2022
2 changes: 1 addition & 1 deletion docs/kfutil_stores_rot_generate-template.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ kfutil stores rot generate-template [flags]

* [kfutil stores rot](kfutil_stores_rot.md) - Root of trust utility

###### Auto generated by spf13/cobra on 29-Nov-2022
###### Auto generated by spf13/cobra on 1-Dec-2022
Loading