public async Task <EnvironmentSeedResponse> Seed(EnvironmentSeed seed)
        {
            OcEnv requestedEnv = validateEnvironment(seed.OrderCloudSettings.Environment);

            if (requestedEnv.environmentName == OrderCloudEnvironments.Production.environmentName && seed.SellerOrgID == null)
            {
                throw new Exception("Cannot create a production environment via the environment seed endpoint. Please contact an OrderCloud Developer to create a production org.");
            }

            // lets us handle requests to multiple api environments
            _oc = new OrderCloudClient(new OrderCloudClientConfig
            {
                ApiUrl  = requestedEnv.apiUrl,
                AuthUrl = requestedEnv.apiUrl
            });

            var portalUserToken = await _portal.Login(seed.PortalUsername, seed.PortalPassword);

            var sellerOrg = await GetOrCreateOrg(portalUserToken, requestedEnv.environmentName, seed.SellerOrgName, seed.SellerOrgID);

            var orgToken = await _portal.GetOrgToken(sellerOrg.Id, portalUserToken);

            await CreateDefaultSellerUsers(seed, orgToken);

            await CreateIncrementors(orgToken);         // must be before CreateBuyers
            await CreateMessageSenders(seed, orgToken); // must be before CreateBuyers and CreateSuppliers

            await CreateSecurityProfiles(orgToken);
            await CreateBuyers(seed, orgToken);
            await CreateConfigureAnonBuyer(seed, orgToken);

            await CreateApiClients(orgToken);
            await AssignSecurityProfiles(seed, orgToken);

            var apiClients = await GetApiClients(orgToken);

            await CreateXPIndices(orgToken);
            await CreateAndAssignIntegrationEvents(new string[] { apiClients.BuyerUiApiClient.ID }, apiClients.BuyerLocalUiApiClient.ID, orgToken, seed);
            await CreateSuppliers(seed, orgToken);

            // populate default english translations into blob container name: settings.BlobSettings.ContainerNameTranslations or "ngx-translate" if setting is not defined
            // provide other language files to support multiple languages

            var englishTranslationsPath = Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, "Assets", "english-translations.json"));

            if (seed?.BlobSettings?.ConnectionString != null && seed?.BlobSettings?.ContainerNameTranslations != null)
            {
                var translationsConfig = new BlobServiceConfig()
                {
                    ConnectionString = seed.BlobSettings.ConnectionString,
                    Container        = seed.BlobSettings.ContainerNameTranslations,
                    AccessType       = BlobContainerPublicAccessType.Container
                };
                var translationsBlob = new OrderCloudIntegrationsBlobService(translationsConfig);
                await translationsBlob.Save("i18n/en.json", File.ReadAllText(englishTranslationsPath));
            }

            return(new EnvironmentSeedResponse
            {
                Comments = "Success! Your environment is now seeded. The following clientIDs & secrets should be used to finalize the configuration of your application. The initial admin username and password can be used to sign into your admin application",
                OrganizationName = sellerOrg.Name,
                OrganizationID = sellerOrg.Id,
                OrderCloudEnvironment = requestedEnv.environmentName,
                ApiClients = new Dictionary <string, dynamic>
                {
                    ["Middleware"] = new
                    {
                        ClientID = apiClients.MiddlewareApiClient.ID,
                        ClientSecret = apiClients.MiddlewareApiClient.ClientSecret
                    },
                    ["Seller"] = new
                    {
                        ClientID = apiClients.AdminUiApiClient.ID
                    },
                    ["Buyer"] = new
                    {
                        ClientID = apiClients.BuyerUiApiClient.ID
                    }
                }
            });
        }
示例#2
0
        /// <summary>
        /// This seeding function can be used to initially seed an marketplace
        /// it is also meant to be safe to call after an marketplace has been seeded (by including seed.MarketplaceID)
        /// If a method starts with CreateOrUpdate it will update the resource every time its called based on what has been defined in SeedConstants.cs
        /// If a method starts with CreateOnlyOnce it will only create the resource once and then ignore thereafter
        /// The CreateOnlyOnce resources are likely to change after initial creation so we ignore to avoid overwriting desired changes that happen outside of seeding
        /// </summary>
        public async Task <EnvironmentSeedResponse> Seed(EnvironmentSeed seed)
        {
            OcEnv requestedEnv = validateEnvironment(seed.OrderCloudSettings.Environment);

            if (requestedEnv.environmentName == OrderCloudEnvironments.Production.environmentName && seed.MarketplaceID == null)
            {
                throw new Exception("Cannot create a production environment via the environment seed endpoint. Please contact an OrderCloud Developer to create a production marketplace.");
            }

            // lets us handle requests to multiple api environments
            _oc = new OrderCloudClient(new OrderCloudClientConfig
            {
                ApiUrl  = requestedEnv.apiUrl,
                AuthUrl = requestedEnv.apiUrl
            });

            var portalUserToken = await _portal.Login(seed.PortalUsername, seed.PortalPassword);

            var marketplace = await GetOrCreateMarketplace(portalUserToken, requestedEnv.environmentName, seed.MarketplaceName, seed.MarketplaceID);

            var marketplaceToken = await _portal.GetMarketplaceToken(marketplace.Id, portalUserToken);

            await CreateOrUpdateDefaultSellerUser(seed, marketplaceToken);

            await CreateOnlyOnceIncrementors(marketplaceToken);                       // must be before CreateBuyers
            await CreateOrUpdateMessageSendersAndAssignments(seed, marketplaceToken); // must be before CreateBuyers and CreateSuppliers

            await CreateOrUpdateSecurityProfiles(marketplaceToken);
            await CreateOnlyOnceBuyers(seed, marketplaceToken);

            await CreateOnlyOnceApiClients(seed, marketplaceToken);
            await CreateOrUpdateSecurityProfileAssignments(seed, marketplaceToken);

            await CreateOrUpdateXPIndices(marketplaceToken);
            await CreateOrUpdateAndAssignIntegrationEvents(marketplaceToken, seed);
            await CreateOrUpdateSuppliers(seed, marketplaceToken);

            await CreateOrUpdateProductFacets(marketplaceToken);

            if (seed?.StorageAccountSettings?.ConnectionString != null && seed?.StorageAccountSettings?.ContainerNameTranslations != null)
            {
                await UpdateTranslations(seed.StorageAccountSettings.ConnectionString, seed.StorageAccountSettings.ContainerNameTranslations);
            }

            var apiClients = await GetApiClients(marketplaceToken);

            return(new EnvironmentSeedResponse
            {
                Comments = "Success! Your environment is now seeded. The following clientIDs & secrets should be used to finalize the configuration of your application. The initial admin username and password can be used to sign into your admin application",
                MarketplaceName = marketplace.Name,
                MarketplaceID = marketplace.Id,
                OrderCloudEnvironment = requestedEnv.environmentName,
                ApiClients = new Dictionary <string, dynamic>
                {
                    ["Middleware"] = new
                    {
                        ClientID = apiClients.MiddlewareApiClient.ID,
                        ClientSecret = apiClients.MiddlewareApiClient.ClientSecret
                    },
                    ["Seller"] = new
                    {
                        ClientID = apiClients.AdminUiApiClient.ID
                    },
                    ["Buyer"] = new
                    {
                        ClientID = apiClients.BuyerUiApiClient.ID
                    }
                }
            });
        }