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
2 changes: 0 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ jobs:
uses: ./.github/workflows/tailscale
with:
auth_key: ${{ secrets.TAILSCALE_AUTH_KEY_EPHEMERAL }}
exit_node: 100.99.49.20
accept_dns: true

- name: Test application
uses: ./.github/workflows/go-test
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.11.0
0.12.0
8 changes: 4 additions & 4 deletions authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ func NewClient(appKey string, appSecret string, baseUri string) (Client, error)
client.common.client = &client

client.Entries = &Entries{
UserCredential: (*EntryUserCredentialService)(&client.common),
Certificate: (*EntryCertificateService)(&client.common),
Website: (*EntryWebsiteService)(&client.common),
Host: (*EntryHostService)(&client.common),
Credential: (*EntryCredentialService)(&client.common),
Certificate: (*EntryCertificateService)(&client.common),
Website: (*EntryWebsiteService)(&client.common),
Host: (*EntryHostService)(&client.common),
}
client.Vaults = (*Vaults)(&client.common)

Expand Down
123 changes: 93 additions & 30 deletions entries.go
Original file line number Diff line number Diff line change
@@ -1,51 +1,114 @@
package dvls

import (
"strconv"
"encoding/json"
"fmt"
"strings"
)

const (
entryEndpoint string = "/api/connections/partial"
entryConnectionsEndpoint string = "/api/connections"
entryBasePublicEndpoint string = "/api/v1/vault/{vaultId}/entry"
entryPublicEndpoint string = "/api/v1/vault/{vaultId}/entry/{id}"
)

type Entries struct {
Certificate *EntryCertificateService
Host *EntryHostService
UserCredential *EntryUserCredentialService
Website *EntryWebsiteService
}

func keywordsToSlice(kw string) []string {
var spacedTag bool
tags := strings.FieldsFunc(string(kw), func(r rune) bool {
if r == '"' {
spacedTag = !spacedTag
}
return !spacedTag && r == ' '
})
for i, v := range tags {
unquotedTag, err := strconv.Unquote(v)
if err != nil {
continue
}
Certificate *EntryCertificateService
Host *EntryHostService
Credential *EntryCredentialService
Website *EntryWebsiteService
}

type Entry struct {
ID string `json:"id,omitempty"`
VaultId string `json:"vaultId,omitempty"`
Name string `json:"name"`
Path string `json:"path"`
Type string `json:"type"`
SubType string `json:"subType"`

Data EntryData `json:"data,omitempty"`

Description string `json:"description"`
ModifiedBy string `json:"modifiedBy,omitempty"`
ModifiedOn *ServerTime `json:"modifiedOn,omitempty"`
CreatedBy string `json:"createdBy,omitempty"`
CreatedOn *ServerTime `json:"createdOn,omitempty"`
Tags []string `json:"tags,omitempty"`
}

type EntryData any

func (e *Entry) GetType() string {
return e.Type
}

func (e *Entry) GetSubType() string {
return e.SubType
}

var entryFactories = map[string]func() EntryData{
"Credential/AccessCode": func() EntryData { return &EntryCredentialAccessCodeData{} },
"Credential/ApiKey": func() EntryData { return &EntryCredentialApiKeyData{} },
"Credential/AzureServicePrincipal": func() EntryData { return &EntryCredentialAzureServicePrincipalData{} },
"Credential/ConnectionString": func() EntryData { return &EntryCredentialConnectionStringData{} },
"Credential/Default": func() EntryData { return &EntryCredentialDefaultData{} },
"Credential/PrivateKey": func() EntryData { return &EntryCredentialPrivateKeyData{} },
}

tags[i] = unquotedTag
func (e *Entry) UnmarshalJSON(data []byte) error {
type alias Entry
raw := &struct {
Data json.RawMessage `json:"data"`
*alias
}{
alias: (*alias)(e),
}

return tags
if err := json.Unmarshal(data, &raw); err != nil {
return err
}

key := fmt.Sprintf("%s/%s", raw.Type, raw.SubType)
factory, ok := entryFactories[key]
if !ok {
return fmt.Errorf("unsupported entry type/subtype: %s", key)
}

dataStruct := factory()
if err := json.Unmarshal(raw.Data, dataStruct); err != nil {
return fmt.Errorf("failed to unmarshal entry data: %w", err)
}

e.Data = dataStruct

return nil
}

func sliceToKeywords(kw []string) string {
keywords := []string(kw)
for i, v := range keywords {
if strings.Contains(v, " ") {
kw[i] = "\"" + v + "\""
}
func (e Entry) MarshalJSON() ([]byte, error) {
type alias Entry

dataBytes, err := json.Marshal(e.Data)
if err != nil {
return nil, err
}

kString := strings.Join(keywords, " ")
return json.Marshal(&struct {
Data json.RawMessage `json:"data"`
*alias
}{
Data: dataBytes,
alias: (*alias)(&e),
})
}

func entryPublicEndpointReplacer(vaultId string, entryId string) string {
replacer := strings.NewReplacer("{vaultId}", vaultId, "{id}", entryId)
return replacer.Replace(entryPublicEndpoint)
}

return kString
func entryPublicBaseEndpointReplacer(vaultId string) string {
replacer := strings.NewReplacer("{vaultId}", vaultId)
return replacer.Replace(entryBasePublicEndpoint)
}
File renamed without changes.
2 changes: 1 addition & 1 deletion entry_certificate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var (
testCertificateEntry EntryCertificate = EntryCertificate{
VaultId: testVaultId,
Name: "TestK8sCertificate",
Password: testEntryPassword,
Password: "TestK8sCertificatePassword",
Tags: []string{"test", "k8s"},
CertificateIdentifier: "test",
}
Expand Down
Loading
Loading