golang

package module
v0.0.0-...-a9240ff Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2023 License: AGPL-3.0 Imports: 26 Imported by: 1

Documentation

Index

Constants

View Source
const (
	UserAccessAnonPublic = "anon_public"
	UserAccessNone       = "none"
)

Service is a representation of an individual service defined within a Bopmatic project. This includes its name, a short description, a link to the set of APIs it defines, and the port it should run on. Fields marked with yaml are parsed from Bopmatic.yaml while the remaining fields are derived once the project is parsed (e.g. when NewProject() returns successfully). Currently the only supported ApiDefinition format is protobuf/GRPC

View Source
const (
	UserGroupTypePublic  = "public"
	UserGroupTypePrivate = "private"
)
View Source
const (
	FormatVersion1_0     = "1.0"
	FormatVersion1_1     = "1.1"
	FormatVersionCurrent = FormatVersion1_1
)

Project is a full representation of a Bopmatic project, which defines a set of services to publish, their RPCs, their TCP ports to run on, and a collection of static website assets to publish. FormatVersion describes the set of supported and expected fields within a Bopmatic.yaml project description. Currently this is expected to be "1.1". Older "1.0" existing templates are also supported. This field is intended to be used for backward compatibility. Fields marked with yaml are parsed from Bopmatic.yaml while the remaining fields are derived once the project is parsed (e.g. when NewProject() returns successfully).

Differences between formatversion 1.0 and 1.1:

1.1 introduces usergroups & relationships between usersgroups and
    services for access control purposes. In version 1.0 as usergroups
    had not yet been introduced, all defined services were implictly
    vended with anonymous public access by default. In version 1.1, the
    default access is instead none.
View Source
const DefaultArtifactDir = ".bopmatic"
View Source
const DefaultProjectFilename = "Bopmatic.yaml"
View Source
const PackagesSubdir = "pkgs"

Variables

This section is empty.

Functions

func Delete

func Delete(packageId string, opts ...DeployOption) error

Delete() implemented using a client generated with go-swagger:

https://github.com/go-swagger/go-swagger

func Describe

func Describe(packageId string, opts ...DeployOption) (*pb.DescribePackageReply, error)

Describe() implemented using a client generated with go-swagger:

https://github.com/go-swagger/go-swagger

func IsGoodProjectName

func IsGoodProjectName(projectName string) (bool, error)

func List

func List(projName string,
	opts ...DeployOption) ([]pb.ListPackagesReply_ListPackagesItem, error)

List() implemented using a client generated with go-swagger:

https://github.com/go-swagger/go-swagger

func RemoveStalePackages

func RemoveStalePackages(proj *Project) error

Types

type Database

type Database struct {
	Name        string          `yaml:"name"`
	Description string          `yaml:"desc,omitempty"`
	Tables      []DatabaseTable `yaml:"tables,flow"`
	Services    []string        `yaml:"services_access,flow"`
}

Database is a group of DatabaseTables accessible by one or more services. Running services may access databases by employing the DAPR state store APIs via the SDK of the user's preferred programming language. See https://docs.dapr.io/developing-applications/sdks/ for further detail.

type DatabaseTable

type DatabaseTable struct {
	Name        string `yaml:"name"`
	Description string `yaml:"desc,omitempty"`
}

DatabaseTable is a representation of persistent state organized by a set of related key/value pairs.

type DeployOption

type DeployOption func(*deployOptions) *deployOptions

func DeployOptHttpClient

func DeployOptHttpClient(httpClient *http.Client) DeployOption

type ObjectStore

type ObjectStore struct {
	Name        string   `yaml:"name"`
	Description string   `yaml:"desc,omitempty"`
	Services    []string `yaml:"services_access,flow"`
}

ObjectStore is an object storage container accessible by one or more services. Running services may access object stores by employing the S3 APIs in the AWS SDK of the user's preferred programming language.

type Package

type Package struct {
	Proj        *Project
	Id          string
	Name        string
	TarballPath string
	Xsum        []byte
}

func NewPackage

func NewPackage(pkgName string, proj *Project, stdOut io.Writer,
	stdErr io.Writer, opts ...PkgOption) (*Package, error)

@todo add logic to avoid generating a new package when the underlying binaries haven't changed; currently this isn't happening due to the copied files in the tarball having different timestamps. Fixing this is non-trivial since golang's os.Stat() doesn't return st_atim and os.Chtimes() isn't nanosecond precision

func NewPackageFromExisting

func NewPackageFromExisting(proj *Project, pkgId string) (*Package, error)

func (*Package) AbsTarballPath

func (pkg *Package) AbsTarballPath() string

func (*Package) Deploy

func (pkg *Package) Deploy(opts ...DeployOption) error

func (*Package) DeployViaGoSwagger

func (pkg *Package) DeployViaGoSwagger(opts ...DeployOption) error

Deploy() implemented using a client generated with go-swagger:

https://github.com/go-swagger/go-swagger

func (*Package) DeployViaOpenApiGenerator

func (pkg *Package) DeployViaOpenApiGenerator(opts ...DeployOption) error

Deploy() implemented using a client generated with openapi-generator:

https://github.com/OpenAPITools/openapi-generator

func (*Package) DeployViaProtoJson

func (pkg *Package) DeployViaProtoJson(opts ...DeployOption) error

Deploy() implemented using protojson & http.Post()

func (*Package) String

func (pkg *Package) String() string

type PkgOption

type PkgOption func(*pkgOptions) *pkgOptions

func PkgOptUseHostOS

func PkgOptUseHostOS() PkgOption

PkgOptUseHostOS() instructs NewProjectFromPackage() to utilize tar&xz from the host operating system directly rather than the default behavior of utilizing them via the Bopmatic Build container. It is the caller's responsibility to ensure tar&xz are installed on the host OS when utilizing this option.

