forked from daattali/beautiful-jekyll
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DataCatalogJs.html
198 lines (159 loc) · 7.92 KB
/
DataCatalogJs.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<!DOCTYPE html>
<html>
<head>
<title>Data Catalog - REST API Demo - Authenticate an Office 365 user with ADAL JS</title>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<style>body{font:normal normal normal 14px/1.5em "Century Gothic", sans-serif;}</style>
<!-- <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://secure.aadcdn.microsoftonline-p.com/lib/1.0.0/js/adal.js"></script>
<script type="text/javascript">
$(document).ready(function () {
"use strict";
// Assign variables
var variables = {
// Domain of Azure AD tenant
azureAD: "eggy.onmicrosoft.com",
// ClientId of Azure AD application principal, web, need to ensure users are granted app permissions and app has permissions to data catalog
clientId: "c98fd384-0c09-4471-93a5-02b51589820d",
randomName: Date.now().toFixed()
}
// Create config and get AuthenticationContext
window.config = {
tenant: variables.azureAD,
clientId: variables.clientId,
postLogoutRedirectUri: window.location.origin,
endpoints: {
graphApiUri: "https://graph.microsoft.com",
dataCatalogUri: "https://api.azuredatacatalog.com"
},
cacheLocation: "localStorage"
};
var authContext = new AuthenticationContext(config);
var isCallback = authContext.isCallback(window.location.hash + 'a');
authContext.handleWindowCallback();
if (isCallback && !authContext.getLoginError()) {
window.location = authContext._getItem(authContext.CONSTANTS.STORAGE.LOGIN_REQUEST);
}
var user = authContext.getCachedUser();
if (!user) {
authContext.login();
}
$("#UserName").html("Welcome " + user.userName);
$("#assetName").val(variables.randomName);
$("button").on("click", function () {
authContext.acquireToken(config.endpoints.dataCatalogUri, function (error, token) {
if (error || !token) {
console.log("ADAL error occurred: " + error);
return;
}
else {
//$("#UserName").html(user.userName);
// var dataCatalogUri = "https://api.azuredatacatalog.com/catalogs/DefaultCatalog/views/tables?api-version=2016-03-30";
//var body ='{{ "properties" : {{ "fromSourceSystem" : false, "name": "{0}", "dataSource": {{ "sourceType": "SQL Server", "objectType": "Table", }}, "dsl": {{ "protocol": "tds", "authentication": "windows", "address": {{ "server": "test.contoso.com", "database": "Northwind", "schema": "dbo", "object": "{0}" }} }}, "lastRegisteredBy": {{ "upn": "{1}" }}, }}, "annotations" : {{ "schema": {{ "properties" : {{ "fromSourceSystem" : false, "columns": [ {{ "name": "OrderID", "isNullable": false, "type": "int", "maxLength": 4, "precision": 10 }}, {{ "name": "CustomerID", "isNullable": true, "type": "nchar", "maxLength": 10, "precision": 0 }}, {{ "name": "OrderDate", "isNullable": true, "type": "datetime", "maxLength": 8, "precision": 23 }}, ], }} }}, "previews": [ {{ "properties": {{ "preview": [ {{ "OrderId": 1, "CustomerID": 11, "OrderDate": null }}, {{ "OrderId": 2, "CustomerID": 12, "OrderDate": "08/02/2017" }} ], "key": "SqlExtractor", "fromSourceSystem": true }} }} ], "tableDataProfiles": [ {{ "properties": {{ "dataModifiedTime": "2015 -12-31T00:32:22.4832805-08:00", "schemaModifiedTime": "2015 -12-31T00:32:22.4832805-08:00", "size": 9223372036854775807, "numberOfRows": 9223372036854775807, "key": "Test", "fromSourceSystem": true }} }} ], "columnsDataProfiles": [ {{ "properties": {{ "columns": [ {{ "columnName": "OrderId", "type": "int", "min": "1", "max": "1002", "stdev": 50, "avg": 201, "nullCount": 0, "distinctCount": 12121212 }} ], "key": "Test", "fromSourceSystem": true }} }} ], }} }}';
var dataCatalogUri = "https://api.aue.datacatalog.azure.com/catalogs/DefaultCatalog/views/tables?api-version=2016-03-30";
var body = '{ "roles": [ { "role": "Contributor", "members": [ { "objectId": "00000000-0000-0000-0000-000000000201" } ] } ], "properties": { "fromSourceSystem": true, "name": "{0}", "dataSource": { "sourceType": "SQL Server", "objectType": "Table" }, "dsl": { "protocol": "tds", "authentication": "windows", "address": { "server": "MyServer.contoso.com", "database": "NORTHWND", "schema": "dbo", "object": "Orders" } }, "lastRegisteredBy": { "upn": "[email protected]", "firstName": "User1FirstName", "lastName": "User1LastName" } }, "annotations": { "schema": { "roles": [ { "role": "Contributor", "members": [ { "objectId": "00000000-0000-0000-0000-000000000201" } ] } ], "properties": { "fromSourceSystem": true, "columns": [ { "name": "OrderID", "isNullable": false, "type": "int", "maxLength": 4, "precision": 10 }, { "name": "CustomerID", "isNullable": true, "type": "nchar", "maxLength": 10, "precision": 0 }, { "name": "EmployeeID", "isNullable": true, "type": "int", "maxLength": 4, "precision": 10 }, { "name": "OrderDate", "isNullable": true, "type": "datetime", "maxLength": 8, "precision": 23 } ] } } } }';
var newAssetName = variables.randomName;
if ($("#assetName").val()) {
newAssetName = $("#assetName").val();
}
body = body.replace('{0}', newAssetName)
body = body.replace('{1}', user.userName)
//NOTE: body text based on this page but example was invalid: https://docs.microsoft.com/en-us/rest/api/datacatalog/data-catalog-data-asset#register-or-update
console.log("about to send " + body);
$.ajax({
type: "POST",
//dataType: "jsonp",
url: dataCatalogUri,
data: body,
//data: body,
headers: {
"Authorization": "Bearer " + token,
"accept": "application/json",
"Content-Type": "application/json"
}
}).done(function (response) {
console.log(token);
console.log("Posted to data catalog.");
$("#message").html("Created Data Catalog Asset named " + newAssetName + " ");
//$("#search").attr("href", "https://aue-su1.azuredatacatalog.com/#/browse?searchTerms=" + newAssetName);
$("#search").attr("href", "https://aue-su1.azuredatacatalog.com/#/browse?searchTerms=timestamp%20%3E%20'1%2F23%2F2019'");
$("#resultsArea").fadeIn( 800 );
}).fail(function (error) {
console.log("Data catalog call failed.");
console.log(error);
});
console.log("Data catalog ended.");
}
});
});
});
</script>
<style>
body {
background: powderblue;
padding: 20px;
font-family: Helvetica;
}
#banner-message {
background: #fff;
border-radius: 4px;
padding: 20px;
font-size: 25px;
text-align: center;
transition: all 0.2s;
margin: 0 auto;
width: 300px;
}
a, button {
background: #0084ff;
border: none;
border-radius: 5px;
padding: 8px 14px;
font-size: 15px;
color: #fff;
margin-top: 5px;
}
a#search{
text-decoration: none;
display: inline-block;
}
input {
border-radius: 5px;
padding: 8px 14px;
font-size: 15px;
}
.alert-box {
padding: 15px;
margin-bottom: 20px;
border: 1px solid transparent;
border-radius: 4px;
}
.success {
color: #3c763d;
background-color: #dff0d8;
border-color: #d6e9c6;
display: none;
}
</style>
</head>
<body>
<div id="banner">
<img src='emotions-3459666_640.jpg' />
<h1>Data Catalog REST API example</h1>
<ul>
<ul id="UserName">
</ul>
<h2>create asset</h2>
<input type="text" id="assetName" />
<br/>
<button>Create Asset</button>
<p id="resultsArea" class="alert-box success" style="display:none;">
<span id="message"></span>
<br/>
<a id="search" href='#' target="_blank">View in Azure Data Catalog</a>
</p>
<!-- If your admin hasn't done it then you may need to <a href='https://login.microsoftonline.com/eggy.onmicrosoft.com/oauth2/authorize?client_id=2114ef90-f5c0-4cde-83db-aeaf2912229b&response_type=code&redirect_uri=http://127.0.0.1:8887/DataCatalogJs.html&nonce=1234&resource=https://graph.windows.net&prompt=admin_consent'>authorise</a> -->
</div>
</body>
</html>