Skip to content

Commit

Permalink
resolving pr requests
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Beenham <[email protected]>
  • Loading branch information
superbeeny committed Aug 1, 2024
1 parent a9cc5a8 commit c0d0fe5
Show file tree
Hide file tree
Showing 15 changed files with 106 additions and 153 deletions.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion hack/bicep-types-radius/generated/index.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"Resources":{"Applications.Core/applications@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":58},"Applications.Core/containers@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":126},"Applications.Core/environments@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":164},"Applications.Core/extenders@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":182},"Applications.Core/gateways@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":203},"Applications.Core/secretStores@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":226},"Applications.Core/volumes@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":263},"Applications.Dapr/pubSubBrokers@2023-10-01-preview":{"RelativePath":"applications/applications.dapr/2023-10-01-preview/types.json","Index":49},"Applications.Dapr/secretStores@2023-10-01-preview":{"RelativePath":"applications/applications.dapr/2023-10-01-preview/types.json","Index":66},"Applications.Dapr/stateStores@2023-10-01-preview":{"RelativePath":"applications/applications.dapr/2023-10-01-preview/types.json","Index":84},"Applications.Datastores/mongoDatabases@2023-10-01-preview":{"RelativePath":"applications/applications.datastores/2023-10-01-preview/types.json","Index":50},"Applications.Datastores/redisCaches@2023-10-01-preview":{"RelativePath":"applications/applications.datastores/2023-10-01-preview/types.json","Index":69},"Applications.Datastores/sqlDatabases@2023-10-01-preview":{"RelativePath":"applications/applications.datastores/2023-10-01-preview/types.json","Index":88},"Applications.Messaging/rabbitMQQueues@2023-10-01-preview":{"RelativePath":"applications/applications.messaging/2023-10-01-preview/types.json","Index":50}},"Functions":{"applications.core/extenders":{"2023-10-01-preview":[{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":264}]},"applications.core/secretstores":{"2023-10-01-preview":[{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":270}]},"applications.datastores/mongodatabases":{"2023-10-01-preview":[{"RelativePath":"applications/applications.datastores/2023-10-01-preview/types.json","Index":90}]},"applications.datastores/rediscaches":{"2023-10-01-preview":[{"RelativePath":"applications/applications.datastores/2023-10-01-preview/types.json","Index":92}]},"applications.datastores/sqldatabases":{"2023-10-01-preview":[{"RelativePath":"applications/applications.datastores/2023-10-01-preview/types.json","Index":94}]},"applications.messaging/rabbitmqqueues":{"2023-10-01-preview":[{"RelativePath":"applications/applications.messaging/2023-10-01-preview/types.json","Index":52}]}}}
{"Resources":{"Applications.Core/applications@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":58},"Applications.Core/containers@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":126},"Applications.Core/environments@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":163},"Applications.Core/extenders@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":181},"Applications.Core/gateways@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":202},"Applications.Core/secretStores@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":225},"Applications.Core/volumes@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":262},"Applications.Dapr/pubSubBrokers@2023-10-01-preview":{"RelativePath":"applications/applications.dapr/2023-10-01-preview/types.json","Index":49},"Applications.Dapr/secretStores@2023-10-01-preview":{"RelativePath":"applications/applications.dapr/2023-10-01-preview/types.json","Index":66},"Applications.Dapr/stateStores@2023-10-01-preview":{"RelativePath":"applications/applications.dapr/2023-10-01-preview/types.json","Index":84},"Applications.Datastores/mongoDatabases@2023-10-01-preview":{"RelativePath":"applications/applications.datastores/2023-10-01-preview/types.json","Index":50},"Applications.Datastores/redisCaches@2023-10-01-preview":{"RelativePath":"applications/applications.datastores/2023-10-01-preview/types.json","Index":69},"Applications.Datastores/sqlDatabases@2023-10-01-preview":{"RelativePath":"applications/applications.datastores/2023-10-01-preview/types.json","Index":88},"Applications.Messaging/rabbitMQQueues@2023-10-01-preview":{"RelativePath":"applications/applications.messaging/2023-10-01-preview/types.json","Index":50}},"Functions":{"applications.core/extenders":{"2023-10-01-preview":[{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":263}]},"applications.core/secretstores":{"2023-10-01-preview":[{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":269}]},"applications.datastores/mongodatabases":{"2023-10-01-preview":[{"RelativePath":"applications/applications.datastores/2023-10-01-preview/types.json","Index":90}]},"applications.datastores/rediscaches":{"2023-10-01-preview":[{"RelativePath":"applications/applications.datastores/2023-10-01-preview/types.json","Index":92}]},"applications.datastores/sqldatabases":{"2023-10-01-preview":[{"RelativePath":"applications/applications.datastores/2023-10-01-preview/types.json","Index":94}]},"applications.messaging/rabbitmqqueues":{"2023-10-01-preview":[{"RelativePath":"applications/applications.messaging/2023-10-01-preview/types.json","Index":52}]}}}
2 changes: 1 addition & 1 deletion pkg/corerp/api/v20231001preview/container_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func fromEnvironmentVariableDataModel(e map[string]datamodel.EnvironmentVariable
} else {
m[key] = &EnvironmentVariable{
ValueFrom: &EnvironmentVariableReference{
SecretRef: &EnvironmentVariableSecretReference{
SecretRef: &SecretReference{
Source: to.Ptr(val.ValueFrom.SecretRef.Source),
Key: to.Ptr(val.ValueFrom.SecretRef.Key),
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/corerp/api/v20231001preview/container_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func TestContainerConvertVersionedToDataModel(t *testing.T) {
if tt.filename == "containerresource.json" {
require.Equal(t, map[string]datamodel.EnvironmentVariable{
"DB_USER": {
Value: to.StringPtr("DB_USER"),
Value: to.Ptr("DB_USER"),
},
"DB_PASSWORD": {
ValueFrom: &datamodel.EnvironmentVariableReference{
Expand Down Expand Up @@ -195,7 +195,7 @@ func TestContainerConvertDataModelToVersioned(t *testing.T) {
if tt.filename == "containerresourcedatamodel.json" {
require.Equal(t, map[string]datamodel.EnvironmentVariable{
"DB_USER": {
Value: to.StringPtr("DB_USER"),
Value: to.Ptr("DB_USER"),
},
"DB_PASSWORD": {
ValueFrom: &datamodel.EnvironmentVariableReference{
Expand Down
36 changes: 14 additions & 22 deletions 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.

93 changes: 31 additions & 62 deletions pkg/corerp/api/v20231001preview/zz_generated_models_serde.go

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

5 changes: 4 additions & 1 deletion pkg/corerp/datamodel/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ type Container struct {

// EnvironmentVariable - Environment variable for the container
type EnvironmentVariable struct {
Value *string `json:"value,omitempty"`
// Value is the property for the environment variable specified by the user. Such as "key": "value"
Value *string `json:"value,omitempty"`
// ValueFrom is the property for the environment variable specified by a reference to a secret.
ValueFrom *EnvironmentVariableReference `json:"valueFrom,omitempty"`
}

Expand All @@ -141,6 +143,7 @@ type EnvironmentVariableReference struct {

// EnvironmentVariableSecretReference - Environment variable secret reference for the container
type EnvironmentVariableSecretReference struct {
// Source is either the resource id of a radius resource or a kubernetes secret reference.
Source string `json:"source"`
Key string `json:"key"`
}
Expand Down
10 changes: 8 additions & 2 deletions pkg/corerp/renderers/container/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -649,10 +649,16 @@ func convertEnvVar(key string, env datamodel.EnvironmentVariable, options render
if !ok {
return corev1.EnvVar{}, fmt.Errorf("failed to find source in dependencies: %s", env.ValueFrom.SecretRef.Source)
}
// The format may be <namespace>/<name> or <name>

// The format may be <namespace>/<name> or <name>, as an example "default/my-secret" or "my-secret"
var name string
if strings.Contains(secretStore.Properties.Resource, "/") {
name = strings.Split(secretStore.Properties.Resource, "/")[1]
parts := strings.Split(secretStore.Properties.Resource, "/")
if len(parts) == 2 {
name = parts[1]
} else {
name = secretStore.Properties.Resource
}
} else {
name = env.ValueFrom.SecretRef.Source
}
Expand Down
16 changes: 16 additions & 0 deletions pkg/corerp/renderers/container/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,14 @@ func Test_Render_Basic(t *testing.T) {
},
},
},
envVarName4: {
ValueFrom: &datamodel.EnvironmentVariableReference{
SecretRef: &datamodel.EnvironmentVariableSecretReference{
Source: envVarSource4,
Key: envVarValue4,
},
},
},
},
},
}
Expand Down Expand Up @@ -413,6 +421,14 @@ func Test_Render_Basic(t *testing.T) {
Key: envVarValue3,
},
}},
{Name: envVarName4, ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: envVarSource4,
},
Key: envVarValue4,
},
}},
}
require.Equal(t, expectedEnv, container.Env)

Expand Down
5 changes: 0 additions & 5 deletions pkg/to/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ func String(s *string) string {
return ""
}

// StringPtr returns a pointer to the string passed in.
func StringPtr(s string) *string {
return &s
}

// StringSlice returns a string slice value for the passed string slice pointer. It returns a nil
// slice if the pointer is nil.
func StringSlice(s *[]string) []string {
Expand Down
5 changes: 0 additions & 5 deletions pkg/to/value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ func TestString(t *testing.T) {
require.Exactly(t, v, *Ptr(v))
}

func TestStringPtr(t *testing.T) {
v := "foo"
require.Exactly(t, v, *StringPtr(v))
}

func TestStringSlice(t *testing.T) {
v := []string{}
require.Exactly(t, v, StringSlice(&v))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3339,7 +3339,7 @@
"description": "The reference to the variable",
"properties": {
"secretRef": {
"$ref": "#/definitions/EnvironmentVariableSecretReference",
"$ref": "#/definitions/SecretReference",
"description": "The secret reference"
}
},
Expand All @@ -3352,43 +3352,11 @@
"description": "The reference to the variable",
"properties": {
"secretRef": {
"$ref": "#/definitions/EnvironmentVariableSecretReferenceUpdate",
"$ref": "#/definitions/SecretReferenceUpdate",
"description": "The secret reference"
}
}
},
"EnvironmentVariableSecretReference": {
"type": "object",
"description": "The secret reference",
"properties": {
"source": {
"type": "string",
"description": "The secret source identifier"
},
"key": {
"type": "string",
"description": "The secret key"
}
},
"required": [
"source",
"key"
]
},
"EnvironmentVariableSecretReferenceUpdate": {
"type": "object",
"description": "The secret reference",
"properties": {
"source": {
"type": "string",
"description": "The secret source identifier"
},
"key": {
"type": "string",
"description": "The secret key"
}
}
},
"EnvironmentVariableUpdate": {
"type": "object",
"description": "Environment variables type",
Expand Down Expand Up @@ -4722,7 +4690,7 @@
},
"SecretReference": {
"type": "object",
"description": "This secret is used within a recipe. Secrets are encrypted, often have fine-grained access control, auditing and are recommended to be used to hold sensitive data.",
"description": "This specifies a reference to a secret. Secrets are encrypted, often have fine-grained access control, auditing and are recommended to be used to hold sensitive data.",
"properties": {
"source": {
"type": "string",
Expand All @@ -4738,6 +4706,20 @@
"key"
]
},
"SecretReferenceUpdate": {
"type": "object",
"description": "This specifies a reference to a secret. Secrets are encrypted, often have fine-grained access control, auditing and are recommended to be used to hold sensitive data.",
"properties": {
"source": {
"type": "string",
"description": "The ID of an Applications.Core/SecretStore resource containing sensitive data required for recipe execution."
},
"key": {
"type": "string",
"description": "The key for the secret in the secret store."
}
}
},
"SecretStoreDataType": {
"type": "string",
"description": "The type of SecretStore data",
Expand Down
10 changes: 10 additions & 0 deletions typespec/Applications.Core/common.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,13 @@ limitations under the License.
import "@typespec/openapi";

using OpenAPI;


@doc("This specifies a reference to a secret. Secrets are encrypted, often have fine-grained access control, auditing and are recommended to be used to hold sensitive data.")
model SecretReference {
@doc("The ID of an Applications.Core/SecretStore resource containing sensitive data required for recipe execution.")
source: string;

@doc("The key for the secret in the secret store.")
key: string;
}
Loading

0 comments on commit c0d0fe5

Please sign in to comment.