type Project

type Project struct {
	FormatVersion string      `yaml:"formatversion"`
	Desc          ProjectDesc `yaml:"project"`
}

func NewProject

func NewProject(projFile string, opts ...ProjectOption) (*Project, error)

NewProject instantiates a new Project instance from the specified project filename. It will parse the project file & derivative API definitions for each service defined in the project file and validate that it is well formed. Otherwise, an error is returned. Here is an example Bopmatic.yaml project file:

formatversion: "1.1" project:

name: "Foo"
desc: "Foo Project"
sitedir: "site"
services:
- name: "Greeter"
  desc: "Service for greeting customers"
  apidef: "pb/greeter.proto"
  port: 26001
  executable: "greeter_server"
  useraccess: "anon_public"
- name: "Orders"
  desc: "Service for taking customer orders"
  apidef: "pb/orders.proto"
  port: 26002
  executable: "orders_server"
  useraccess: "CustomerUserGroup"
databases:
- name: "Customers"
  desc: "Customer database"
  tables:
  - name: "ContactDetails"
    desc: "Customer names, shipping address, phone, etc."
  - name: "Orders"
    desc: "Customer orders"
  services_access: [ "Greeter" ]
object_stores:
- name: "UploadBucket"
  desc: "Bucket for uploading data"
  services_access: [ "Orders" ]
usergroups:
- name: "CustomerUserGroup"
  desc: "Customer user group"
  type: "public"

func NewProjectFromPackage

func NewProjectFromPackage(pkgFile string, projRoot string,
	opts ...PkgOption) (*Project, error)

NewProjectFromPackage instantiates a new Project instance from the specified package file

func (*Project) Build

func (proj *Project) Build(stdOut io.Writer, stdErr io.Writer) error

Compile the project

func (*Project) ExportToFile

func (proj *Project) ExportToFile(projFile string) error

ExportToFile export Project to a new Bopmatic.yaml file

func (*Project) HashString

func (proj *Project) HashString() string

String converts a Project into shorthand string suitable as a GUID

func (*Project) IsEqual

func (proj *Project) IsEqual(cmpProj *Project) bool

IsEqual compares project with cmpProj to determine whether they are equivalent

func (*Project) NewPackageCreate

func (proj *Project) NewPackageCreate(pkgName string, stdOut io.Writer,
	stdErr io.Writer, opts ...PkgOption) (*Package, error)

NewPackage collects all of the build & project artifacts required in order to submit to Bopmatic's ServiceRunner for deployment. Upon success a Package instance is returned.

func (*Project) NewPackageExisting

func (proj *Project) NewPackageExisting(pkgId string) (*Package, error)

func (*Project) RemoveStalePackages

func (proj *Project) RemoveStalePackages() error

RemoveStalePackages deletes any previously created project packages

func (*Project) String

func (proj *Project) String() string

String converts a Project into a human-friendly printable string

type ProjectDesc

type ProjectDesc struct {
	Name          string        `yaml:"name"`
	Description   string        `yaml:"desc,omitempty"`
	Services      []Service     `yaml:"services,omitempty,flow"`
	Databases     []Database    `yaml:"databases,omitempty,flow"`
	ObjectStores  []ObjectStore `yaml:"object_stores,omitempty,flow"`
	UserGroups    []UserGroup   `yaml:"usergroups,omitempty,flow"`
	SiteAssets    string        `yaml:"sitedir,omitempty"`
	RuntimeConfig string        `yaml:"runtime_config,omitempty"`
	BuildCmd      string        `yaml:"buildcmd"`
	// contains filtered or unexported fields
}

ProjectDesc see Project for a complete description

func (*ProjectDesc) GetRoot

func (desc *ProjectDesc) GetRoot() string

type ProjectOption

type ProjectOption func(*projectOptions) *projectOptions

func ProjectOptValidateSiteAssets

func ProjectOptValidateSiteAssets() ProjectOption

ProjectOptValidateSiteAssets()instructs NewProject() to validate the existence and content (e.g. whether index.html is present) of a project's specified sitedir. The default is false because projects may create sitedir at build time so it may not be present prior to a build

type Service

type Service struct {
	Name          string `yaml:"name"`
	Description   string `yaml:"desc,omitempty"`
	ApiDefinition string `yaml:"apidef"`
	ApiDefAssets  string `yaml:"apidef_assets,omitempty"`
	Port          uint64 `yaml:"port"`
	Executable    string `yaml:"executable"`
	ExecAssets    string `yaml:"executable_assets,omitempty"`
	// The user access refers to the name of user group which is allowed to
	// invoke a service's APIs. The user group should either also be defined
	// in the same Bopmatic.yaml or refer to one of the following two built-in
	// user accesses:
	//     1. anon_public - Access to the APIs is public and does not require
	//                      any authentication. e.g. a google search
	//     2. none        - No users are allowed to access the service directly.
	//                      e.g. an internal sales analytics service that is
	//                      only invoked by other services and not by end users
	//                      directly. This is the default.
	UserAccess string `yaml:"user_access,omitempty"`
	// contains filtered or unexported fields
}

func (*Service) GetRpcs

func (svc *Service) GetRpcs() []string

type UserGroup

type UserGroup struct {
	Name        string `yaml:"name"`
	Description string `yaml:"desc,omitempty"`

	// 2 usergroup types are currently defined:
	//
	// 1. public - membership to the group is available to the public. users
	//             can sign themselves up without any interaction from service
	//             administrators. e.g. a new customer can signup
	//             at will.
	// 2. private - membership to the group is controlled by service
	//             administrators. Users may not sign themselves up. e.g.
	//             a new employee has to be onboarded by HR.
	Type string `yaml:"type"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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