Skip to content

Commit

Permalink
better docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Oct 28, 2023
1 parent b46bd5e commit 4b9c3be
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 43 deletions.
1 change: 0 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
Expand Down
71 changes: 46 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,6 @@

A Go library for simplifying the process of authenticating and managing tokens with the Akeyless CLI. This library handles token retrieval and management, ensuring tokens are reused when valid and only re-authenticating when necessary to reduce unnecessary user prompts.

## Directory Structure

```plaintext
.
├── LICENSE
├── README.md
├── akeyless-sheller
├── go.mod
├── go.sum
├── main.go # Example implementation of the library
├── main_test.go
└── sheller
├── config.go
├── profile.go
└── token.go
```

## Getting Started

1. **Clone the Repository:**
Expand All @@ -28,19 +11,55 @@ git clone https://github.com/your-username/akeyless-sheller.git
cd akeyless-sheller
```

2. **Install Dependencies:**
1. **Install Dependencies:**

```bash
go mod tidy
```

3. **Run the Example:**
1. **Run the Example:**

```bash
go run main.go
```

## Example Implementation
## Example Quickstart

The following code snippet provides a quickstart example of how to use the `sheller` library to obtain a token for a specified profile:

```go
package main

import (
"fmt"
"time"

"github.com/akeyless-community/akeyless-sheller/sheller"
)

func main() {
// Define the configuration
config := sheller.NewConfig(
"", // will pull from path if akeyless CLI is on system path
"default", // the name of the CLI profile to use
"/Users/chrisgruel/.akeyless", // the path to the Akeyless home directory usually located at ~/.akeyless
10*time.Minute, // if the token expiration is within this upcoming interval, a new token will be obtained
)

// Get a token for the specified profile
token, err := sheller.GetToken(profile, config)
if err != nil {
fmt.Printf("Failed to get token: %v\n", err)
return
}

// Print the obtained token
fmt.Printf("Obtained token: %v\n", token.Token)
}

```

## Example Full Implementation

The `main.go` file in the root directory serves as an example implementation of the `sheller` library. Below is a brief explanation of how it operates:

Expand All @@ -57,15 +76,17 @@ import (
"fmt"
"sheller"
"time"

"github.com/akeyless-community/akeyless-sheller/sheller"
)

func main() {
// Define the configuration
config := sheller.NewConfig(
"/path/to/akeyless-cli",
"default",
"/Users/chrisgruel/.akeyless",
10*time.Minute,
"", // will pull from path if akeyless CLI is on system path
"default", // the name of the CLI profile to use
"/Users/chrisgruel/.akeyless", // the path to the Akeyless home directory usually located at ~/.akeyless
10*time.Minute, // if the token expiration is within this upcoming interval, a new token will be obtained
)

// Initialize the sheller library
Expand Down Expand Up @@ -110,4 +131,4 @@ go test ./...

## License

This project is licensed under the terms of the MIT license. See the [LICENSE](LICENSE) file for details.
This project is licensed under the terms of the Apache 2.0 license. See the [LICENSE](LICENSE) file for details.
19 changes: 2 additions & 17 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,9 @@ func main() {
10*time.Minute, // ExpiryBuffer
)

// Initialize the sheller library
err := sheller.InitializeLibrary(config)
token, err := sheller.InitializeAndGetToken(config)
if err != nil {
fmt.Printf("Failed to initialize sheller library: %v\n", err)
return
}

// Load the specified profile
profile, err := sheller.GetProfile(config.Profile, config)
if err != nil {
fmt.Printf("Failed to load profile: %v\n", err)
return
}

// Get a token for the specified profile
token, err := sheller.GetToken(profile, config)
if err != nil {
fmt.Printf("Failed to get token: %v\n", err)
fmt.Printf("Failed to initialize and get token: %v\n", err)
return
}

Expand Down

0 comments on commit 4b9c3be

Please sign in to comment.