Skip to content

Commit

Permalink
allow private to be missing without using default of false (#3616)
Browse files Browse the repository at this point in the history
  • Loading branch information
ianedwards authored Sep 20, 2023
1 parent a208a76 commit 560a76a
Show file tree
Hide file tree
Showing 14 changed files with 75 additions and 62 deletions.
2 changes: 1 addition & 1 deletion api/server/handlers/porter_app/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func addPorterSubdomainsIfNecessary(ctx context.Context, app *porterv1.PorterApp

webConfig := service.GetWebConfig()

if !webConfig.Private && len(webConfig.Domains) == 0 {
if !webConfig.GetPrivate() && len(webConfig.Domains) == 0 {
subdomain, err := porter_app.CreatePorterSubdomain(ctx, createSubdomainInput)
if err != nil {
return app, fmt.Errorf("error creating subdomain: %w", err)
Expand Down
14 changes: 7 additions & 7 deletions dashboard/package-lock.json

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

2 changes: 1 addition & 1 deletion dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"@loadable/component": "^5.15.2",
"@material-ui/core": "^4.11.3",
"@material-ui/lab": "^4.0.0-alpha.61",
"@porter-dev/api-contracts": "^0.1.4",
"@porter-dev/api-contracts": "^0.1.7",
"@react-spring/web": "^9.6.1",
"@sentry/react": "^6.13.2",
"@sentry/tracing": "^6.13.2",
Expand Down
22 changes: 11 additions & 11 deletions dashboard/src/lib/hooks/usePorterYaml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import { z } from "zod";

type PorterYamlStatus =
| {
loading: true;
detectedName: null;
detectedServices: null;
porterYamlFound: false;
}
loading: true;
detectedName: null;
detectedServices: null;
porterYamlFound: false;
}
| {
detectedServices: DetectedServices | null;
detectedName: string | null;
loading: false;
porterYamlFound: boolean;
};
detectedServices: DetectedServices | null;
detectedName: string | null;
loading: false;
porterYamlFound: boolean;
};

/*
*
Expand Down Expand Up @@ -107,7 +107,7 @@ export const usePorterYaml = ({
try {
const res = await api.parsePorterYaml(
"<token>",
{ b64_yaml: b64Yaml, app_name: appName},
{ b64_yaml: b64Yaml, app_name: appName },
{
project_id: projectId,
cluster_id: clusterId,
Expand Down
3 changes: 2 additions & 1 deletion dashboard/src/lib/porter-apps/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,11 @@ export function clientAppFromProto({
);

if (override) {
return deserializeService({
const ds = deserializeService({
service: svc,
override: serializeService(override),
});
return ds;
}
return deserializeService({ service: svc });
});
Expand Down
62 changes: 31 additions & 31 deletions dashboard/src/lib/porter-apps/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ export const serviceValidator = z.object({
autoscaling: autoscalingValidator.optional(),
domains: domainsValidator,
healthCheck: healthcheckValidator.optional(),
private: serviceBooleanValidator.default({
value: false,
readOnly: false,
}),
private: serviceBooleanValidator.optional(),
}),
z.object({
type: z.literal("worker"),
Expand Down Expand Up @@ -72,27 +69,27 @@ export type SerializedService = {
cpuCores: number;
ramMegabytes: number;
config:
| {
type: "web";
domains: {
name: string;
}[];
autoscaling?: SerializedAutoscaling;
healthCheck?: SerializedHealthcheck;
private: boolean;
}
| {
type: "worker";
autoscaling?: SerializedAutoscaling;
}
| {
type: "job";
allowConcurrent: boolean;
cron: string;
}
| {
type: "predeploy";
};
| {
type: "web";
domains: {
name: string;
}[];
autoscaling?: SerializedAutoscaling;
healthCheck?: SerializedHealthcheck;
private?: boolean;
}
| {
type: "worker";
autoscaling?: SerializedAutoscaling;
}
| {
type: "job";
allowConcurrent: boolean;
cron: string;
}
| {
type: "predeploy";
};
};

export function isPredeployService(service: SerializedService | ClientService) {
Expand Down Expand Up @@ -192,7 +189,7 @@ export function serializeService(service: ClientService): SerializedService {
domains: config.domains.map((domain) => ({
name: domain.name.value,
})),
private: config.private.value,
private: config.private?.value,
},
})
)
Expand Down Expand Up @@ -286,18 +283,21 @@ export function deserializeService({
override: overrideWebConfig?.healthCheck,
}),

domains: Array.from(new Set([...config.domains, ...(overrideWebConfig?.domains ?? [])])).map((domain) => ({
domains: Array.from(
new Set([...config.domains, ...(overrideWebConfig?.domains ?? [])])
).map((domain) => ({
name: ServiceField.string(
domain.name,
overrideWebConfig?.domains.find(
(overrideDomain) => overrideDomain.name == domain.name
)?.name
),
})),
private: ServiceField.boolean(
config.private,
overrideWebConfig?.private
),
private:
typeof config.private === "boolean" ||
typeof overrideWebConfig?.private === "boolean"
? ServiceField.boolean(config.private, overrideWebConfig?.private)
: undefined,
},
};
})
Expand Down
9 changes: 6 additions & 3 deletions dashboard/src/lib/porter-apps/values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,13 @@ export const ServiceField = {
value: getNumericValue(defaultValue, overrideValue, validAsZero),
};
},
boolean: (defaultValue: boolean, overrideValue?: boolean): ServiceBoolean => {
boolean: (
defaultValue?: boolean,
overrideValue?: boolean
): ServiceBoolean => {
return {
readOnly: overrideValue != null,
value: overrideValue ?? defaultValue,
readOnly: typeof overrideValue === "boolean",
value: overrideValue ?? defaultValue ?? false,
};
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const Networking: React.FC<NetworkingProps> = ({ index, service }) => {
render={({ field: { value, onChange } }) => (
<Checkbox
checked={!value}
disabled={service.config.private.readOnly}
disabled={service.config.private?.readOnly}
toggleChecked={() => {
onChange(!value);
}}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ require (
github.com/matryer/is v1.4.0
github.com/nats-io/nats.go v1.24.0
github.com/open-policy-agent/opa v0.44.0
github.com/porter-dev/api-contracts v0.1.6
github.com/porter-dev/api-contracts v0.1.7
github.com/riandyrn/otelchi v0.5.1
github.com/santhosh-tekuri/jsonschema/v5 v5.0.1
github.com/stefanmcshane/helm v0.0.0-20221213002717-88a4a2c6e77d
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1516,8 +1516,8 @@ github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/polyfloyd/go-errorlint v0.0.0-20210722154253-910bb7978349/go.mod h1:wi9BfjxjF/bwiZ701TzmfKu6UKC357IOAtNr0Td0Lvw=
github.com/porter-dev/api-contracts v0.1.6 h1:nMP/+M53Mohwe/1mNq/HYEnfIKEiDHEFItZwjLmPZ+8=
github.com/porter-dev/api-contracts v0.1.6/go.mod h1:fX6JmP5QuzxDLvqP3evFOTXjI4dHxsG0+VKNTjImZU8=
github.com/porter-dev/api-contracts v0.1.7 h1:Mxua9qTur0HIhIS4gmK0a9sLcHrgJfFwSQI0CxZBkh4=
github.com/porter-dev/api-contracts v0.1.7/go.mod h1:fX6JmP5QuzxDLvqP3evFOTXjI4dHxsG0+VKNTjImZU8=
github.com/porter-dev/switchboard v0.0.3 h1:dBuYkiVLa5Ce7059d6qTe9a1C2XEORFEanhbtV92R+M=
github.com/porter-dev/switchboard v0.0.3/go.mod h1:xSPzqSFMQ6OSbp42fhCi4AbGbQbsm6nRvOkrblFeXU4=
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
Expand Down
2 changes: 2 additions & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,8 @@ github.com/pkg/sftp v1.10.1 h1:VasscCm72135zRysgrJDKsntdmPN+OuU3+nnHYA9wyc=
github.com/polyfloyd/go-errorlint v0.0.0-20210722154253-910bb7978349 h1:Kq/3kL0k033ds3tyez5lFPrfQ74fNJ+OqCclRipubwA=
github.com/porter-dev/api-contracts v0.0.63/go.mod h1:qr2L58mJLr5DUGV5OPw3REiSrQvJq6TgkKyEWP95dyU=
github.com/porter-dev/api-contracts v0.0.86/go.mod h1:fX6JmP5QuzxDLvqP3evFOTXjI4dHxsG0+VKNTjImZU8=
github.com/porter-dev/api-contracts v0.1.7 h1:Mxua9qTur0HIhIS4gmK0a9sLcHrgJfFwSQI0CxZBkh4=
github.com/porter-dev/api-contracts v0.1.7/go.mod h1:fX6JmP5QuzxDLvqP3evFOTXjI4dHxsG0+VKNTjImZU8=
github.com/posener/complete v1.2.3 h1:NP0eAhjcjImqslEwo/1hq7gpajME0fTLTezBKDqfXqo=
github.com/pquerna/cachecontrol v0.1.0 h1:yJMy84ti9h/+OEWa752kBTKv4XC30OtVVHYv/8cTqKc=
github.com/pquerna/cachecontrol v0.1.0/go.mod h1:NrUG3Z7Rdu85UNR3vm7SOsl1nFIeSiQnrHV5K9mBcUI=
Expand Down
2 changes: 2 additions & 0 deletions internal/porter_app/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"testing"

"google.golang.org/protobuf/encoding/protojson"
"k8s.io/utils/pointer"

porterv1 "github.com/porter-dev/api-contracts/generated/go/porter/v1"
"github.com/sergi/go-diff/diffmatchpatch"
Expand Down Expand Up @@ -173,6 +174,7 @@ var v1_result_nobuild_no_image = &porterv1.PorterApp{
Enabled: true,
HttpPath: "/healthz",
},
Private: pointer.Bool(false),
},
},
Type: 1,
Expand Down
4 changes: 3 additions & 1 deletion internal/porter_app/v1/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,9 @@ func webConfigProtoFromConfig(service Service) (*porterv1.WebServiceConfig, erro
return nil, errors.New("annotations are not supported")
}
webConfig.Domains = domains
webConfig.Private = !service.Config.Ingress.Enabled

private := !service.Config.Ingress.Enabled
webConfig.Private = &private
}

return webConfig, nil
Expand Down
7 changes: 5 additions & 2 deletions internal/porter_app/v2/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ type Service struct {
HealthCheck *HealthCheck `yaml:"healthCheck,omitempty" validate:"excluded_unless=Type web"`
AllowConcurrent bool `yaml:"allowConcurrent" validate:"excluded_unless=Type job"`
Cron string `yaml:"cron" validate:"excluded_unless=Type job"`
Private bool `yaml:"private" validate:"excluded_unless=Type web"`
Private *bool `yaml:"private" validate:"excluded_unless=Type web"`
}

// AutoScaling represents the autoscaling settings for web services
Expand Down Expand Up @@ -232,7 +232,10 @@ func serviceProtoFromConfig(service Service, serviceType porterv1.ServiceType) (
})
}
webConfig.Domains = domains
webConfig.Private = service.Private

if service.Private != nil {
webConfig.Private = service.Private
}

serviceProto.Config = &porterv1.Service_WebConfig{
WebConfig: webConfig,
Expand Down

0 comments on commit 560a76a

Please sign in to comment.