Help us shape the future of Go! Take the 2026 Go Developer Survey

profile

package
v1.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 31, 2023 License: Apache-2.0 Imports: 44 Imported by: 0

Documentation

Overview

Package profile is for specific profiles @todo this package is the definition of cruft and should be rewritten in a more elegant way

Index

Constants

This section is empty.

Variables

View Source
var Client = &Profile{
	Name:  "client",
	Setup: func(ctx *cli.Context) error { return nil },
}

Client profile is for any entrypoint that behaves as a client

View Source
var Local = &Profile{
	Name: "local",
	Setup: func(ctx *cli.Context) error {

		client.DefaultClient = grpcClient.NewClient()
		server.DefaultServer = grpcServer.NewServer()

		microAuth.DefaultAuth = jwt.NewAuth()
		microStore.DefaultStore = file.NewStore(file.WithDir(filepath.Join(user.Dir, "server", "store")))
		SetupConfigSecretKey(ctx)
		config.DefaultConfig, _ = storeConfig.NewConfig(microStore.DefaultStore, "")

		SetupJWT(ctx)
		SetupRegistry(memory.NewRegistry())
		SetupBroker(memBroker.NewBroker())

		model.DefaultModel = model.NewModel(
			model.WithStore(microStore.DefaultStore),
		)

		microRuntime.DefaultRuntime = local.NewRuntime()

		var err error
		microEvents.DefaultStream, err = memStream.NewStream()
		if err != nil {
			logger.Fatalf("Error configuring stream: %v", err)
		}
		microEvents.DefaultStore = evStore.NewStore(
			evStore.WithStore(microStore.DefaultStore),
		)

		microStore.DefaultBlobStore, err = file.NewBlobStore()
		if err != nil {
			logger.Fatalf("Error configuring file blob store: %v", err)
		}

		return nil
	},
}

Local profile to run as a single process

View Source
var Platform = &Profile{
	Name: "platform",
	Setup: func(ctx *cli.Context) error {
		var retErr error
		platformOnce.Do(func() {
			auth.DefaultAuth = jwt.NewAuth()

			store.DefaultStore = postgres.NewStore(store.Nodes(ctx.String("store_address")))
			SetupBroker(redisBroker.NewBroker(broker.Addrs(ctx.String("broker_address"))))
			SetupRegistry(etcd.NewRegistry(registry.Addrs(ctx.String("registry_address"))))
			SetupJWT(ctx)
			SetupConfigSecretKey(ctx)

			var err error
			if ctx.Args().Get(1) == "events" {
				events.DefaultStream, err = redisstream.NewStream(redisStreamOpts(ctx)...)
				if err != nil {
					logger.Fatalf("Error configuring stream: %v", err)
				}

				opts := []s3.Option{
					s3.Credentials(
						os.Getenv("MICRO_EVENTS_STORE_ACCESS_KEY"),
						os.Getenv("MICRO_EVENTS_STORE_SECRET_KEY"),
					),
					s3.Endpoint(os.Getenv("MICRO_EVENTS_STORE_ENDPOINT")),
					s3.Region(os.Getenv("MICRO_EVENTS_STORE_REGION")),
					s3.Bucket(os.Getenv("MICRO_EVENTS_STORE_BUCKET")),
				}

				events.DefaultStore = evStore.NewStore(
					evStore.WithStore(store.DefaultStore),
					evStore.WithBackup(s3.NewBackup(opts...)),
				)

			}

			if ctx.Args().Get(1) == "runtime" || ctx.Args().Get(1) == "store" {
				opts := []s3.Option{
					s3.Credentials(
						os.Getenv("MICRO_BLOB_STORE_ACCESS_KEY"),
						os.Getenv("MICRO_BLOB_STORE_SECRET_KEY"),
					),
					s3.Endpoint(os.Getenv("MICRO_BLOB_STORE_ENDPOINT")),
					s3.Region(os.Getenv("MICRO_BLOB_STORE_REGION")),
					s3.Bucket(os.Getenv("MICRO_BLOB_STORE_BUCKET")),
				}
				if val := os.Getenv("MICRO_BLOB_STORE_INSECURE"); len(val) > 0 {
					opts = append(opts, s3.Insecure())
				}

				store.DefaultBlobStore, err = s3.NewBlobStore(opts...)
				if err != nil {
					logger.Fatalf("Error configuring s3 blob store: %v", err)
				}
			}

			microRuntime.DefaultRuntime = kubernetes.NewRuntime()
			microBuilder.DefaultBuilder, err = golang.NewBuilder()
			if err != nil {
				logger.Fatalf("Error configuring golang builder: %v", err)
			}

			kubernetes.DefaultImage = "ghcr.io/m3o/cells:v3"
		})
		return retErr
	},
}

