Skip to content

Commit

Permalink
repair routing. Add bootstrap check
Browse files Browse the repository at this point in the history
  • Loading branch information
Barber authored and Barber committed Dec 6, 2023
1 parent d6bb5d3 commit c58644b
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 18 deletions.
4 changes: 4 additions & 0 deletions backend/internal/application/enums.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ type AuditLine string
const (
Config_Updated AuditLine = "Config_Updated"
Parameters_Updated = "Parameters_Updated"

Bootstrap_Successful = "Bootstrap_Successful"

Bootstrap_Unsuccessful = "Bootstrap_Unsuccessful"
)

func (s AuditLine) String() string {
Expand Down
2 changes: 1 addition & 1 deletion backend/internal/models/websocket.pb.go

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

76 changes: 65 additions & 11 deletions backend/internal/processes/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
log "github.com/sirupsen/logrus"
"github.com/spf13/afero"
"github.com/unity-sds/unity-cs-manager/marketplace"
"github.com/unity-sds/unity-management-console/backend/internal/application"
"github.com/unity-sds/unity-management-console/backend/internal/application/config"
"github.com/unity-sds/unity-management-console/backend/internal/aws"
"github.com/unity-sds/unity-management-console/backend/internal/database"
Expand All @@ -14,39 +15,83 @@ func BootstrapEnv(appconf *config.AppConfig) {
store, err := database.NewGormDatastore()
if err != nil {
log.WithError(err).Error("Problem creating database")
err = store.AddToAudit(application.Bootstrap_Unsuccessful, "test")
if err != nil {
log.WithError(err).Error("Problem writing to auditlog")
}
return
}

err = provisionS3(appconf)
if err != nil {
err = store.AddToAudit(application.Bootstrap_Unsuccessful, "test")
if err != nil {
log.WithError(err).Error("Problem writing to auditlog")
}
return
}
err = storeDefaultSSMParameters(appconf, store)
if err != nil {
err = store.AddToAudit(application.Bootstrap_Unsuccessful, "test")
if err != nil {
log.WithError(err).Error("Problem writing to auditlog")
}
return
}
err = initTerraform(store, appconf)
if err != nil {
err = store.AddToAudit(application.Bootstrap_Unsuccessful, "test")
if err != nil {
log.WithError(err).Error("Problem writing to auditlog")
}
return
}
provisionS3(appconf)
storeDefaultSSMParameters(appconf, store)
initTerraform(store, appconf)

//r := action.ActRunnerImpl{}
//err = UpdateCoreConfig(appconf, store, nil, "")
//if err != nil {
// log.WithError(err).Error("Problem updating ssm config")
//}
installGateway(store, appconf)
err = installGateway(store, appconf)
if err != nil {
err = store.AddToAudit(application.Bootstrap_Unsuccessful, "test")
if err != nil {
log.WithError(err).Error("Problem writing to auditlog")
}
return
}

err = store.AddToAudit(application.Bootstrap_Successful, "test")
if err != nil {
log.WithError(err).Error("Problem writing to auditlog")
}

}

func provisionS3(appConfig *config.AppConfig) {
func provisionS3(appConfig *config.AppConfig) error {
aws.CreateBucket(nil, appConfig)
err := aws.CreateTable(appConfig)
if err != nil {
log.WithError(err).Error("Error creating table")
return
return err
}

return nil
}

func initTerraform(store database.Datastore, appconf *config.AppConfig) {
func initTerraform(store database.Datastore, appconf *config.AppConfig) error {
fs := afero.NewOsFs()
writeInitTemplate(fs, appconf)
err := installUnityCloudEnv(store, appconf)
if err != nil {
return
return err
}

return nil

}

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

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

// Write the configuration to the file
_, err = file.WriteString(tfconfig)
if err != nil {
log.WithError(err).Error("Could not write provider string")
return err
}

// Save changes to the file
err = file.Sync()
if err != nil {
log.WithError(err).Error("Could not write provider.tf")
return err
}

log.Println("File 'provider.tf' has been written")
return nil
}
func storeDefaultSSMParameters(appConfig *config.AppConfig, store database.Datastore) {
func storeDefaultSSMParameters(appConfig *config.AppConfig, store database.Datastore) error {

err := store.StoreSSMParams(appConfig.DefaultSSMParameters, "bootstrap")
if err != nil {
log.WithError(err).Error("Problem storing parameters in database.")
return err
}
return nil
}

func installGateway(store database.Datastore, appConfig *config.AppConfig) {
func installGateway(store database.Datastore, appConfig *config.AppConfig) error {
applications := marketplace.Install_Applications{
Name: "unity-proxy",
Version: "0.1",
Expand All @@ -112,7 +164,9 @@ func installGateway(store database.Datastore, appConfig *config.AppConfig) {
err := TriggerInstall(nil, "", store, &install, appConfig)
if err != nil {
log.WithError(err).Error("Issue installing API Gateway")
return err
}
return nil
}

func installUnityCloudEnv(store database.Datastore, appConfig *config.AppConfig) error {
Expand Down
14 changes: 14 additions & 0 deletions backend/internal/processes/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,26 @@ func fetchConfig(conf *config.AppConfig, store database.Datastore) ([]byte, erro
}
auditline := application.Config_Updated
audit, err := store.FindLastAuditLineByOperation(auditline)

auditline = application.Bootstrap_Unsuccessful
bootstrapfailed, err := store.FindLastAuditLineByOperation(auditline)

auditline = application.Bootstrap_Successful
bootstrapsuccess, err := store.FindLastAuditLineByOperation(auditline)

bsoutput := ""
if bootstrapsuccess.Owner != "" {
bsoutput = "complete"
} else if bootstrapfailed.Owner != "" {
bsoutput = "failed"
}
genconfig := &marketplace.Config{

ApplicationConfig: &appConfig,
NetworkConfig: &netconfig,
Lastupdated: audit.CreatedAt.Format("2006-01-02T15:04:05.000"),
Updatedby: audit.Owner,
Bootstrap: bsoutput,
}

mpcfg := marketplace.UnityWebsocketMessage_Config{Config: genconfig}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ require (
github.com/spf13/viper v1.15.0
github.com/stretchr/testify v1.8.2
github.com/thomaspoignant/go-feature-flag v1.10.2
github.com/unity-sds/unity-cs-manager v0.0.0-20230928140018-edeec42cf112
github.com/unity-sds/unity-cs-manager v0.0.0-20231206163020-d3543a638b81
github.com/zclconf/go-cty v1.13.0
golang.org/x/tools v0.7.0
google.golang.org/protobuf v1.30.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,8 @@ github.com/unity-sds/unity-cs-manager v0.0.0-20230928100015-031bbdfb15df h1:w5w7
github.com/unity-sds/unity-cs-manager v0.0.0-20230928100015-031bbdfb15df/go.mod h1:2AW0iNfvHGRdrb3u6PuheZP0zbV4W2eBIW0+7/6RCfE=
github.com/unity-sds/unity-cs-manager v0.0.0-20230928140018-edeec42cf112 h1:Y0lS5n0heb+LvDKK2ypQTq4QP38Kppt4WRo+48/SPVo=
github.com/unity-sds/unity-cs-manager v0.0.0-20230928140018-edeec42cf112/go.mod h1:2AW0iNfvHGRdrb3u6PuheZP0zbV4W2eBIW0+7/6RCfE=
github.com/unity-sds/unity-cs-manager v0.0.0-20231206163020-d3543a638b81 h1:t6asRKLl6tT4e8CLTyaMtk/nSV1pqf4f867YhbUtf3A=
github.com/unity-sds/unity-cs-manager v0.0.0-20231206163020-d3543a638b81/go.mod h1:2AW0iNfvHGRdrb3u6PuheZP0zbV4W2eBIW0+7/6RCfE=
github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
github.com/vmihailenco/msgpack/v4 v4.3.12/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+NXzzngzBKDPIqw4=
github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI=
Expand Down
16 changes: 15 additions & 1 deletion src/data/unity-cs-manager/protobuf/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export interface Config {
networkConfig: Config_NetworkConfig | undefined;
lastupdated: string;
updatedby: string;
bootstrap: string;
}

export interface Config_ApplicationConfig {
Expand Down Expand Up @@ -1180,7 +1181,7 @@ export const SimpleMessage = {
};

function createBaseConfig(): Config {
return { applicationConfig: undefined, networkConfig: undefined, lastupdated: "", updatedby: "" };
return { applicationConfig: undefined, networkConfig: undefined, lastupdated: "", updatedby: "", bootstrap: "" };
}

export const Config = {
Expand All @@ -1197,6 +1198,9 @@ export const Config = {
if (message.updatedby !== "") {
writer.uint32(34).string(message.updatedby);
}
if (message.bootstrap !== "") {
writer.uint32(42).string(message.bootstrap);
}
return writer;
},

Expand Down Expand Up @@ -1235,6 +1239,13 @@ export const Config = {

message.updatedby = reader.string();
continue;
case 5:
if (tag !== 42) {
break;
}

message.bootstrap = reader.string();
continue;
}
if ((tag & 7) === 4 || tag === 0) {
break;
Expand All @@ -1252,6 +1263,7 @@ export const Config = {
networkConfig: isSet(object.networkConfig) ? Config_NetworkConfig.fromJSON(object.networkConfig) : undefined,
lastupdated: isSet(object.lastupdated) ? String(object.lastupdated) : "",
updatedby: isSet(object.updatedby) ? String(object.updatedby) : "",
bootstrap: isSet(object.bootstrap) ? String(object.bootstrap) : "",
};
},

Expand All @@ -1264,6 +1276,7 @@ export const Config = {
(obj.networkConfig = message.networkConfig ? Config_NetworkConfig.toJSON(message.networkConfig) : undefined);
message.lastupdated !== undefined && (obj.lastupdated = message.lastupdated);
message.updatedby !== undefined && (obj.updatedby = message.updatedby);
message.bootstrap !== undefined && (obj.bootstrap = message.bootstrap);
return obj;
},

Expand All @@ -1281,6 +1294,7 @@ export const Config = {
: undefined;
message.lastupdated = object.lastupdated ?? "";
message.updatedby = object.updatedby ?? "";
message.bootstrap = object.bootstrap ?? "";
return message;
},
};
Expand Down
2 changes: 1 addition & 1 deletion src/routes/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import { redirect } from '@sveltejs/kit';
import type { PageLoad } from './$types';

export const load: PageLoad = async () => {
throw redirect(301, '/dev/mgmtproxy/ui/landing');
throw redirect(301, '/ui/landing');
};
22 changes: 21 additions & 1 deletion src/routes/landing/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,19 @@
});
let setuprun: boolean;
let bootstrapfailed: boolean;
let bootstrapped: boolean;
$: {
if (conf && conf.bootstrap == "complete") {
bootstrapped = true;
bootstrapfailed = false;
} else if (conf && conf.bootstrap == "failed") {
bootstrapped = false;
bootstrapfailed = true;
} else if (conf && conf.bootstrap == "") {
bootstrapped = false;
bootstrapfailed = false;
}
setuprun = !!(conf && conf.updatedby !== "");
}
$: cardData = [
Expand Down Expand Up @@ -50,7 +62,15 @@
<div class="container mx-auto">
<div class="flex justify-center">
<div class="flex-initial">
{#if !setuprun}
{#if bootstrapfailed}
<div>
<h5 class="text-xl">The Bootstrap Process Failed Please Check The Logs</h5>
</div>
{:else if !bootstrapped}
<div>
<h5 class="text-xl">Bootstrap is either in progress or has not been run</h5>
</div>
{:else if !setuprun}
<div>
<h5 class="text-xl">Setup has not been run, please go to Core Management</h5>
</div>
Expand Down
2 changes: 1 addition & 1 deletion svelte.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const config = {
}),
paths: {
// base path on the server
base: '/dev/mgmtproxy/ui'
base: '/ui'
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion unity-cs-manager

0 comments on commit c58644b

Please sign in to comment.