Skip to content
This repository has been archived by the owner on Jul 14, 2022. It is now read-only.

implemented "show trace view" feature to open the trace view in browser #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Default.sublime-commands
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
{
"caption":"Apigee: Add Flow to Proxy",
"command":"add_flow"
},
{
"caption":"Apigee: Show Trace (opens in browser)",
"command":"show_trace"
}

]
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"username":"USERNAME",
"password":"PASSWORD (OPTIONAL)",
"uri":"MGMT SERVER URL(OPTIONAL)",
"trace_uri":"https://enterprise.apigee.com/platform/#/:org/apis/:proxy/1?section=trace",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couple of things here

  1. Trace URL changes with proxy revision. trace_uri has to account for that
  2. If trace_uri is not provided or left empty in deploy_vars.json, sweetlime should assume that it is case of cloud installation and switch to the enterprise trace url. Hence it is not required to show the trace_uri in deploy_vars.json

"trace_uri":"TRACE URL(OPTIONAL)".

If the user provides a url then we use that instead of the enterprise one.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey girish.

  1. oh my, i totally oversaw the "/1" in the url! Thanks for pointing that out!
    What would be the preferable way to determine the revision? Ask the user for it or use the management api (http://apigee.com/docs/api/get-api-proxy) to fetch the list of revisions and let the user choose one?
    The latter would give a chance to quit with an error message before launching the browser if the proxy hasn't been deployed yet.

  2. Where would you put the default url? Hard coding it in ShowTrace.py sounds dirty to me. Is SweetLime.sublime-settings a good place for that? That would enable a team of OPDK in-house developers to use Sweetlime as-is and share the settings among team members so they only have to configure the url once and not in every deploy.vars file...

  • Tim.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Tim,

On point 2), using .sublime-settings is the best solution. Please go ahead with that.

On point 1), If at all possible I would avoid hitting the mgmt api again. For deploying the proxy I rely on apigeetool deployproxy source: https://github.com/apigee/api-platform-tools/blob/master/ApigeePlatformTools/deployproxy.py. Upon a successful deploy, the deployproxy.py script throws up, along with other stuff like proxy-name, env, etc, also the revision number. However it is a part of a success message that goes something like this: Proxy: "myAwesomeProxy" Revision 1.
screen shot 2014-07-17 at 12 09 27 am

While a dirty way would be to fallback on string manipulation to fetch the revision, the cleaner way would be to make changes to deployproxy.py such that we get the revision number explicitly.

Girish

If all this doesnt work for whatever reason then we just fall back on the mgmt api call.

"displayname":"DISPLAY NAME (OPTIONAL)",
"basepath":"BASEPATH (OPTIONAL)"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"username":"USERNAME",
"password":"PASSWORD (OPTIONAL)",
"uri":"MGMT SERVER URL(OPTIONAL)",
"trace_uri":"https://enterprise.apigee.com/platform/#/:org/apis/:proxy/1?section=trace",
"displayname":"DISPLAY NAME (OPTIONAL)",
"basepath":"BASEPATH (OPTIONAL)"
}
}
3 changes: 2 additions & 1 deletion ProjectTemplates/Apigee Proxy/deploy_vars.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"username":"USERNAME",
"password":"PASSWORD (OPTIONAL)",
"uri":"MGMT SERVER URL(OPTIONAL)",
"trace_uri":"https://enterprise.apigee.com/platform/#/:org/apis/:proxy/1?section=trace",
"displayname":"DISPLAY NAME (OPTIONAL)",
"basepath":"BASEPATH (OPTIONAL)"
}
}
10 changes: 8 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ OSX
> `git clone [email protected]:apigee/Sweetlime.git ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/ApigeeSweetLime'

Windows
> coming soon (testing underway)
> `git clone [email protected]:apigee/Sweetlime.git %APPDATA%\Sublime Text 3\Packages\ApigeeSweetLime'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

works in Windows too? thats great!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, at least with windows 7 and the latest sublime text 3 version. Unfortunately I have no chance to test this on windows 8. But I think it's a good idea to give the installation advice in the readme, so anyone with windows 8 has any clue how to test it and open an issue if it doesn't work.


##Using SweetLime

Expand All @@ -41,6 +41,8 @@ Adds a policy step - existing and new.
Creates a new policy from a list of policy templates.
###Apigee: Fetch Policy Templates
Fetches a policy template to a file.
###Apigee: Show Trace (opens in browser)
Opens the trace view of a deployed proxy in a new browser tab

[Video: Developing proxies for Apigee Edge](https://www.youtube.com/watch?v=TMVIEFuQr7k)

Expand All @@ -62,6 +64,7 @@ Proxies created with SweetLime include a JSON file called `deploy_vars.json` wit
"username":"USERNAME",
"password":"PASSWORD (OPTIONAL)",
"uri":"MGMT SERVER URL(OPTIONAL)",
"trace_uri":""https://enterprise.apigee.com/platform/#/:org/apis/:proxy/1?section=trace"",
"displayname":"DISPLAY NAME (OPTIONAL)",
"basepath":"BASEPATH (OPTIONAL)"
}
Expand All @@ -84,6 +87,9 @@ keyring.set_password("orgname", "username", "password")
###uri - optional
If your deploy destination is Apigee cloud then leave this empty, else provide the url to the management server on your OPDK installation

###trace_uri - optional
If your deploy destination is Apigee cloud then leave as-is, else provide the url to the management server on your OPDK installation. Use ":org" and ":proxy" as placeholders for organization and proxy name (e.g. "https://apigee.mycompany.com/platform/#/:org/apis/:proxy/1?section=trace")

###displayname - optional
If displayname is not provided, it will be defaulted to the proxy name

Expand All @@ -110,4 +116,4 @@ The above copyright notice and this permission notice shall be included in all c
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


[1]: https://github.com/apigee/api-platform-tools
[1]: https://github.com/apigee/api-platform-tools
37 changes: 37 additions & 0 deletions ShowTrace.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import os, time, re
import sublime
import sublime_plugin
import glob
import json
import webbrowser
from pprint import pprint

current_path = None

class ShowTraceCommand(sublime_plugin.WindowCommand):


def run(self):

if not self.find_root():
return

proxy = os.path.basename(self.root)
json_data = open(self.root + '/deploy_vars.json')
data = json.load(json_data)
json_data.close()

new = 2 # open in a new tab, if possible
url = data['trace_uri'].replace(':org',data['org']).replace(':proxy', proxy)

webbrowser.open(url,new=new)

def find_root(self):
folders = self.window.folders()
if len(folders) == 0:
sublime.error_message('Could not find project root')
return False

self.root = folders[0]
self.rel_path_start = len(self.root) + 1
return True