Skip to content

Commit

Permalink
Merge pull request #23 from DelineaXPM/add.platformLoginSupport
Browse files Browse the repository at this point in the history
Add platform login support
  • Loading branch information
delineaKrehl authored Apr 10, 2024
2 parents 009d2e0 + 9b50f87 commit 3dae291
Show file tree
Hide file tree
Showing 4 changed files with 440 additions and 65 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ env:
TSS_TEST_PASSWORD: ${{ secrets.TSS_TEST_PASSWORD }}
TSS_SEARCH_FIELD: ${{ secrets.TSS_SEARCH_FIELD }}
TSS_SEARCH_TEXT: ${{ secrets.TSS_SEARCH_TEXT }}
TSS_PLATFORM_USERNAME: ${{ secrets.TSS_PLATFORM_USERNAME }}
TSS_PLATFORM_PASSWORD: ${{ secrets.TSS_PLATFORM_PASSWORD }}
TSS_PLATFORM_URL: ${{ secrets.TSS_PLATFORM_URL }}

jobs:
build:
Expand Down
27 changes: 22 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ A Golang API and examples for [Delinea](https://delinea.com/)
## Configure

The API requires a `Configuration` object containing a `Username`, `Password`
and either a `Tenant` for Secret Server Cloud or a `ServerURL`:
and either a `Tenant` for Secret Server Cloud or a `ServerURL` of Secret Server/Platform:

```golang
type UserCredential struct {
Expand All @@ -23,7 +23,7 @@ type Configuration struct {

## Use

Define a `Configuration`, use it to create an instance of `Server`:
Define a `Configuration`, use it to create an instance of `Server` for Secret Server:

```golang
tss := server.New(server.Configuration{
Expand All @@ -37,6 +37,20 @@ tss := server.New(server.Configuration{
})
```

OR

Define a `Configuration`, use it to create an instance of `Server` for Platform:

```golang
tss := server.New(server.Configuration{
Credentials: UserCredential{
Username: os.Getenv("TSS_PLATFORM_USERNAME"),
Password: os.Getenv("TSS_PLATFORM_PASSWORD"),
},
ServerURL: os.Getenv("TSS_PLATFORM_URL"),
})
```

Get a secret by its numeric ID:

```golang
Expand Down Expand Up @@ -111,10 +125,13 @@ The necessary configuration may also be configured from environment variables:

| Env Var Name | Description |
|----------------|------------------------------------------------------------------------------------------------------------------------------------------|
| TSS_USERNAME | The user name for the Secret Server |
| TSS_PASSWORD | The password for the user |
| TSS_USERNAME | The user name for the Secret Server |
| TSS_PASSWORD | The password for the user of Secret Server |
| TSS_TENANT | Name for tenants hosted in the Secret Server Cloud. This is prepended to the *.secretservercloud.com domain to determine the server URL. |
| TSS_SERVER_URL | URL for servers not hosted in the cloud, eg: https://delinea.mycompany.com/SecretServer |
| TSS_SERVER_URL | URL for secret servers not hosted in the cloud, eg: https://delinea.mycompany.com/SecretServer or platform URL |
| TSS_PLATFORM_USERNAME | The user name for the Platform user |
| TSS_PLATFORM_PASSWORD | The password for the Platform user |
| TSS_PLATFORM_URL | URL for Platform, eg: https://delinea.secureplatform.com/ |

### Test #1 - Read Secret Password
Reads the secret with ID `1` or the ID passed in the `TSS_SECRET_ID` environment variable
Expand Down
147 changes: 118 additions & 29 deletions server/secret_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,26 @@ import (

// TestSecret tests Secret. Referred to as "Test #1" in the README.
func TestSecret(t *testing.T) {
tss, err := initServer()
if err != nil {
t.Error("configuring the Server:", err)
return
}
t.Run("SecretServer_TestSecret", func(t *testing.T) {
tss, err := initServer()
if err != nil {
t.Error("configuring the Server:", err)
return
}
GetSecret(t, tss)
})

t.Run("Platform_TestSecret", func(t *testing.T) {
tss, err := initPlatformServer()
if err != nil {
t.Error("configuring the Platform Server:", err)
return
}
GetSecret(t, tss)
})
}

func GetSecret(t *testing.T, tss *Server) {
id := initIntegerFromEnv("TSS_SECRET_ID", t)
if id < 0 {
return
Expand Down Expand Up @@ -45,13 +59,26 @@ func TestSecret(t *testing.T) {
// TestSecretCRUD tests the creation, read, update, and delete of a Secret.
// Referred to as "Test #2" in the README.
func TestSecretCRUD(t *testing.T) {
t.Run("SecretServer_TestSecretCRUD", func(t *testing.T) {
tss, err := initServer()
if err != nil {
t.Error("configuring the Server:", err)
return
}
SecretCRUD(t, tss)
})

// Initialize
tss, err := initServer()
if err != nil {
t.Error("configuring the Server:", err)
return
}
t.Run("Platform_TestSecretCRUD", func(t *testing.T) {
tss, err := initPlatformServer()
if err != nil {
t.Error("configuring the Platform Server:", err)
return
}
SecretCRUD(t, tss)
})
}

func SecretCRUD(t *testing.T, tss *Server) {
siteId := initIntegerFromEnv("TSS_SITE_ID", t)
folderId := initIntegerFromEnv("TSS_FOLDER_ID", t)
templateId := initIntegerFromEnv("TSS_TEMPLATE_ID", t)
Expand Down Expand Up @@ -190,7 +217,7 @@ func TestSecretCRUD(t *testing.T) {

// Test read of the deleted secret fails
s, err := tss.Secret(sc.ID)
if s != nil {
if s != nil && s.Active {
t.Errorf("deleted secret with id '%d' returned from read", sc.ID)
}
}
Expand All @@ -199,13 +226,26 @@ func TestSecretCRUD(t *testing.T) {
// of a Secret which uses an SSH key template, that is, a template with extended
// mappings that support SSH keys. Referred to as "Test #3" in the README.
func TestSecretCRUDForSSHTemplate(t *testing.T) {
t.Run("SecretServer_TestSecretCRUDForSSHTemplate", func(t *testing.T) {
tss, err := initServer()
if err != nil {
t.Error("configuring the Server:", err)
return
}
SecretCRUDForSSHTemplate(t, tss)
})

// Initialize
tss, err := initServer()
if err != nil {
t.Error("configuring the Server:", err)
return
}
t.Run("Platform_TestSecretCRUDForSSHTemplate", func(t *testing.T) {
tss, err := initPlatformServer()
if err != nil {
t.Error("configuring the Platform Server:", err)
return
}
SecretCRUDForSSHTemplate(t, tss)
})
}

func SecretCRUDForSSHTemplate(t *testing.T, tss *Server) {
siteId := initIntegerFromEnv("TSS_SITE_ID", t)
folderId := initIntegerFromEnv("TSS_FOLDER_ID", t)
templateId := initIntegerFromEnv("TSS_SSH_KEY_TEMPLATE_ID", t)
Expand Down Expand Up @@ -559,18 +599,33 @@ func TestSecretCRUDForSSHTemplate(t *testing.T) {

// Test read of the deleted secret fails
s, err := tss.Secret(sc.ID)
if s != nil {
if s != nil && s.Active {
t.Errorf("deleted secret with id '%d' returned from read", sc.ID)
}
}

// TestSearch tests Secret. Referred to as "Test #4" in the README.
func TestSearch(t *testing.T) {
tss, err := initServer()
if err != nil {
t.Error("configuring the Server:", err)
return
}
t.Run("SecretServer_TestSearch", func(t *testing.T) {
tss, err := initServer()
if err != nil {
t.Error("configuring the Server:", err)
return
}
Search(t, tss)
})

t.Run("Platform_TestSearch", func(t *testing.T) {
tss, err := initPlatformServer()
if err != nil {
t.Error("configuring the Platform Server:", err)
return
}
Search(t, tss)
})
}

func Search(t *testing.T, tss *Server) {

s, err := tss.Secrets(os.Getenv("TSS_SEARCH_TEXT"), os.Getenv("TSS_SEARCH_FIELD"))

Expand All @@ -590,11 +645,26 @@ func TestSearch(t *testing.T) {

// TestSearchWithoutField tests Secret. Referred to as "Test #5" in the README.
func TestSearchWithoutField(t *testing.T) {
tss, err := initServer()
if err != nil {
t.Error("configuring the Server:", err)
return
}
t.Run("SecretServer_TestSearchWithoutField", func(t *testing.T) {
tss, err := initServer()
if err != nil {
t.Error("configuring the Server:", err)
return
}
SearchWithoutField(t, tss)
})

t.Run("Platform_TestSearchWithoutField", func(t *testing.T) {
tss, err := initPlatformServer()
if err != nil {
t.Error("configuring the Platform Server:", err)
return
}
SearchWithoutField(t, tss)
})
}

func SearchWithoutField(t *testing.T, tss *Server) {

s, err := tss.Secrets(os.Getenv("TSS_SEARCH_TEXT"), "")

Expand Down Expand Up @@ -632,6 +702,25 @@ func initServer() (*Server, error) {
return New(*config)
}

func initPlatformServer() (*Server, error) {
var config *Configuration

if cj, err := ioutil.ReadFile("../test_config.json"); err == nil {
config = new(Configuration)

json.Unmarshal(cj, &config)
} else {
config = &Configuration{
Credentials: UserCredential{
Username: os.Getenv("TSS_PLATFORM_USERNAME"),
Password: os.Getenv("TSS_PLATFORM_PASSWORD"),
},
ServerURL: os.Getenv("TSS_PLATFORM_URL"),
}
}
return New(*config)
}

// initIntegerFromEnv reads the given environment variable and if it's declared, parses it to an integer. Otherwise,
// returns a default integer of '1'.
func initIntegerFromEnv(envVarName string, t *testing.T) int {
Expand Down
Loading

0 comments on commit 3dae291

Please sign in to comment.