-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2273 from posit-dev/dotnomad/deploy-with-secrets
Add ability to send secrets to `POST /api/deployments/$NAME` endpoint
- Loading branch information
Showing
10 changed files
with
310 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package config | ||
|
||
// Copyright (C) 2024 by Posit Software, PBC. | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/suite" | ||
) | ||
|
||
type ConfigHasSecretSuite struct { | ||
suite.Suite | ||
} | ||
|
||
func TestConfig_HasSecret(t *testing.T) { | ||
suite.Run(t, new(ConfigHasSecretSuite)) | ||
} | ||
|
||
func (s *ConfigHasSecretSuite) TestSecretExists() { | ||
c := &Config{ | ||
Secrets: []string{"SECRET1", "SECRET2", "SECRET3"}, | ||
} | ||
s.True(c.HasSecret("SECRET2")) | ||
} | ||
|
||
func (s *ConfigHasSecretSuite) TestSecretDoesNotExist() { | ||
c := &Config{ | ||
Secrets: []string{"SECRET1", "SECRET2", "SECRET3"}, | ||
} | ||
s.False(c.HasSecret("SECRET4")) | ||
} | ||
|
||
func (s *ConfigHasSecretSuite) TestEmptySecretsList() { | ||
c := &Config{} | ||
s.False(c.HasSecret("SECRET1")) | ||
} | ||
|
||
func (s *ConfigHasSecretSuite) TestCaseSensitiveCheck() { | ||
c := &Config{ | ||
Secrets: []string{"SECRET1", "SECRET2", "SECRET3"}, | ||
} | ||
s.False(c.HasSecret("secret2")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package publish | ||
|
||
// Copyright (C) 2024 by Posit Software, PBC. | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/posit-dev/publisher/internal/clients/connect" | ||
"github.com/posit-dev/publisher/internal/events" | ||
"github.com/posit-dev/publisher/internal/logging" | ||
"github.com/posit-dev/publisher/internal/state" | ||
"github.com/posit-dev/publisher/internal/types" | ||
"github.com/posit-dev/publisher/internal/util/utiltest" | ||
"github.com/stretchr/testify/mock" | ||
"github.com/stretchr/testify/suite" | ||
) | ||
|
||
type SetEnvVarsSuite struct { | ||
utiltest.Suite | ||
} | ||
|
||
func TestSetEnvVarsSuite(t *testing.T) { | ||
suite.Run(t, new(SetEnvVarsSuite)) | ||
} | ||
|
||
func (s *SetEnvVarsSuite) TestSetEnvVarsWithNoEnvironmentOrSecrets() { | ||
stateStore := state.Empty() | ||
log := logging.New() | ||
emitter := events.NewCapturingEmitter() | ||
|
||
publisher := &defaultPublisher{ | ||
State: stateStore, | ||
log: log, | ||
emitter: emitter, | ||
} | ||
client := connect.NewMockClient() | ||
|
||
err := publisher.setEnvVars(client, types.ContentID("test-content-id")) | ||
s.NoError(err) | ||
|
||
// No calls to the Connect API to set environment variables should be made | ||
s.Equal(0, len(client.Calls)) | ||
} | ||
|
||
func (s *SetEnvVarsSuite) TestSetEnvVarsWithSecrets() { | ||
stateStore := state.Empty() | ||
log := logging.New() | ||
emitter := events.NewCapturingEmitter() | ||
|
||
stateStore.Secrets = map[string]string{"SOME_SECRET": "some-secret-value", "ANOTHER_SECRET": "another-secret-value"} | ||
|
||
publisher := &defaultPublisher{ | ||
State: stateStore, | ||
log: log, | ||
emitter: emitter, | ||
} | ||
client := connect.NewMockClient() | ||
|
||
client.On("SetEnvVars", types.ContentID("test-content-id"), stateStore.Secrets, mock.Anything).Return(nil) | ||
|
||
err := publisher.setEnvVars(client, types.ContentID("test-content-id")) | ||
s.NoError(err) | ||
|
||
client.AssertExpectations(s.T()) | ||
} | ||
|
||
func (s *SetEnvVarsSuite) TestSetEnvVarsWithEnvironment() { | ||
stateStore := state.Empty() | ||
log := logging.New() | ||
emitter := events.NewCapturingEmitter() | ||
|
||
stateStore.Config.Environment = map[string]string{"TEST_ENV_VAR": "test-value", "ANOTHER_TEST_ENV_VAR": "another-test-value"} | ||
|
||
publisher := &defaultPublisher{ | ||
State: stateStore, | ||
log: log, | ||
emitter: emitter, | ||
} | ||
client := connect.NewMockClient() | ||
|
||
client.On("SetEnvVars", types.ContentID("test-content-id"), stateStore.Config.Environment, mock.Anything).Return(nil) | ||
|
||
err := publisher.setEnvVars(client, types.ContentID("test-content-id")) | ||
s.NoError(err) | ||
|
||
client.AssertExpectations(s.T()) | ||
} | ||
|
||
func (s *SetEnvVarsSuite) TestSetEnvVarsWithSecretsAndEnvironment() { | ||
stateStore := state.Empty() | ||
stateStore.Config.Environment = map[string]string{"TEST_ENV_VAR": "test-value", "ANOTHER_TEST_ENV_VAR": "another-test-value"} | ||
stateStore.Secrets = map[string]string{"SOME_SECRET": "some-secret-value", "ANOTHER_SECRET": "another-secret-value"} | ||
log := logging.New() | ||
emitter := events.NewCapturingEmitter() | ||
|
||
publisher := &defaultPublisher{ | ||
State: stateStore, | ||
log: log, | ||
emitter: emitter, | ||
} | ||
client := connect.NewMockClient() | ||
|
||
combinedEnv := map[string]string{ | ||
"TEST_ENV_VAR": "test-value", | ||
"ANOTHER_TEST_ENV_VAR": "another-test-value", | ||
"SOME_SECRET": "some-secret-value", | ||
"ANOTHER_SECRET": "another-secret-value", | ||
} | ||
client.On("SetEnvVars", types.ContentID("test-content-id"), combinedEnv, mock.Anything).Return(nil) | ||
|
||
err := publisher.setEnvVars(client, types.ContentID("test-content-id")) | ||
s.NoError(err) | ||
|
||
client.AssertExpectations(s.T()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.