Skip to content

Commit

Permalink
Merge pull request #170 from appuio/feat/odoo16-storage
Browse files Browse the repository at this point in the history
Implement storage backend for odoo16
  • Loading branch information
HappyTetrahedron authored Nov 29, 2023
2 parents cf383b5 + 3b79f54 commit 0573991
Show file tree
Hide file tree
Showing 7 changed files with 1,029 additions and 5 deletions.
34 changes: 32 additions & 2 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/appuio/control-api/apiserver/authwrapper"
billingStore "github.com/appuio/control-api/apiserver/billing"
"github.com/appuio/control-api/apiserver/billing/odoostorage"
"github.com/appuio/control-api/apiserver/billing/odoostorage/odoo/odoo16"
"github.com/appuio/control-api/apiserver/billing/odoostorage/odoo/odoo8"
"github.com/appuio/control-api/apiserver/billing/odoostorage/odoo/odoo8/countries"
orgStore "github.com/appuio/control-api/apiserver/organization"
Expand Down Expand Up @@ -55,16 +56,25 @@ func APICommand() *cobra.Command {
cmd.Flags().StringVar(&usernamePrefix, "username-prefix", "", "Prefix prepended to username claims. Usually the same as \"--oidc-username-prefix\" of the Kubernetes API server")
cmd.Flags().BoolVar(&allowEmptyBillingEntity, "allow-empty-billing-entity", true, "Allow empty billing entity references")

cmd.Flags().StringVar(&ob.billingEntityStorage, "billing-entity-storage", "fake", "Storage backend for billing entities. Supported values: fake, odoo8")
cmd.Flags().StringVar(&ob.billingEntityStorage, "billing-entity-storage", "fake", "Storage backend for billing entities. Supported values: fake, odoo8, odoo16")

cmd.Flags().BoolVar(&ob.billingEntityFakeMetadataSupport, "billing-entity-fake-metadata-support", false, "Enable metadata support for the fake storage backend")

cmd.Flags().StringVar(&ob.odoo8URL, "billing-entity-odoo8-url", "http://localhost:8069", "URL of the Odoo instance to use for billing entities")
cmd.Flags().BoolVar(&ob.odoo8DebugTransport, "billing-entity-odoo8-debug-transport", false, "Enable debug logging for the Odoo transport")
cmd.Flags().StringVar(&ob.odoo8CountryListPath, "billing-entity-odoo8-country-list", "countries.yaml", "Path to the country list file in the format of [{name: \"Germany\", code: \"DE\", id: 81},...]")

cmd.Flags().StringVar(&ob.odoo8AccountingContactDisplayName, "billing-entity-odoo8-accounting-contact-display-name", "Accounting", "Display name of the accounting contact")
cmd.Flags().StringVar(&ob.odoo8LanguagePreference, "billing-entity-odoo8-language-preference", "en_US", "Language preference of the Odoo record")
cmd.Flags().IntVar(&ob.odoo8PaymentTermID, "billing-entity-odoo8-payment-term-id", 2, "Payment term ID of the Odoo record")

cmd.Flags().StringVar(&ob.odoo16URL, "billing-entity-odoo16-url", "http://localhost:8069", "URL of the Odoo instance to use for billing entities")
cmd.Flags().StringVar(&ob.odoo16Db, "billing-entity-odoo16-db", "odooDB", "Database of the Odoo instance to use for billing entities")
cmd.Flags().StringVar(&ob.odoo16Account, "billing-entity-odoo16-account", "Admin", "Odoo Account name to use for billing entities")
cmd.Flags().StringVar(&ob.odoo16Password, "billing-entity-odoo16-password", "superSecret1238", "Odoo Account password to use for billing entities")
cmd.Flags().StringVar(&ob.odoo16CountryListPath, "billing-entity-odoo16-country-list", "countries.yaml", "Path to the country list file in the format of [{name: \"Germany\", code: \"DE\", id: 81},...]")
cmd.Flags().StringVar(&ob.odoo16LanguagePreference, "billing-entity-odoo16-language-preference", "en_US", "Language preference of the Odoo record")
cmd.Flags().IntVar(&ob.odoo16PaymentTermID, "billing-entity-odoo16-payment-term-id", 2, "Payment term ID of the Odoo record")

cmd.Flags().StringVar(&ib.backingNS, "invitation-storage-backing-ns", "default", "Namespace to store invitation secrets in")

rf := cmd.Run
Expand All @@ -90,6 +100,10 @@ type odooStorageBuilder struct {
odoo8AccountingContactDisplayName, odoo8LanguagePreference string
odoo8PaymentTermID int
billingEntityFakeMetadataSupport, odoo8DebugTransport bool
odoo16LanguagePreference string
odoo16URL, odoo16CountryListPath string
odoo16Db, odoo16Account, odoo16Password string
odoo16PaymentTermID int
}

func (o *odooStorageBuilder) Build(s *runtime.Scheme, g genericregistry.RESTOptionsGetter) (rest.Storage, error) {
Expand All @@ -107,6 +121,22 @@ func (o *odooStorageBuilder) Build(s *runtime.Scheme, g genericregistry.RESTOpti
PaymentTermID: o.odoo8PaymentTermID,
CountryIDs: countryIDs,
}).(authwrapper.StorageScoper))(s, g)
case "odoo16":
countryIDs, err := countries.LoadCountryIDs(o.odoo16CountryListPath)
if err != nil {
return nil, err
}
return billingStore.New(odoostorage.NewOdoo16Storage(
odoo16.OdooCredentials{
URL: o.odoo16URL,
Admin: o.odoo16Account,
Password: o.odoo16Password,
Database: o.odoo16Db,
}, odoo16.Config{
LanguagePreference: o.odoo16LanguagePreference,
PaymentTermID: o.odoo16PaymentTermID,
CountryIDs: countryIDs,
}).(authwrapper.StorageScoper))(s, g)
default:
return nil, fmt.Errorf("unknown billing entity storage: %s", o.billingEntityStorage)
}
Expand Down
Loading

0 comments on commit 0573991

Please sign in to comment.