Beispiel #1
0
 def __call__(self, options):
     # Try and obtain credentials interactively if they're not given, or
     # read them from stdin if they're specified as "-".
     credentials = obtain_credentials(options.url, options.credentials)
     # Check for bogus credentials. Do this early so that the user is not
     # surprised when next invoking the MAAS CLI.
     if credentials is not None:
         try:
             valid_apikey = check_valid_apikey(
                 options.url, credentials, options.insecure)
         except UnexpectedResponse as e:
             raise SystemExit("%s" % e)
         else:
             if not valid_apikey:
                 raise SystemExit("The MAAS server rejected your API key.")
     # Get description of remote API.
     description = fetch_api_description(options.url, options.insecure)
     # Save the config.
     profile_name = options.profile_name
     with ProfileConfig.open() as config:
         config[profile_name] = {
             "credentials": credentials,
             "description": description,
             "name": profile_name,
             "url": options.url,
             }
         profile = config[profile_name]
     self.print_whats_next(profile)
Beispiel #2
0
 def __call__(self, options):
     with ProfileConfig.open() as config:
         for profile_name in config:
             profile = config[profile_name]
             url = profile["url"]
             profile["description"] = fetch_api_description(url)
             config[profile_name] = profile
Beispiel #3
0
 def __call__(self, options):
     with ProfileConfig.open() as config:
         for profile_name in config:
             profile = config[profile_name]
             url = profile["url"]
             profile["description"] = fetch_api_description(url)
             config[profile_name] = profile
Beispiel #4
0
 def __call__(self, options):
     try:
         with ProfileConfig.open() as config:
             for profile_name in config:
                 profile = config[profile_name]
                 url = profile["url"]
                 profile["description"] = fetch_api_description(url)
                 config[profile_name] = profile
     except FileNotFoundError:
         return
Beispiel #5
0
 def test_fetch_api_description(self):
     content = factory.make_name("content")
     request = self.patch(httplib2.Http, "request")
     response = httplib2.Response({})
     response.status = httplib.OK
     response["content-type"] = "application/json"
     request.return_value = response, json.dumps(content)
     self.assertEqual(
         content, api.fetch_api_description("http://example.com/api/1.0/"))
     request.assert_called_once_with(
         b"http://example.com/api/1.0/describe/", "GET", body=None,
         headers=None)
Beispiel #6
0
 def test_fetch_api_description(self):
     content = factory.make_name("content")
     request = self.patch(httplib2.Http, "request")
     response = httplib2.Response({})
     response.status = http.client.OK
     response["content-type"] = "application/json"
     request.return_value = response, bytes(json.dumps(content), "utf-8")
     self.assertEqual(
         content, api.fetch_api_description("http://example.com/api/2.0/"))
     self.assertThat(request, MockCalledOnceWith(
         "http://example.com/api/2.0/describe/", "GET", body=None,
         headers=None))
Beispiel #7
0
 def __call__(self, options):
     # Try and obtain credentials interactively if they're not given, or
     # read them from stdin if they're specified as "-".
     credentials = obtain_credentials(options.credentials)
     # Get description of remote API.
     description = fetch_api_description(options.url, options.insecure)
     # Save the config.
     profile_name = options.profile_name
     with ProfileConfig.open() as config:
         config[profile_name] = {
             "credentials": credentials,
             "description": description,
             "name": profile_name,
             "url": options.url,
             }
         profile = config[profile_name]
     self.print_whats_next(profile)
Beispiel #8
0
 def __call__(self, options):
     # Try and obtain credentials interactively if they're not given, or
     # read them from stdin if they're specified as "-".
     credentials = obtain_credentials(options.credentials)
     # Get description of remote API.
     description = fetch_api_description(options.url, options.insecure)
     # Save the config.
     profile_name = options.profile_name
     with ProfileConfig.open() as config:
         config[profile_name] = {
             "credentials": credentials,
             "description": description,
             "name": profile_name,
             "url": options.url,
         }
         profile = config[profile_name]
     self.print_whats_next(profile)