Profile is for running the micro platform

View Source
var PlatformClient = &Profile{
	Name: "platform_client",
	Setup: func(ctx *cli.Context) error {
		var retErr error
		clientOnce.Do(func() {
			auth2.DefaultBlockList = blocklist.New(
				os.Getenv("MICRO_API_REDIS_ADDRESS"),
				os.Getenv("MICRO_API_REDIS_USER"),
				os.Getenv("MICRO_API_REDIS_PASSWORD"),
				&tls.Config{})
		})
		return retErr
	},
}
View Source
var Server = &Profile{
	Name: "server",
	Setup: func(ctx *cli.Context) error {
		microAuth.DefaultAuth = jwt.NewAuth()
		microStore.DefaultStore = file.NewStore(file.WithDir(filepath.Join(user.Dir, "server", "store")))
		SetupConfigSecretKey(ctx)
		config.DefaultConfig, _ = storeConfig.NewConfig(microStore.DefaultStore, "")
		SetupJWT(ctx)

		if ctx.Args().Get(1) == "registry" {
			SetupRegistry(memory.NewRegistry())
		} else {

			registry.DefaultRegistry.Init(
				registry.Addrs("localhost:8000"),
			)

			SetupRegistry(registry.DefaultRegistry)
		}

		if ctx.Args().Get(1) == "broker" {
			SetupBroker(memBroker.NewBroker())
		} else {
			broker.DefaultBroker.Init(
				broker.Addrs("localhost:8003"),
			)
			SetupBroker(broker.DefaultBroker)
		}

		model.DefaultModel = model.NewModel(
			model.WithStore(microStore.DefaultStore),
		)

		microRuntime.DefaultRuntime = local.NewRuntime()

		var err error
		microEvents.DefaultStream, err = memStream.NewStream()
		if err != nil {
			logger.Fatalf("Error configuring stream: %v", err)
		}
		microEvents.DefaultStore = evStore.NewStore(
			evStore.WithStore(microStore.DefaultStore),
		)

		microStore.DefaultBlobStore, err = file.NewBlobStore()
		if err != nil {
			logger.Fatalf("Error configuring file blob store: %v", err)
		}

		return nil
	},
}
View Source
var Service = &Profile{
	Name:  "service",
	Setup: func(ctx *cli.Context) error { return nil },
}

Service is the default for any services run

View Source
var Test = &Profile{
	Name: "test",
	Setup: func(ctx *cli.Context) error {
		microAuth.DefaultAuth = noop.NewAuth()
		microStore.DefaultStore = mem.NewStore()
		microStore.DefaultBlobStore, _ = file.NewBlobStore()
		config.DefaultConfig, _ = storeConfig.NewConfig(microStore.DefaultStore, "")
		SetupRegistry(memory.NewRegistry())

		model.DefaultModel = model.NewModel(
			model.WithStore(microStore.DefaultStore),
		)
		return nil
	},
}

Test profile is used for the go test suite

Functions

func Register

func Register(name string, p *Profile) error

Register a profile

func SetupBroker

func SetupBroker(b broker.Broker)

SetupBroker configures the broker

func SetupConfigSecretKey

func SetupConfigSecretKey(ctx *cli.Context)

func SetupJWT

func SetupJWT(ctx *cli.Context)

SetupJWT configures the default internal system rules

func SetupRegistry

func SetupRegistry(reg registry.Registry)

SetupRegistry configures the registry

Types

type Profile

type Profile struct {
	// name of the profile
	Name string
	// function used for setup
	Setup func(*cli.Context) error
}

Profile configures an environment

func Load

func Load(name string) (*Profile, error)

Load a profile

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL