-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathstore.py
More file actions
80 lines (65 loc) · 2.24 KB
/
store.py
File metadata and controls
80 lines (65 loc) · 2.24 KB
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
# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
#
# Copyright 2021 Canonical Ltd
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import getpass
import logging
import json
import os
import sys
import pathlib
from typing import Optional, TextIO
from urllib.parse import urljoin, urlparse
import requests
from simplejson.scanner import JSONDecodeError
import http_clients
def main():
authClient = http_clients.UbuntuOneAuthClient()
# get macaroon for account
url = "https://dashboard.snapcraft.io/dev/api/acl/"
data = {"permissions":["package_access"]}
# getting macaroon can only be anonymous, so no auth client
response = requests.request(
"POST",
url,
data=json.dumps(data),
headers={"Content-Type": "application/json", "Accept": "application/json"},
)
if not response.ok:
print('Error getting macaroon')
print(response.text)
sys.exit(1)
_macaroon = response.json()["macaroon"]
_email = input("Ubuntu SSO email address: ")
_password = getpass.getpass("password: ")
_otp = input("two factor: ")
authClient.login(_email, _password, _macaroon, _otp)
# get account info
url = "https://dashboard.snapcraft.io/dev/api/account"
headers = str
response = authClient.request(
"GET",
url,
headers={"Content-Type": "application/json", "Accept": "application/json", "Authorization": authClient.auth},
)
#print("status code", response.status_code)
if not response.ok:
print('Error getting account info')
print(response.text)
sys.exit(1)
f = open("out.json", "w")
f.write(json.dumps(response.json(), indent=2))
f.close()
if __name__ == "__main__":
main()