Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] main from radius-project:main #1

Open
wants to merge 141 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
141 commits
Select commit Hold shift + click to select a range
4c85b6a
Updating Purge AWS Test Resources workflow (#7581)
ytimocin May 13, 2024
10627b0
Update bubbletea version and the unit test (#7526)
ytimocin May 13, 2024
0edd2b6
Bump the all group across 1 directory with 2 updates (#7591)
dependabot[bot] May 13, 2024
5fba423
Bump the all group across 1 directory with 4 updates (#7587)
dependabot[bot] May 13, 2024
427eed2
Update CLI client code and add tests (#7594)
rynowak May 16, 2024
a1cb280
add functional test results to artifacts (#7583)
nithyatsu May 16, 2024
af5e332
Stern - maxLogRequests option update (#7578)
ytimocin May 18, 2024
4537dfe
Bump the all group with 16 updates (#7615)
dependabot[bot] May 20, 2024
658dba7
fix for purge old container (#7616)
nithyatsu May 20, 2024
1a88d49
fix: close file (#7608)
testwill May 21, 2024
1af1fd8
Update Terraform recipe download error to include module version (#7620)
kachawla May 21, 2024
ea316f3
fix for rad init cannot work from folders with uppercase (#7617)
nithyatsu May 21, 2024
66aad2c
Add required_providers block to main.tf.config, functional test for T…
lakshmimsft May 21, 2024
4cacb58
Update kubebuilder to the latest working version (#7629)
sk593 May 23, 2024
950a256
Release 0.34.0-rc1: Update release version with RC1 (#7628)
sk593 May 23, 2024
1376150
Update release version 0.34 (#7633)
sk593 May 24, 2024
260c376
Bump the all group with 22 updates (#7635)
dependabot[bot] May 27, 2024
67f19d3
Update autorest related dependencies (#7636)
ytimocin May 28, 2024
f7ef3b2
Update purge workflow with manual trigger (#7622)
sk593 May 28, 2024
2b2b9d9
Revert "Update kubebuilder to the latest working version" (#7632)
sk593 May 28, 2024
0b6e13b
Update CNCF sandbox acceptance in README.md (#7639)
Reshrahim May 29, 2024
32e99aa
Update documentation on guideline for test images to be added to/pull…
lakshmimsft May 29, 2024
0cd0c8a
Fixing flaky config unit test (#7649)
ytimocin May 30, 2024
de7033d
Update purge workflow_dispatch logic (#7646)
sk593 May 30, 2024
85e1bcc
Fix purge workflow (#7653)
sk593 May 31, 2024
3ce1d0f
Adding support for terraform nested modules (#7519)
vishwahiremat May 31, 2024
b92cf6f
Update release docs (#7642)
sk593 May 31, 2024
869f120
Update instructions to publish bicep extension (#7579)
kachawla May 31, 2024
a8654c7
Bump the all group with 7 updates (#7656)
dependabot[bot] Jun 3, 2024
fe9355c
Fix for flaky unit test (#7654)
lakshmimsft Jun 3, 2024
d1a55c9
Adding EnableWebsockets property to the gateway (#7643)
ytimocin Jun 3, 2024
e3900e3
fixes #7592 - adding typed to mockgen (#7647)
superbeeny Jun 4, 2024
1ff7d17
Show correct environment and application for delete commands (#7669)
rynowak Jun 8, 2024
db6eeb2
Bump the all group with 10 updates (#7671)
dependabot[bot] Jun 10, 2024
a03a0c7
Remove extra files in TF recipe using azurerm (#7672)
lakshmimsft Jun 10, 2024
fd8d14e
Add upmerge instructions to release instructions (#7675)
willtsai Jun 10, 2024
eda496e
Bump github.com/Azure/azure-sdk-for-go/sdk/azidentity from 1.5.1 to 1…
dependabot[bot] Jun 11, 2024
7ffcb23
Bump github.com/Azure/azure-sdk-for-go/sdk/azidentity from 1.5.2 to 1…
dependabot[bot] Jun 12, 2024
9e9812a
Adding TypeSpec check to Lint workflow and running the TypeSpec forma…
ytimocin Jun 13, 2024
d7c5874
Adding the step to delete the created Azure resource group to the fun…
ytimocin Jun 15, 2024
5f7c51c
Bump the all group with 11 updates (#7689)
dependabot[bot] Jun 17, 2024
b2c8878
Bump mikefarah/yq from 4.44.1 to 4.44.2 in the all group (#7690)
dependabot[bot] Jun 17, 2024
d26a411
Switch Radius Helm chart pull from ACR to GHCR (#7455)
willdavsmith Jun 17, 2024
86b4397
Rename misspelled field (#7692)
rynowak Jun 17, 2024
b748443
Add Azure Workload Identity support (#7640)
willdavsmith Jun 18, 2024
e7a4ec9
Fix UCP test (#7694)
willdavsmith Jun 19, 2024
e253d7c
Fixing containerd should be direct warning by running go mod tidy (#7…
ytimocin Jun 19, 2024
3845082
Adding a test for annotations and labels to the existing k8s extensib…
ytimocin Jun 19, 2024
0b6ecc0
Release 0.35.0-rc1: Update release version with RC1 (#7698)
vishwahiremat Jun 19, 2024
d7031e2
Update release version 0.35 (#7701)
vishwahiremat Jun 21, 2024
3222fe9
Update wait time on postgres db in functional test (#7707)
lakshmimsft Jun 21, 2024
f1cdec3
Bump the all group with 14 updates (#7711)
dependabot[bot] Jun 24, 2024
95dce96
Updating dependencies manually (#7710)
ytimocin Jun 24, 2024
13d50f7
Update link in release notes highlights (#7712)
Reshrahim Jun 24, 2024
a8371ee
add IRSA credential type (#7708)
nithyatsu Jul 3, 2024
7ebd49e
Bump the all group with 13 updates (#7720)
dependabot[bot] Jul 5, 2024
534cba6
Bump the all group with 14 updates (#7729)
dependabot[bot] Jul 8, 2024
5d448d5
Fix prompt text test occasional failure (#7722)
brooke-hamilton Jul 8, 2024
ccc385f
Bump google.golang.org/grpc from 1.64.0 to 1.64.1 in the go_modules g…
dependabot[bot] Jul 9, 2024
b183209
Add secret support to Terraform Providers (backend updates) (#7695)
lakshmimsft Jul 13, 2024
00a3092
Fix broken link in contributing docs (#7736)
willdavsmith Jul 13, 2024
0782511
Bump the all group with 9 updates (#7737)
dependabot[bot] Jul 15, 2024
9b9cf3b
implement controllers for AWS IRSA (#7739)
nithyatsu Jul 16, 2024
faa6d3d
Add datamodel changes for secret support to Terraform Providers (#7731)
lakshmimsft Jul 18, 2024
2a4effe
Update release version v0.36.0-rc1 (#7742)
sk593 Jul 18, 2024
53e19b2
Update testrp and magpie Dockerfiles (#7745)
ytimocin Jul 19, 2024
fbed321
Update release version v0.36.0 (#7749)
sk593 Jul 22, 2024
a8f29eb
Bump the all group with 13 updates (#7751)
dependabot[bot] Jul 22, 2024
46bf036
Splitting functional tests as cloud and non-cloud (#7716)
ytimocin Jul 22, 2024
0dbbf5a
Reformatting the files in the scripts folder (#7755)
ytimocin Jul 22, 2024
594faf6
Update cyrilgdn/postgresql version in the postgres recipe (#7766)
ytimocin Jul 25, 2024
1127d12
Bump ossf/scorecard-action from 2.3.3 to 2.4.0 in the all group (#7769)
dependabot[bot] Jul 29, 2024
1c7b3ea
Bump the all group with 2 updates (#7768)
dependabot[bot] Jul 29, 2024
93ddbdb
Increasing `Test_TerraformRecipe_KubernetesPostgres` timeout to 2m (#…
willdavsmith Jul 29, 2024
c9b6581
implement irsa server side support (#7738)
nithyatsu Jul 29, 2024
9b77737
rad credential show - support for IRSA (#7757)
nithyatsu Jul 30, 2024
81b89fd
Adding rad install changes for AWS IRSA support (#7741)
vishwahiremat Jul 30, 2024
9b564db
"rad credential register aws" command changes for irsa (#7750)
vishwahiremat Jul 30, 2024
c62434f
Bump github.com/docker/docker from 27.0.0+incompatible to 27.1.0+inco…
dependabot[bot] Jul 30, 2024
78b52b1
Adding multi arch container image generation for magpie and testrp (#…
ytimocin Jul 31, 2024
a61a428
Updating and adding a timeout to the cleanup cluster step (#7727)
ytimocin Aug 1, 2024
b2ecfe8
Adding packages:write permission to the purge test resources workflow…
ytimocin Aug 1, 2024
be5da14
Update the registry in CLI functional test (#7779)
ytimocin Aug 2, 2024
4c9db50
Updating registry in the redis functional test (#7781)
ytimocin Aug 2, 2024
63490d6
Bump the all group with 3 updates (#7783)
dependabot[bot] Aug 5, 2024
4ba025d
Use local aws config in cli to get account and regions (#7758)
vishwahiremat Aug 5, 2024
a4a4b90
Adding rad init command changes to support irsa (#7761)
vishwahiremat Aug 6, 2024
83f57c2
Removing double imports found by staticcheck (#7791)
ytimocin Aug 8, 2024
3d96ee6
Adding a check to a cast to the Recipe object (#7797)
ytimocin Aug 9, 2024
5c10d92
Bicep compiler merge (#7662)
sk593 Aug 12, 2024
255c6d8
Update credential precedence in bicepconfig.json (#7803)
sk593 Aug 13, 2024
d01ecf9
Add warning when deleting an environment with existing applications (…
SoTrx Aug 13, 2024
9ed50f4
Replace Azure Service Principal auth with Azure Workload Identity aut…
willdavsmith Aug 13, 2024
f7c07fd
Bump the all group across 1 directory with 2 updates (#7802)
dependabot[bot] Aug 13, 2024
531d123
Bump github.com/docker/docker from 27.1.0+incompatible to 27.1.1+inco…
dependabot[bot] Aug 13, 2024
fb02873
Update error message value for LRT (#7810)
sk593 Aug 14, 2024
487081f
Update release version v0.37.0-rc1 (#7813)
vishwahiremat Aug 15, 2024
65ca82d
Update release version v0.37.0 (#7817)
vishwahiremat Aug 19, 2024
3cfb583
Add dependabot updates for bicep-types submodule (#7807)
sk593 Aug 19, 2024
6e18608
Bump bicep-types from `cd259b2` to `f0cd725` (#7821)
dependabot[bot] Aug 20, 2024
875c5ca
Remove unused test artifacts (#7824)
kachawla Aug 21, 2024
33d3d5e
Update validate workflow to test against PR specific schema changes …
sk593 Aug 21, 2024
7da87d4
Remove assets.yaml (#7832)
lakshmimsft Aug 22, 2024
a58b8cb
Temporarily disabling tests: `Test_Storage` and `Test_PersistentVolum…
willdavsmith Aug 28, 2024
84cb120
Update LoadSecrets() (#7796)
lakshmimsft Aug 29, 2024
50fef93
Add new secret types to Applications.Core/secretstores (#7816)
lakshmimsft Aug 29, 2024
940792c
Bump bicep-types from `f0cd725` to `49b2a9e` (#7843)
dependabot[bot] Aug 30, 2024
28fb22c
Fix doc links in kubernetes install command docs (#7849)
Reshrahim Aug 30, 2024
7232cc6
Updates to adding secret types PR (#7867)
lakshmimsft Aug 30, 2024
0c4a1bd
Bump the all group across 1 directory with 34 updates (#7858)
dependabot[bot] Sep 1, 2024
64da215
Bump bicep-types from `49b2a9e` to `99cdcee` (#7877)
dependabot[bot] Sep 2, 2024
96d5cf8
Bump the npm_and_yarn group across 2 directories with 2 updates (#7875)
dependabot[bot] Sep 3, 2024
3ddb61e
Adding Kubernetes native secrets to secret stores (#7744)
superbeeny Sep 3, 2024
5366a82
Fixes #7391 - fixing error in rad group show for no args (#7852)
superbeeny Sep 4, 2024
9091f8b
Add purge flag to delete radius related namespace (#7847)
lbzss Sep 5, 2024
dca3a27
Adding fix for publishing recipes to ECR (#7887)
vishwahiremat Sep 5, 2024
a1ab146
Support for secret store reference in Dapr components (#7823)
SoTrx Sep 5, 2024
dd81399
Add more Logging for cloud functional test workflow (#7885)
lakshmimsft Sep 5, 2024
cce1fe6
Add to debug logs for cloud functional test workflow (#7892)
lakshmimsft Sep 6, 2024
f89f424
Adding Bicep private registry support using basic auth, Azure workloa…
vishwahiremat Sep 9, 2024
8151a96
Add workflow condition in cloud functional tests (#7907)
lakshmimsft Sep 9, 2024
3d2825f
Remove radbicep references (#7894)
sk593 Sep 9, 2024
897f2aa
support deployment of an application to a scope "scope1" using enviro…
nithyatsu Sep 10, 2024
96fb582
Remove the error message added for debugging. (#7913)
vishwahiremat Sep 10, 2024
48c28ed
Release Radius v0.38.0-rc1 (#7920)
willdavsmith Sep 13, 2024
547fa81
Update version to 0.38 in versions.yaml (#7924)
ytimocin Sep 16, 2024
a5e97c3
Bump bicep-types from `99cdcee` to `d936309` (#7929)
dependabot[bot] Sep 16, 2024
a17f9cf
Implementation of Dapr Building Block: Configuration Store (#7906)
SoTrx Sep 18, 2024
69d6726
Updating and reformatting the release doc (#7933)
ytimocin Sep 19, 2024
50c1600
Update the timeout of the clean-up cluster step to 1h (#7938)
ytimocin Sep 19, 2024
a7395fb
Add dapr-sts* namespaces to be deleted to the clean-up workflow (#7942)
ytimocin Sep 19, 2024
cf639b4
Update golangci-lint version and fix new warnings (#7951)
ytimocin Sep 21, 2024
8f78e63
Improve validation and simplify database tests (#7949)
rynowak Sep 23, 2024
d13b0c4
Separating purge old images and purge Azure test resources workflows …
ytimocin Sep 23, 2024
62c6291
Bump peter-evans/create-pull-request from 6 to 7 in the all group (#7…
dependabot[bot] Sep 23, 2024
78751aa
Bump bicep-types from `d936309` to `ebba845` (#7957)
dependabot[bot] Sep 23, 2024
2df79ec
Add an in-memory data store (#7950)
rynowak Sep 23, 2024
24be8e6
Removing bicep workaround + minor cleanup (#7965)
sk593 Sep 27, 2024
b4c4d50
Update the bicep extension used in the dev container (#7969)
brooke-hamilton Sep 27, 2024
223ec1e
Implement PostgreSQL datastore (#7961)
rynowak Sep 27, 2024
ecd79d1
Add a PR Checklist for Contributions (#7921)
kachawla Oct 3, 2024
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
Prev Previous commit
Next Next commit
Add new secret types to Applications.Core/secretstores (radius-projec…
…t#7816)

# Description

Add new types to Applications.Core/secretstores (basicAuthentication,
azureWorkloadIdentity, awsIRSA)
Update convertor, tests.
Update existing ValidateAndMutateRequest() in
/pkg/corerp/frontend/controller/secretstores/kubernetes.go
to check if required secret keys exist for current secret type. Add to
existing unit tests.

## Type of change

- This pull request fixes a bug in Radius and has an approved issue
(radius-project#6917 ).


Fixes: Part of radius-project#6917
  • Loading branch information
lakshmimsft authored Aug 29, 2024
commit 50fef93875db22242aebc6e6507d21d8f3047a98

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions hack/bicep-types-radius/generated/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
"$ref": "applications/applications.core/2023-10-01-preview/types.json#/197"
},
"Applications.Core/secretStores@2023-10-01-preview": {
"$ref": "applications/applications.core/2023-10-01-preview/types.json#/226"
"$ref": "applications/applications.core/2023-10-01-preview/types.json#/232"
},
"Applications.Core/volumes@2023-10-01-preview": {
"$ref": "applications/applications.core/2023-10-01-preview/types.json#/263"
"$ref": "applications/applications.core/2023-10-01-preview/types.json#/269"
},
"Applications.Dapr/pubSubBrokers@2023-10-01-preview": {
"$ref": "applications/applications.dapr/2023-10-01-preview/types.json#/44"
Expand Down
12 changes: 12 additions & 0 deletions pkg/corerp/api/v20231001preview/secretstore_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ func toSecretStoreDataTypeDataModel(src *SecretStoreDataType) datamodel.SecretTy
return datamodel.SecretTypeGeneric
case SecretStoreDataTypeCertificate:
return datamodel.SecretTypeCert
case SecretStoreDataTypeBasicAuthentication:
return datamodel.SecretTypeBasicAuthentication
case SecretStoreDataTypeAzureWorkloadIdentity:
return datamodel.SecretTypeAzureWorkloadIdentity
case SecretStoreDataTypeAwsIRSA:
return datamodel.SecretTypeAWSIRSA
}

return datamodel.SecretTypeGeneric
Expand All @@ -117,6 +123,12 @@ func fromSecretStoreDataTypeDataModel(src datamodel.SecretType) *SecretStoreData
return to.Ptr(SecretStoreDataTypeGeneric)
case datamodel.SecretTypeCert:
return to.Ptr(SecretStoreDataTypeCertificate)
case datamodel.SecretTypeBasicAuthentication:
return to.Ptr(SecretStoreDataTypeBasicAuthentication)
case datamodel.SecretTypeAzureWorkloadIdentity:
return to.Ptr(SecretStoreDataTypeAzureWorkloadIdentity)
case datamodel.SecretTypeAWSIRSA:
return to.Ptr(SecretStoreDataTypeAwsIRSA)
}
return nil
}
Expand Down
12 changes: 12 additions & 0 deletions pkg/corerp/api/v20231001preview/zz_generated_constants.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/corerp/api/v20231001preview/zz_generated_models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions pkg/corerp/datamodel/secretstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ const (
SecretTypeGeneric SecretType = "generic"
// SecretTypeCert is the certificate secret type.
SecretTypeCert SecretType = "certificate"
// SecretTypeBasicAuthentication is the basicAuthentication secret type.
SecretTypeBasicAuthentication SecretType = "basicAuthentication"
// SecretTypeAzureWorkloadIdentity is the azureWorkloadIdentity secret type.
SecretTypeAzureWorkloadIdentity SecretType = "azureWorkloadIdentity"
// SecretTypeAWSIRSA is the awsIRSA secret type.
SecretTypeAWSIRSA SecretType = "awsIRSA"
)

// SecretStore represents secret store resource.
Expand Down
21 changes: 20 additions & 1 deletion pkg/corerp/frontend/controller/secretstores/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ func getOrDefaultType(t datamodel.SecretType) (datamodel.SecretType, error) {
t = datamodel.SecretTypeGeneric
case datamodel.SecretTypeCert:
case datamodel.SecretTypeGeneric:
case datamodel.SecretTypeBasicAuthentication:
case datamodel.SecretTypeAzureWorkloadIdentity:
case datamodel.SecretTypeAWSIRSA:
default:
err = fmt.Errorf("'%s' is invalid secret type", t)
}
Expand Down Expand Up @@ -75,8 +78,15 @@ func getOrDefaultEncoding(t datamodel.SecretType, e datamodel.SecretValueEncodin
return e, err
}

// Define a map of required keys for each SecretType
var requiredKeys = map[datamodel.SecretType][]string{
datamodel.SecretTypeBasicAuthentication: {RequiredUsername, RequiredPassword},
datamodel.SecretTypeAzureWorkloadIdentity: {RequiredClientId, RequiredTenantId},
datamodel.SecretTypeAWSIRSA: {RequiredRoleARN},
}

// ValidateAndMutateRequest checks the type and encoding of the secret store, and ensures that the secret store data is
// valid. If any of these checks fail, a BadRequestResponse is returned.
// valid and required keys are present for the secret type. If any of these checks fail, a BadRequestResponse is returned.
func ValidateAndMutateRequest(ctx context.Context, newResource *datamodel.SecretStore, oldResource *datamodel.SecretStore, options *controller.Options) (rest.Response, error) {
var err error
newResource.Properties.Type, err = getOrDefaultType(newResource.Properties.Type)
Expand Down Expand Up @@ -116,6 +126,15 @@ func ValidateAndMutateRequest(ctx context.Context, newResource *datamodel.Secret
}
}

// Validate that required keys for the secret type are present in the secret data
if keys, ok := requiredKeys[newResource.Properties.Type]; ok {
for _, key := range keys {
if _, ok := newResource.Properties.Data[key]; !ok {
return rest.NewBadRequestResponse(fmt.Sprintf("$.properties.data must contain '%s' key for %s type.", key, newResource.Properties.Type)), nil
}
}
}

return nil, nil
}

Expand Down
153 changes: 107 additions & 46 deletions pkg/corerp/frontend/controller/secretstores/kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ const (
testFileGenericValueGlobalScope = "secretstores_datamodel_global_scope.json"
testFileGenericValueInvalidResource = "secretstores_datamodel_global_scope_invalid_resource.json"
testFileGenericValueEmptyResource = "secretstores_datamodel_global_scope_empty_resource.json"

testFileBasicAuthentication = "secretstores_datamodel_basicauth.json"
testFileBasicAuthenticationInvalid = "secretstores_datamodel_basicauth_invalid.json"
testFileAWSIRSA = "secretstores_datamodel_awsirsa.json"
testFileAzureWorkloadIdentity = "secretstores_datamodel_azwi.json"
)

func TestGetNamespace(t *testing.T) {
Expand Down Expand Up @@ -247,53 +252,109 @@ func TestGetOrDefaultEncoding(t *testing.T) {
}

func TestValidateAndMutateRequest(t *testing.T) {
t.Run("default type is generic", func(t *testing.T) {
newResource := testutil.MustGetTestData[datamodel.SecretStore](testFileCertValueFrom)
newResource.Properties.Type = ""

resp, err := ValidateAndMutateRequest(context.TODO(), newResource, nil, nil)
require.NoError(t, err)
require.Nil(t, resp)

// assert
require.Equal(t, datamodel.SecretTypeGeneric, newResource.Properties.Type)
})

t.Run("new resource, but referencing valueFrom", func(t *testing.T) {
newResource := testutil.MustGetTestData[datamodel.SecretStore](testFileCertValueFrom)
newResource.Properties.Resource = ""
resp, err := ValidateAndMutateRequest(context.TODO(), newResource, nil, nil)
require.NoError(t, err)

// assert
r := resp.(*rest.BadRequestResponse)
require.True(t, r.Body.Error.Message == "$.properties.data[tls.crt].Value must be given to create the secret." ||
r.Body.Error.Message == "$.properties.data[tls.key].Value must be given to create the secret.")
})

t.Run("update the existing resource - type not matched", func(t *testing.T) {
oldResource := testutil.MustGetTestData[datamodel.SecretStore](testFileCertValueFrom)
oldResource.Properties.Type = datamodel.SecretTypeGeneric
newResource := testutil.MustGetTestData[datamodel.SecretStore](testFileCertValueFrom)
resp, err := ValidateAndMutateRequest(context.TODO(), newResource, oldResource, nil)
require.NoError(t, err)

// assert
r := resp.(*rest.BadRequestResponse)
require.Equal(t, "$.properties.type cannot change from 'generic' to 'certificate'.", r.Body.Error.Message)
})

t.Run("inherit resource id from existing resource", func(t *testing.T) {
oldResource := testutil.MustGetTestData[datamodel.SecretStore](testFileCertValueFrom)
newResource := testutil.MustGetTestData[datamodel.SecretStore](testFileCertValueFrom)
newResource.Properties.Resource = ""
resp, err := ValidateAndMutateRequest(context.TODO(), newResource, oldResource, nil)
tests := []struct {
name string
testFile string
oldResource *datamodel.SecretStore
modifyResource func(*datamodel.SecretStore, *datamodel.SecretStore)
assertions func(*testing.T, rest.Response, error, *datamodel.SecretStore, *datamodel.SecretStore)
}{
{
name: "default type is generic",
testFile: testFileCertValueFrom,
modifyResource: func(newResource, oldResource *datamodel.SecretStore) {
newResource.Properties.Type = ""
},
assertions: func(t *testing.T, resp rest.Response, err error, newResource, oldResource *datamodel.SecretStore) {
require.NoError(t, err)
require.Nil(t, resp)
require.Equal(t, datamodel.SecretTypeGeneric, newResource.Properties.Type)
},
},
{
name: "new resource, but referencing valueFrom",
testFile: testFileCertValueFrom,
modifyResource: func(newResource, oldResource *datamodel.SecretStore) {
newResource.Properties.Resource = ""
},
assertions: func(t *testing.T, resp rest.Response, err error, newResource, oldResource *datamodel.SecretStore) {
require.NoError(t, err)
r := resp.(*rest.BadRequestResponse)
require.True(t, r.Body.Error.Message == "$.properties.data[tls.crt].Value must be given to create the secret." ||
r.Body.Error.Message == "$.properties.data[tls.key].Value must be given to create the secret.")
},
},
{
name: "update the existing resource - type not matched",
testFile: testFileCertValueFrom,
oldResource: testutil.MustGetTestData[datamodel.SecretStore](testFileCertValueFrom),
modifyResource: func(newResource, oldResource *datamodel.SecretStore) {
oldResource.Properties.Type = datamodel.SecretTypeGeneric
},
assertions: func(t *testing.T, resp rest.Response, err error, newResource, oldResource *datamodel.SecretStore) {
require.NoError(t, err)
r := resp.(*rest.BadRequestResponse)
require.Equal(t, "$.properties.type cannot change from 'generic' to 'certificate'.", r.Body.Error.Message)
},
},
{
name: "inherit resource id from existing resource",
testFile: testFileCertValueFrom,
oldResource: testutil.MustGetTestData[datamodel.SecretStore](testFileCertValueFrom),
modifyResource: func(newResource, oldResource *datamodel.SecretStore) {
newResource.Properties.Resource = ""
},
assertions: func(t *testing.T, resp rest.Response, err error, newResource, oldResource *datamodel.SecretStore) {
require.NoError(t, err)
require.Nil(t, resp)
require.Equal(t, oldResource.Properties.Resource, newResource.Properties.Resource)
},
},
{
name: "new basicAuthentication resource",
testFile: testFileBasicAuthentication,
assertions: func(t *testing.T, resp rest.Response, err error, newResource, oldResource *datamodel.SecretStore) {
require.NoError(t, err)
require.Nil(t, resp)
},
},
{
name: "new awsIRSA resource",
testFile: testFileAWSIRSA,
assertions: func(t *testing.T, resp rest.Response, err error, newResource, oldResource *datamodel.SecretStore) {
require.NoError(t, err)
require.Nil(t, resp)
},
},
{
name: "new azureWorkloadIdentity resource",
testFile: testFileAzureWorkloadIdentity,
assertions: func(t *testing.T, resp rest.Response, err error, newResource, oldResource *datamodel.SecretStore) {
require.NoError(t, err)
require.Nil(t, resp)
},
},
{
name: "invalid basicAuthentication resource",
testFile: testFileBasicAuthenticationInvalid,
assertions: func(t *testing.T, resp rest.Response, err error, newResource, oldResource *datamodel.SecretStore) {
require.NoError(t, err)
r := resp.(*rest.BadRequestResponse)
require.True(t, r.Body.Error.Message == "$.properties.data must contain 'password' key for basicAuthentication type.")
},
},
}

// assert
require.NoError(t, err)
require.Nil(t, resp)
require.Equal(t, oldResource.Properties.Resource, newResource.Properties.Resource)
})
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
newResource := testutil.MustGetTestData[datamodel.SecretStore](tt.testFile)
if tt.modifyResource != nil {
tt.modifyResource(newResource, tt.oldResource)
}
resp, err := ValidateAndMutateRequest(context.TODO(), newResource, tt.oldResource, nil)
tt.assertions(t, resp, err, newResource, tt.oldResource)
})
}
}

func TestUpsertSecret(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testGroup/providers/Applications.Core/secretStores/secret0",
"name": "secret0",
"type": "applications.core/secretstores",
"location": "global",
"systemData": {
"createdAt": "2022-03-22T18:54:52.6857175Z",
"createdBy": "fake@hotmail.com",
"createdByType": "User",
"lastModifiedAt": "2022-03-22T18:57:52.6857175Z",
"lastModifiedBy": "fake@hotmail.com",
"lastModifiedByType": "User"
},
"provisioningState": "Succeeded",
"properties": {
"application": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testGroup/providers/Applications.Core/applications/app0",
"type": "awsIRSA",
"data": {
"roleARN": {
"value": "test-role-arn"
}
}
},
"tenantId": "00000000-0000-0000-0000-000000000000",
"subscriptionId": "00000000-0000-0000-0000-000000000000",
"resourceGroup": "testGroup",
"createdApiVersion": "2023-10-01-preview",
"updatedApiVersion": "2023-10-01-preview"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testGroup/providers/Applications.Core/secretStores/secret0",
"name": "secret0",
"type": "applications.core/secretstores",
"location": "global",
"systemData": {
"createdAt": "2022-03-22T18:54:52.6857175Z",
"createdBy": "fake@hotmail.com",
"createdByType": "User",
"lastModifiedAt": "2022-03-22T18:57:52.6857175Z",
"lastModifiedBy": "fake@hotmail.com",
"lastModifiedByType": "User"
},
"provisioningState": "Succeeded",
"properties": {
"application": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testGroup/providers/Applications.Core/applications/app0",
"type": "azureWorkloadIdentity",
"data": {
"clientId": {
"value": "test-client-Id"
},
"tenantId": {
"value": "test-tenant-Id"
}
}
},
"tenantId": "00000000-0000-0000-0000-000000000000",
"subscriptionId": "00000000-0000-0000-0000-000000000000",
"resourceGroup": "testGroup",
"createdApiVersion": "2023-10-01-preview",
"updatedApiVersion": "2023-10-01-preview"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testGroup/providers/Applications.Core/secretStores/secret0",
"name": "secret0",
"type": "applications.core/secretstores",
"location": "global",
"systemData": {
"createdAt": "2022-03-22T18:54:52.6857175Z",
"createdBy": "fake@hotmail.com",
"createdByType": "User",
"lastModifiedAt": "2022-03-22T18:57:52.6857175Z",
"lastModifiedBy": "fake@hotmail.com",
"lastModifiedByType": "User"
},
"provisioningState": "Succeeded",
"properties": {
"application": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testGroup/providers/Applications.Core/applications/app0",
"type": "basicAuthentication",
"data": {
"username": {
"value": "uname123"
},
"password": {
"value": "testpwd-dGxzLmNlcnQK"
}
}
},
"tenantId": "00000000-0000-0000-0000-000000000000",
"subscriptionId": "00000000-0000-0000-0000-000000000000",
"resourceGroup": "testGroup",
"createdApiVersion": "2023-10-01-preview",
"updatedApiVersion": "2023-10-01-preview"
}
Loading