Skip to content

Commit

Permalink
Merge branch 'main' into token
Browse files Browse the repository at this point in the history
  • Loading branch information
delinea-sagar authored Apr 11, 2024
2 parents 9cc9d90 + 3dae291 commit 0e63ebd
Show file tree
Hide file tree
Showing 6 changed files with 446 additions and 96 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ jobs:
environment: release
steps:
- name: Set up Go 1.13
uses: actions/setup-go@v3
uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568 # v3
with:
go-version: 1.13
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v3
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3

- name: Get dependencies
run: |
go get -v -t -d ./...
- name: Build
run: go build -v .

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3
with:
name: artifacts
path: tss-sdk-go.exe
9 changes: 6 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ on:
- main

env:
TSS_SERVER_URL: ${{ secrets.TSS_SERVER_URL }}
TSS_TENANT: ${{ secrets.TSS_TENANT }}
TSS_USERNAME: ${{ secrets.TSS_USERNAME }}
TSS_PASSWORD: ${{ secrets.TSS_PASSWORD }}
TSS_SECRET_ID: ${{ secrets.TSS_SECRET_ID }}
Expand All @@ -27,20 +27,23 @@ 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:
name: Build
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.13
uses: actions/setup-go@v3
uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568 # v3
with:
go-version: 1.13
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v3
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3

- name: Get dependencies
run: |
Expand Down
25 changes: 0 additions & 25 deletions .whitesource

This file was deleted.

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 0e63ebd

Please sign in to comment.