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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ agent-config.test.yaml
infisical-merge
test/infisical-merge
.DS_Store


/agent-testing
8 changes: 8 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,14 @@ require (
github.com/aws/aws-sdk-go-v2/service/sts v1.28.12 // indirect
github.com/aws/smithy-go v1.20.2 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chzyer/readline v1.5.1 // indirect
github.com/danieljoos/wincred v1.2.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dgraph-io/badger/v3 v3.2103.5 // indirect
github.com/dgraph-io/ristretto v0.1.1 // indirect
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/dvsekhvalnov/jose2go v1.6.0 // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
Expand All @@ -91,8 +96,11 @@ require (
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/gofrs/flock v0.8.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/glog v1.2.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.3 // indirect
github.com/google/flatbuffers v1.12.1 // indirect
github.com/google/gnostic-models v0.6.9 // indirect
github.com/google/go-cmp v0.7.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
Expand Down
45 changes: 45 additions & 0 deletions go.sum

Large diffs are not rendered by default.

45 changes: 44 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,57 @@ Copyright (c) 2023 Infisical Inc.
package main

import (
"fmt"
"os"
"strings"
"time"

"github.com/Infisical/infisical-merge/packages/cmd"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)

func main() {
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})

// very annoying but zerolog doesn't allow us to change one color without changing all of them
// these are the default colors for each level, except for warn
levelColors := map[string]string{
"trace": "\033[35m", // magenta
"debug": "\033[33m", // yellow
"info": "\033[32m", // green
"warn": "\033[33m", // yellow (this one is custom, the default is red \033[31m)
"error": "\033[31m", // red
"fatal": "\033[31m", // red
"panic": "\033[31m", // red
}

// map full level names to abbreviated forms (default zerolog behavior)
// see consoleDefaultFormatLevel, in zerolog for example
levelAbbrev := map[string]string{
"trace": "TRC",
"debug": "DBG",
"info": "INF",
"warn": "WRN",
"error": "ERR",
"fatal": "FTL",
"panic": "PNC",
}

log.Logger = log.Output(zerolog.ConsoleWriter{
Out: os.Stderr,
TimeFormat: time.RFC3339,
FormatLevel: func(i interface{}) string {
level := fmt.Sprintf("%s", i)
color := levelColors[level]
if color == "" {
color = "\033[0m" // no color for unknown levels
}
abbrev := levelAbbrev[level]
if abbrev == "" {
abbrev = strings.ToUpper(level) // fallback to uppercase if unknown
}
return color + abbrev + "\033[0m"
},
})
cmd.Execute()
}
28 changes: 28 additions & 0 deletions packages/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package api

import (
"encoding/base64"
"errors"
"fmt"
"net/http"
"strings"
Expand Down Expand Up @@ -54,6 +55,8 @@ const (
operationCallInstanceRelayHeartBeat = "CallInstanceRelayHeartBeat"
)

var ErrNotFound = errors.New("resource not found")

func CallGetEncryptedWorkspaceKey(httpClient *resty.Client, request GetEncryptedWorkspaceKeyRequest) (GetEncryptedWorkspaceKeyResponse, error) {
endpoint := fmt.Sprintf("%v/v2/workspace/%v/encrypted-key", config.INFISICAL_URL, request.WorkspaceId)
var result GetEncryptedWorkspaceKeyResponse
Expand Down Expand Up @@ -572,6 +575,31 @@ func CallCreateDynamicSecretLeaseV1(httpClient *resty.Client, request CreateDyna
return createDynamicSecretLeaseResponse, nil
}

func CallGetDynamicSecretLeaseV1(httpClient *resty.Client, request GetDynamicSecretLeaseV1Request) (GetDynamicSecretLeaseV1Response, error) {
var getDynamicSecretLeaseResponse GetDynamicSecretLeaseV1Response
response, err := httpClient.
R().
SetResult(&getDynamicSecretLeaseResponse).
SetHeader("User-Agent", USER_AGENT).
SetQueryParam("environmentSlug", request.Environment).
SetQueryParam("projectSlug", request.ProjectSlug).
SetQueryParam("secretPath", request.SecretPath).
Get(fmt.Sprintf("%v/v1/dynamic-secrets/leases/%s", config.INFISICAL_URL, request.LeaseID))

if err != nil {
return GetDynamicSecretLeaseV1Response{}, fmt.Errorf("CallGetDynamicSecretLeaseV1: Unable to complete api request [err=%w]", err)
}

if response.IsError() {
if response.StatusCode() == http.StatusNotFound {
return GetDynamicSecretLeaseV1Response{}, ErrNotFound
}
return GetDynamicSecretLeaseV1Response{}, fmt.Errorf("CallGetDynamicSecretLeaseV1: Unsuccessful response [status-code=%v] [response=%v]", response.StatusCode(), response.String())
}

return getDynamicSecretLeaseResponse, nil
}

func CallCreateRawSecretsV3(httpClient *resty.Client, request CreateRawSecretV3Request) error {
response, err := httpClient.
R().
Expand Down
15 changes: 15 additions & 0 deletions packages/api/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,21 @@ type CreateDynamicSecretLeaseV1Response struct {
Data map[string]interface{} `json:"data"`
}

type GetDynamicSecretLeaseV1Request struct {
LeaseID string
Environment string
ProjectSlug string
SecretPath string
}

type GetDynamicSecretLeaseV1Response struct {
Lease struct {
Id string `json:"id"`
ExpireAt time.Time `json:"expireAt"`
} `json:"lease"`
DynamicSecret models.DynamicSecret `json:"dynamicSecret"`
}

type GetLoginV3Request struct {
Email string `json:"email"`
Password string `json:"password"`
Expand Down
Loading
Loading