Skip to content
This repository has been archived by the owner on Feb 28, 2020. It is now read-only.

Commit

Permalink
feat: added pipenv
Browse files Browse the repository at this point in the history
  • Loading branch information
Audrey committed Nov 2, 2017
2 parents 85a824c + ba829d3 commit e16db08
Show file tree
Hide file tree
Showing 104 changed files with 1,128 additions and 260 deletions.
2 changes: 1 addition & 1 deletion generators/app/fallback_bluemix.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ module.exports = JSON.stringify({
"postgresql": {
"uri": "postgres://admin:password@bluemix.net:20058/compose"
},
"alertnotification": {
"alertNotification": {
"url": "https://bluemix.net",
"name": "alertnotification",
"password": "alertnotification-password"
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ibmcloudenv~=0.0
ibmcloudenv
4 changes: 2 additions & 2 deletions generators/language-python-flask/templates/services_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
# GENERATE IMPORT HERE

def initServices(app):
# GENERATE HERE
return
# GENERATE HERE
return
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"auth": "appid",
"conversation": "watson_conversation",
"redis": "redis",
"alertnotification": "alert_notification",
"alertNotification": "alert_notification",
"push": "push",
"Auto-Scaling": "autoscaling",
"mongodb": "mongodb",
Expand Down
26 changes: 22 additions & 4 deletions generators/language-swift-kitura/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const bluemixLabelMappings = require('./bluemix-label-mappings.json');
const PATH_MAPPINGS_FILE = "./config/mappings.json";
const PATH_LOCALDEV_CONFIG_FILE = "./config/localdev-config.json";
const PATH_GIT_IGNORE = "./.gitignore";
const FILE_SEARCH_PATH_PREFIX = "file:/config/localdev-config.json:"
const FILE_SEARCH_PATH_PREFIX = "file:/config/localdev-config.json:";

module.exports = class extends Generator {
// Expecting:
Expand All @@ -34,7 +34,6 @@ module.exports = class extends Generator {
this.context.addLocalDevConfig = this._addLocalDevConfig.bind(this);
this.context.addReadMe = this._addReadMe.bind(this);
this.context.addInstrumentation = this._addInstrumentation.bind(this);

// Security Services
this.composeWith(require.resolve('../service-appid'), {context: this.context});

Expand All @@ -44,7 +43,7 @@ module.exports = class extends Generator {
this.composeWith(require.resolve('../service-redis'), {context: this.context});
this.composeWith(require.resolve('../service-postgre'), {context: this.context});
this.composeWith(require.resolve('../service-mongodb'), {context: this.context});

// Watson Services
this.composeWith(require.resolve('../service-watson-conversation'), {context: this.context});

Expand Down Expand Up @@ -108,11 +107,30 @@ module.exports = class extends Generator {
targetFilePath,
{ servLookupKey: bluemixLabelMappings[options.servLabel], context: this.context }
);
let metaFile = options.sourceFilePath.substring(0, options.sourceFilePath.lastIndexOf("/")) + '/meta.json';
let metaData = this.fs.readJSON(metaFile);
// We expect the source file to define a function as an entry point for initialization
// The function should be available in the module scope and have a name of the form:
// 'initializeMyService()'. For example, if the targetFileName is 'service-appid.swift'
// then the function will be 'initializeServiceAppid()'
this.context.injectIntoApplication({ service: `try initialize${targetName}()` });
// this.context.injectIntoApplication({ service: `try initialize${targetName}()` });
this.context.injectIntoApplication({ service_import: `import ${metaData.import}` });
this.context.injectIntoApplication({ service_variable: `public let ${metaData.variableName}: ${metaData.type}` });
this.context.injectIntoApplication({ service: `${metaData.variableName} = try initialize${targetName}(cloudEnv: cloudEnv)` });
// Injecting modules to Package.swift
if(this.context.injectModules){
if(metaData.variableName === 'appidService'){
metaData.import = 'BluemixAppID';
}else if(metaData.variableName === 'autoScalingService'){
metaData.import = '';
}else if(metaData.variableName === 'watsonConversationService'){
metaData.import = 'WatsonDeveloperCloud';
}
if(metaData.import !== ''){
metaData.import = "\"" + metaData.import + "\"";
this.context.injectModules(metaData.import);
}
}
} else {
throw new Error('Standalone execution of this generator is not supported for Swift');
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
.Package(url: "https://github.com/IBM-Swift/CloudEnvironment.git", majorVersion: 3),
.package(url: "https://github.com/IBM-Swift/CloudEnvironment.git", from: "3.0.0"),
39 changes: 33 additions & 6 deletions generators/lib/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,45 @@ module.exports = {
let context = args.context;
let destinationPath = args.destinationPath;

let hasServices = context.deploymentServicesEnv && context.deploymentServicesEnv.length > 0;
if (!hasServices) {
logger.info('No services to add to deployment.yaml');
return resolve();
}

// this deployment.yaml file should've been generated in the generator-ibm-cloud-enablement generator
// for deploy to Kubernetes using Helm chart
let deploymentFilePath = `${destinationPath}/chart/${context.sanitizedAppName}/templates/deployment.yaml`;
let chartFolderPath = `${destinationPath}/chart`;
if (!fs.existsSync(chartFolderPath)) {
logger.info('/chart folder does not exist');
return resolve();
}

let deploymentFilePath = `${chartFolderPath}/${context.sanitizedAppName}/templates/deployment.yaml`;
logger.info(`deployment.yaml path: ${deploymentFilePath}`);

let deploymentFileExists = fs.existsSync(deploymentFilePath);
if (!deploymentFileExists) { return resolve(); }
logger.info("deployment.yaml exists, setting service(s) env");
if (!deploymentFileExists) {
logger.info(`deployment.yaml does not exist at ${deploymentFilePath}, checking /chart directory`);
// chart could've been created with different name than expected
let chartFolders = fs.readdirSync(`${chartFolderPath}`);
// there should only be one folder under /chart, but just in case
for (let i = 0; i < chartFolders.length; i++) {
deploymentFilePath = `${chartFolderPath}/${chartFolders[i]}/templates/deployment.yaml`;
deploymentFileExists = fs.existsSync(deploymentFilePath);
if (deploymentFileExists) {
logger.info(`found deployment.yaml file at ${deploymentFilePath}`);
break;
}
}
}

let hasServices = context.deploymentServicesEnv && context.deploymentServicesEnv.length > 0;
if (!hasServices) { return resolve(); }
logger.info(`has ${context.deploymentServicesEnv.length} services, adding to deployment.yaml env`);
if (!deploymentFileExists) {
logger.error('deployment.yaml not found, cannot add services to env');
return resolve();
}

logger.info(`deployment.yaml exists, adding ${context.deploymentServicesEnv.length} to env` );

let readStream = fs.createReadStream(deploymentFilePath);
let promiseIsRejected = false;
Expand Down
2 changes: 1 addition & 1 deletion generators/service-alert-notification/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'
const BaseGenerator = require('../lib/generatorbase');
const SCAFFOLDER_PROJECT_PROPERTY_NAME = "alertnotification";
const SCAFFOLDER_PROJECT_PROPERTY_NAME = "alertNotification";
const SERVICE_NAME = "service-alert-notification";
const localDevConfig = ['url', 'name', 'password'];

Expand Down
68 changes: 68 additions & 0 deletions generators/service-alert-notification/templates/python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Alert Notification

IBM Alert Notification instantly delivers notifications of problem occurrences in your IT operations environment using automated communication methods such as email, Short Message Service (SMS), voice and mobile messaging. You can use custom groups to send alerts for a problem or class of problem. Groups can be created based on administrative roles, application names, department names or other criteria. Custom filters can be created for alerting different users based on incident type and severity.

## Credentials

### LocalDevConfig

This is where your local configuration is stored for Alert Notification.
```
{
"alert_notification_url": "{{url}}",
"alert_notification_name": "{{name}}",
"alert_notification_password": "{{password}}"
}
```

## Usage
[Alert Notification is accessed through a RESTful API](https://ibmnotifybm.mybluemix.net/docs/alerts/v1/). We provide a simple class for interacting with the three endpoints of the service:

```python
class Alert:
def __init__(self, url, user, password):
self.url = url
self.user = user
self.password = password
self.auth = (user, password)

def sendAlert(self, payload):
res = requests.post(self.url, auth=self.auth, json=payload)
response = res.json()
return response

def getAlert(self, id):
res = requests.get(self.url + '/' + str(id), auth=self.auth)
response = res.json()
return response

def deleteAlert(self, id):
res = requests.delete(self.url + '/' + str(id), auth=self.auth)
return res
```

The `service_manager` returns an initialized instance of this object populated with the provided credentials. [Refer to the complete API documentation](https://ibmnotifybm.mybluemix.net/docs/alerts/v1/) for full details on what can be provided in the payload of `sendAlert`:

```python
from flask import Flask
import requests

app = Flask(__name__, template_folder="../public", static_folder="../public", static_url_path='')

from server.services import *

initServices(app) # Initialize Services

alert = service_manager.get('alert-notification')

alertMessage = {
'What': 'Alert Message',
'Where': 'myserver.mycompany.com',
'Severity': 'Critical'
}

res = alert.sendAlert(alertMessage)
if res and 'ShortId' in res:
messageID = res['ShortId']
alertInfo = alert.getAlert(messageID)
```
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
from ibm_cloud_env import IBMCloudEnv
from ibmcloudenv import IBMCloudEnv
import requests

config = {
'url' : IBMCloudEnv.getString('alert_notification_url') if True else 'https://ibmnotifybm.mybluemix.net/api/alerts/v1',
'user': IBMCloudEnv.getString('alert_notification_name') if True else '',
'password': IBMCloudEnv.getString('alert_notification_password') if True else ''
}
class Alert:
def __init__(self, url, user, password):
self.url = url
self.user = user
self.password = password
self.auth = (user, password)

def getService(app):
return 'alert-notification', config
def sendAlert(self, payload):
res = requests.post(self.url, auth=self.auth, json=payload)
response = res.json()
return response

def getAlert(self, alertID):
res = requests.get(self.url + '/' + str(alertID), auth=self.auth)
response = res.json()
return response

def deleteAlert(self, alertID):
res = requests.delete(self.url + '/' + str(alertID), auth=self.auth)
return res

def getService(app):
url = IBMCloudEnv.getString('alert_notification_url')
user = IBMCloudEnv.getString('alert_notification_name')
password = IBMCloudEnv.getString('alert_notification_password')
return 'alert-notification', Alert(url, user, password)
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
requests

requests

Original file line number Diff line number Diff line change
@@ -1 +1 @@
.Package(url: "https://github.com/IBM-Swift/alert-notification-sdk.git", majorVersion: 1),
.package(url: "https://github.com/IBM-Swift/alert-notification-sdk.git", from: "1.0.0"),
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import LoggerAPI
import CloudEnvironment
import AlertNotifications

var serviceCredentials: ServiceCredentials!

func initializeServiceAlertNotification() throws {
func initializeServiceAlertNotification(cloudEnv: CloudEnv) throws -> ServiceCredentials {
guard let alertNotificationCredentials = cloudEnv.getAlertNotificationCredentials(name: "{{servLookupKey}}") else {
throw InitializationError("Could not load credentials for Alert Notifications.")
}
serviceCredentials = ServiceCredentials(
let serviceCredentials = ServiceCredentials(
url: alertNotificationCredentials.url,
name: alertNotificationCredentials.name,
password: alertNotificationCredentials.password
)
Log.info("Found and loaded credentials for Alert Notifications.")
return serviceCredentials
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"import":"AlertNotifications",
"variableName":"alertNotificationService",
"type":"ServiceCredentials",
"initParams":"cloudEnv: cloudEnv"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ibm_cloud_env import IBMCloudEnv
from ibmcloudenv import IBMCloudEnv

# Apache Spark Python SDK is not available yet
# Docs - https://www.ng.bluemix.net/docs/services/AnalyticsforApacheSpark
Expand Down
4 changes: 2 additions & 2 deletions generators/service-appid/templates/node/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# AppID


App ID is an authentication and profiles service that makes it easy for developers to add authentication to their mobile and web apps, and secure access to cloud native apps and services on Bluemix. It also helps manage end-user data that developers can use to build personalized app experiences.
App ID is an authentication and profiles service that makes it easy for developers to add authentication to their mobile and web apps, and secure access to cloud native apps and services on IBM Cloud. It also helps manage end-user data that developers can use to build personalized app experiences.
## Credentials

### LocalDevConfig
Expand Down Expand Up @@ -130,4 +130,4 @@ This is where your local configuration is stored for AppID.

## Documentation

Other related documentation can be found [here](https://www.npmjs.com/package/bluemix-appid)
Other related documentation can be found [here](https://www.npmjs.com/package/bluemix-appid)
Loading

0 comments on commit e16db08

Please sign in to comment.