Skip to content

Commit c58644b

Browse files
BarberBarber
authored andcommitted
repair routing. Add bootstrap check
1 parent d6bb5d3 commit c58644b

File tree

11 files changed

+126
-18
lines changed

11 files changed

+126
-18
lines changed

backend/internal/application/enums.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ type AuditLine string
55
const (
66
Config_Updated AuditLine = "Config_Updated"
77
Parameters_Updated = "Parameters_Updated"
8+
9+
Bootstrap_Successful = "Bootstrap_Successful"
10+
11+
Bootstrap_Unsuccessful = "Bootstrap_Unsuccessful"
812
)
913

1014
func (s AuditLine) String() string {

backend/internal/models/websocket.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/internal/processes/bootstrap.go

Lines changed: 65 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
log "github.com/sirupsen/logrus"
55
"github.com/spf13/afero"
66
"github.com/unity-sds/unity-cs-manager/marketplace"
7+
"github.com/unity-sds/unity-management-console/backend/internal/application"
78
"github.com/unity-sds/unity-management-console/backend/internal/application/config"
89
"github.com/unity-sds/unity-management-console/backend/internal/aws"
910
"github.com/unity-sds/unity-management-console/backend/internal/database"
@@ -14,39 +15,83 @@ func BootstrapEnv(appconf *config.AppConfig) {
1415
store, err := database.NewGormDatastore()
1516
if err != nil {
1617
log.WithError(err).Error("Problem creating database")
18+
err = store.AddToAudit(application.Bootstrap_Unsuccessful, "test")
19+
if err != nil {
20+
log.WithError(err).Error("Problem writing to auditlog")
21+
}
22+
return
23+
}
24+
25+
err = provisionS3(appconf)
26+
if err != nil {
27+
err = store.AddToAudit(application.Bootstrap_Unsuccessful, "test")
28+
if err != nil {
29+
log.WithError(err).Error("Problem writing to auditlog")
30+
}
31+
return
32+
}
33+
err = storeDefaultSSMParameters(appconf, store)
34+
if err != nil {
35+
err = store.AddToAudit(application.Bootstrap_Unsuccessful, "test")
36+
if err != nil {
37+
log.WithError(err).Error("Problem writing to auditlog")
38+
}
39+
return
40+
}
41+
err = initTerraform(store, appconf)
42+
if err != nil {
43+
err = store.AddToAudit(application.Bootstrap_Unsuccessful, "test")
44+
if err != nil {
45+
log.WithError(err).Error("Problem writing to auditlog")
46+
}
47+
return
1748
}
18-
provisionS3(appconf)
19-
storeDefaultSSMParameters(appconf, store)
20-
initTerraform(store, appconf)
2149

2250
//r := action.ActRunnerImpl{}
2351
//err = UpdateCoreConfig(appconf, store, nil, "")
2452
//if err != nil {
2553
// log.WithError(err).Error("Problem updating ssm config")
2654
//}
27-
installGateway(store, appconf)
55+
err = installGateway(store, appconf)
56+
if err != nil {
57+
err = store.AddToAudit(application.Bootstrap_Unsuccessful, "test")
58+
if err != nil {
59+
log.WithError(err).Error("Problem writing to auditlog")
60+
}
61+
return
62+
}
63+
64+
err = store.AddToAudit(application.Bootstrap_Successful, "test")
65+
if err != nil {
66+
log.WithError(err).Error("Problem writing to auditlog")
67+
}
68+
2869
}
2970

30-
func provisionS3(appConfig *config.AppConfig) {
71+
func provisionS3(appConfig *config.AppConfig) error {
3172
aws.CreateBucket(nil, appConfig)
3273
err := aws.CreateTable(appConfig)
3374
if err != nil {
3475
log.WithError(err).Error("Error creating table")
35-
return
76+
return err
3677
}
78+
79+
return nil
3780
}
3881

39-
func initTerraform(store database.Datastore, appconf *config.AppConfig) {
82+
func initTerraform(store database.Datastore, appconf *config.AppConfig) error {
4083
fs := afero.NewOsFs()
4184
writeInitTemplate(fs, appconf)
4285
err := installUnityCloudEnv(store, appconf)
4386
if err != nil {
44-
return
87+
return err
4588
}
4689

90+
return nil
91+
4792
}
4893

49-
func writeInitTemplate(fs afero.Fs, appConfig *config.AppConfig) {
94+
func writeInitTemplate(fs afero.Fs, appConfig *config.AppConfig) error {
5095
// Define the terraform configuration
5196
tfconfig := `terraform {
5297
required_providers {
@@ -67,38 +112,45 @@ provider "aws" {
67112
err := fs.MkdirAll(filepath.Join(appConfig.Workdir, "workspace"), 0755)
68113
if err != nil {
69114
log.WithError(err).Error("Couldn't create new working directory")
115+
return err
70116
}
71117

72118
// Create a new file
73119
file, err := fs.Create(filepath.Join(appConfig.Workdir, "workspace", "provider.tf"))
74120
if err != nil {
75121
log.WithError(err).Error("Couldn't create new provider.tf file")
122+
return err
76123
}
77124
defer file.Close()
78125

79126
// Write the configuration to the file
80127
_, err = file.WriteString(tfconfig)
81128
if err != nil {
82129
log.WithError(err).Error("Could not write provider string")
130+
return err
83131
}
84132

85133
// Save changes to the file
86134
err = file.Sync()
87135
if err != nil {
88136
log.WithError(err).Error("Could not write provider.tf")
137+
return err
89138
}
90139

91140
log.Println("File 'provider.tf' has been written")
141+
return nil
92142
}
93-
func storeDefaultSSMParameters(appConfig *config.AppConfig, store database.Datastore) {
143+
func storeDefaultSSMParameters(appConfig *config.AppConfig, store database.Datastore) error {
94144

95145
err := store.StoreSSMParams(appConfig.DefaultSSMParameters, "bootstrap")
96146
if err != nil {
97147
log.WithError(err).Error("Problem storing parameters in database.")
148+
return err
98149
}
150+
return nil
99151
}
100152

101-
func installGateway(store database.Datastore, appConfig *config.AppConfig) {
153+
func installGateway(store database.Datastore, appConfig *config.AppConfig) error {
102154
applications := marketplace.Install_Applications{
103155
Name: "unity-proxy",
104156
Version: "0.1",
@@ -112,7 +164,9 @@ func installGateway(store database.Datastore, appConfig *config.AppConfig) {
112164
err := TriggerInstall(nil, "", store, &install, appConfig)
113165
if err != nil {
114166
log.WithError(err).Error("Issue installing API Gateway")
167+
return err
115168
}
169+
return nil
116170
}
117171

118172
func installUnityCloudEnv(store database.Datastore, appConfig *config.AppConfig) error {

backend/internal/processes/messages.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,26 @@ func fetchConfig(conf *config.AppConfig, store database.Datastore) ([]byte, erro
114114
}
115115
auditline := application.Config_Updated
116116
audit, err := store.FindLastAuditLineByOperation(auditline)
117+
118+
auditline = application.Bootstrap_Unsuccessful
119+
bootstrapfailed, err := store.FindLastAuditLineByOperation(auditline)
120+
121+
auditline = application.Bootstrap_Successful
122+
bootstrapsuccess, err := store.FindLastAuditLineByOperation(auditline)
123+
124+
bsoutput := ""
125+
if bootstrapsuccess.Owner != "" {
126+
bsoutput = "complete"
127+
} else if bootstrapfailed.Owner != "" {
128+
bsoutput = "failed"
129+
}
117130
genconfig := &marketplace.Config{
118131

119132
ApplicationConfig: &appConfig,
120133
NetworkConfig: &netconfig,
121134
Lastupdated: audit.CreatedAt.Format("2006-01-02T15:04:05.000"),
122135
Updatedby: audit.Owner,
136+
Bootstrap: bsoutput,
123137
}
124138

125139
mpcfg := marketplace.UnityWebsocketMessage_Config{Config: genconfig}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ require (
3030
github.com/spf13/viper v1.15.0
3131
github.com/stretchr/testify v1.8.2
3232
github.com/thomaspoignant/go-feature-flag v1.10.2
33-
github.com/unity-sds/unity-cs-manager v0.0.0-20230928140018-edeec42cf112
33+
github.com/unity-sds/unity-cs-manager v0.0.0-20231206163020-d3543a638b81
3434
github.com/zclconf/go-cty v1.13.0
3535
golang.org/x/tools v0.7.0
3636
google.golang.org/protobuf v1.30.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,8 @@ github.com/unity-sds/unity-cs-manager v0.0.0-20230928100015-031bbdfb15df h1:w5w7
439439
github.com/unity-sds/unity-cs-manager v0.0.0-20230928100015-031bbdfb15df/go.mod h1:2AW0iNfvHGRdrb3u6PuheZP0zbV4W2eBIW0+7/6RCfE=
440440
github.com/unity-sds/unity-cs-manager v0.0.0-20230928140018-edeec42cf112 h1:Y0lS5n0heb+LvDKK2ypQTq4QP38Kppt4WRo+48/SPVo=
441441
github.com/unity-sds/unity-cs-manager v0.0.0-20230928140018-edeec42cf112/go.mod h1:2AW0iNfvHGRdrb3u6PuheZP0zbV4W2eBIW0+7/6RCfE=
442+
github.com/unity-sds/unity-cs-manager v0.0.0-20231206163020-d3543a638b81 h1:t6asRKLl6tT4e8CLTyaMtk/nSV1pqf4f867YhbUtf3A=
443+
github.com/unity-sds/unity-cs-manager v0.0.0-20231206163020-d3543a638b81/go.mod h1:2AW0iNfvHGRdrb3u6PuheZP0zbV4W2eBIW0+7/6RCfE=
442444
github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
443445
github.com/vmihailenco/msgpack/v4 v4.3.12/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+NXzzngzBKDPIqw4=
444446
github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI=

src/data/unity-cs-manager/protobuf/extensions.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export interface Config {
7979
networkConfig: Config_NetworkConfig | undefined;
8080
lastupdated: string;
8181
updatedby: string;
82+
bootstrap: string;
8283
}
8384

8485
export interface Config_ApplicationConfig {
@@ -1180,7 +1181,7 @@ export const SimpleMessage = {
11801181
};
11811182

11821183
function createBaseConfig(): Config {
1183-
return { applicationConfig: undefined, networkConfig: undefined, lastupdated: "", updatedby: "" };
1184+
return { applicationConfig: undefined, networkConfig: undefined, lastupdated: "", updatedby: "", bootstrap: "" };
11841185
}
11851186

11861187
export const Config = {
@@ -1197,6 +1198,9 @@ export const Config = {
11971198
if (message.updatedby !== "") {
11981199
writer.uint32(34).string(message.updatedby);
11991200
}
1201+
if (message.bootstrap !== "") {
1202+
writer.uint32(42).string(message.bootstrap);
1203+
}
12001204
return writer;
12011205
},
12021206

@@ -1235,6 +1239,13 @@ export const Config = {
12351239

12361240
message.updatedby = reader.string();
12371241
continue;
1242+
case 5:
1243+
if (tag !== 42) {
1244+
break;
1245+
}
1246+
1247+
message.bootstrap = reader.string();
1248+
continue;
12381249
}
12391250
if ((tag & 7) === 4 || tag === 0) {
12401251
break;
@@ -1252,6 +1263,7 @@ export const Config = {
12521263
networkConfig: isSet(object.networkConfig) ? Config_NetworkConfig.fromJSON(object.networkConfig) : undefined,
12531264
lastupdated: isSet(object.lastupdated) ? String(object.lastupdated) : "",
12541265
updatedby: isSet(object.updatedby) ? String(object.updatedby) : "",
1266+
bootstrap: isSet(object.bootstrap) ? String(object.bootstrap) : "",
12551267
};
12561268
},
12571269

@@ -1264,6 +1276,7 @@ export const Config = {
12641276
(obj.networkConfig = message.networkConfig ? Config_NetworkConfig.toJSON(message.networkConfig) : undefined);
12651277
message.lastupdated !== undefined && (obj.lastupdated = message.lastupdated);
12661278
message.updatedby !== undefined && (obj.updatedby = message.updatedby);
1279+
message.bootstrap !== undefined && (obj.bootstrap = message.bootstrap);
12671280
return obj;
12681281
},
12691282

@@ -1281,6 +1294,7 @@ export const Config = {
12811294
: undefined;
12821295
message.lastupdated = object.lastupdated ?? "";
12831296
message.updatedby = object.updatedby ?? "";
1297+
message.bootstrap = object.bootstrap ?? "";
12841298
return message;
12851299
},
12861300
};

src/routes/+page.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ import { redirect } from '@sveltejs/kit';
22
import type { PageLoad } from './$types';
33

44
export const load: PageLoad = async () => {
5-
throw redirect(301, '/dev/mgmtproxy/ui/landing');
5+
throw redirect(301, '/ui/landing');
66
};

src/routes/landing/+page.svelte

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,19 @@
1717
});
1818
1919
let setuprun: boolean;
20+
let bootstrapfailed: boolean;
21+
let bootstrapped: boolean;
2022
$: {
23+
if (conf && conf.bootstrap == "complete") {
24+
bootstrapped = true;
25+
bootstrapfailed = false;
26+
} else if (conf && conf.bootstrap == "failed") {
27+
bootstrapped = false;
28+
bootstrapfailed = true;
29+
} else if (conf && conf.bootstrap == "") {
30+
bootstrapped = false;
31+
bootstrapfailed = false;
32+
}
2133
setuprun = !!(conf && conf.updatedby !== "");
2234
}
2335
$: cardData = [
@@ -50,7 +62,15 @@
5062
<div class="container mx-auto">
5163
<div class="flex justify-center">
5264
<div class="flex-initial">
53-
{#if !setuprun}
65+
{#if bootstrapfailed}
66+
<div>
67+
<h5 class="text-xl">The Bootstrap Process Failed Please Check The Logs</h5>
68+
</div>
69+
{:else if !bootstrapped}
70+
<div>
71+
<h5 class="text-xl">Bootstrap is either in progress or has not been run</h5>
72+
</div>
73+
{:else if !setuprun}
5474
<div>
5575
<h5 class="text-xl">Setup has not been run, please go to Core Management</h5>
5676
</div>

svelte.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const config = {
1717
}),
1818
paths: {
1919
// base path on the server
20-
base: '/dev/mgmtproxy/ui'
20+
base: '/ui'
2121
}
2222
}
2323
};

0 commit comments

Comments
 (0)