Пример #1
0
    def create(self):
        if (self.cli_args.name is None or self.cli_args.name is ''):
            message = "Account name is required"
            CLIResponse.send_error_out(message)

        if (self.cli_args.password is None):
            message = "Account login password is required"
            CLIResponse.send_error_out(message)

        passwordResetRequired = False
        if (self.cli_args.password_reset_required):
            passwordResetRequired = True

        # Get host value from url https://iam.seagate.com:9443
        url_parse_result = urllib.parse.urlparse(Config.endpoint)
        epoch_t = datetime.datetime.utcnow()
        body = urllib.parse.urlencode({
            'Action':
            'CreateAccountLoginProfile',
            'AccountName':
            self.cli_args.name,
            'Password':
            self.cli_args.password,
            'PasswordResetRequired':
            passwordResetRequired
        })
        headers = {
            'content-type': 'application/x-www-form-urlencoded',
            'Accept': 'text/plain'
        }
        headers['Authorization'] = sign_request_v4('POST', '/', body, epoch_t,
                                                   url_parse_result.netloc,
                                                   Config.service,
                                                   Config.default_region)
        headers['X-Amz-Date'] = get_timestamp(epoch_t)
        if (headers['Authorization'] is None):
            message = "Failed to generate v4 signature"
            CLIResponse.send_error_out(message)
        result = ConnMan.send_post_request(body, headers)
        # Validate response
        if (result['status'] == 201):
            profile = CreateAccountLoginProfileResponse(result)

            if profile.is_valid_response():
                profile.print_profile_info()
            else:
                # unlikely message corruption case in network
                message = "Account login profile was created. For details try get account login profile."
                CLIResponse.send_success_out(message)
        elif (result['status'] == 503):
            message = "Failed to create Account login profile.\n" \
                      "An error occurred (503) when calling the CreateAccountLoginProfile operation : " + result['reason']
            CLIResponse.send_error_out(message)
        else:
            message = "Failed to create Account login profile.\n"
            error = ErrorResponse(result)
            message += error.get_error_message()
            CLIResponse.send_error_out(message)
Пример #2
0
    def list(self):
        # Get host value from url https://iam.seagate.com:9443
        if (self.cli_args.name is None):
            message = "Account name is required."
            CLIResponse.send_error_out(message)

        url_parse_result = urllib.parse.urlparse(Config.endpoint)

        epoch_t = datetime.datetime.utcnow()

        body = urllib.parse.urlencode({
            'Action': 'GetAccountLoginProfile',
            'AccountName': self.cli_args.name
        })
        headers = {
            'content-type': 'application/x-www-form-urlencoded',
            'Accept': 'text/plain'
        }
        headers['Authorization'] = sign_request_v4('POST', '/', body, epoch_t,
                                                   url_parse_result.netloc,
                                                   Config.service,
                                                   Config.default_region)
        headers['X-Amz-Date'] = get_timestamp(epoch_t)

        if (self.cli_args.session_token is not None):
            headers['X-Amz-Security-Token'] = self.cli_args.session_token

        if (headers['Authorization'] is None):
            message = "Failed to generate v4 signature"
            CLIResponse.send_error_out(message)
        response = ConnMan.send_post_request(body, headers)
        if response['status'] == 200:
            accounts = GetAccountLoginProfileResponse(response)

            if accounts.is_valid_response():
                accounts.print_account_login_profile_info()
            else:
                # unlikely message corruption case in network
                message = "Failed to list login profile"
                CLIResponse.send_success_out(message)
        elif (response['status'] == 503):
            message = "Failed to get login profile\n" \
                      "An error occurred (503) when calling the GetAccountLoginProfile operation : " + response['reason']
            CLIResponse.send_error_out(message)
        else:
            message = "Failed to get login profile\n"
            error = ErrorResponse(response)
            message += error.get_error_message()
            CLIResponse.send_error_out(message)
Пример #3
0
    def delete(self):
        if self.cli_args.name is None:
            print('Account name is required.')
            CLIResponse.send_error_out(message)
        # Get host value from url https://iam.seagate.com:9443
        url_parse_result = urllib.parse.urlparse(Config.endpoint)

        epoch_t = datetime.datetime.utcnow()

        account_params = {
            'Action': 'DeleteAccount',
            'AccountName': self.cli_args.name
        }
        if self.cli_args.force:
            account_params['force'] = True

        epoch_t = datetime.datetime.utcnow()
        body = urllib.parse.urlencode(account_params)

        headers = {
            'content-type': 'application/x-www-form-urlencoded',
            'Accept': 'text/plain'
        }
        headers['Authorization'] = sign_request_v4('POST', '/', body, epoch_t,
                                                   url_parse_result.netloc,
                                                   Config.service,
                                                   Config.default_region)
        headers['X-Amz-Date'] = get_timestamp(epoch_t)

        if (self.cli_args.session_token is not None):
            headers['X-Amz-Security-Token'] = self.cli_args.session_token
        if (headers['Authorization'] is None):
            print("Failed to generate v4 signature")
            CLIResponse.send_error_out(message)

        response = ConnMan.send_post_request(body, headers)

        if response['status'] == 200:
            print('Account deleted successfully.')
        elif (response['status'] == 503):
            message = "Account cannot be deleted.\n" \
                      "An error occurred (503) when calling the DeleteAccount operation : " + response['reason']
            CLIResponse.send_error_out(message)
        else:
            message = 'Account cannot be deleted.\n'
            error = ErrorResponse(response)
            message += error.get_error_message()
            CLIResponse.send_error_out(message)
Пример #4
0
    def list(self):
        # Get host value from url https://iam.seagate.com:9443
        url_parse_result = urllib.parse.urlparse(Config.endpoint)

        epoch_t = datetime.datetime.utcnow()

        showAll = False
        if (self.cli_args.showall):
            showAll = True

        body = urllib.parse.urlencode({
            'Action': 'ListAccounts',
            'ShowAll': showAll
        })
        headers = {
            'content-type': 'application/x-www-form-urlencoded',
            'Accept': 'text/plain'
        }
        headers['Authorization'] = sign_request_v4('POST', '/', body, epoch_t,
                                                   url_parse_result.netloc,
                                                   Config.service,
                                                   Config.default_region)
        headers['X-Amz-Date'] = get_timestamp(epoch_t)

        if (headers['Authorization'] is None):
            print("Failed to generate v4 signature")
            CLIResponse.send_error_out(message)
        response = ConnMan.send_post_request(body, headers)

        if response['status'] == 200:
            accounts = ListAccountResponse(response)

            if accounts.is_valid_response():
                accounts.print_account_listing()
            else:
                # unlikely message corruption case in network
                print("Failed to list accounts.")
                sys.exit(0)
        elif (response['status'] == 503):
            message = "Failed to list accounts!\n" \
                      "An error occurred (503) when calling the ListAccounts operation : " + response['reason']
            CLIResponse.send_error_out(message)
        else:
            message = "Failed to list accounts!\n"
            error = ErrorResponse(response)
            message += error.get_error_message()
            CLIResponse.send_error_out(message)
Пример #5
0
    def create(self):
        if self.cli_args.name is None:
            message = "Account name is required."
            CLIResponse.send_error_out(message)

        if self.cli_args.email is None:
            message = "Email Id of the user is required to create an Account"
            CLIResponse.send_error_out(message)
        # Get host value from url https://iam.seagate.com:9443
        url_parse_result = urllib.parse.urlparse(Config.endpoint)
        epoch_t = datetime.datetime.utcnow()
        body = urllib.parse.urlencode({
            'Action': 'CreateAccount',
            'AccountName': self.cli_args.name,
            'Email': self.cli_args.email
        })
        headers = {
            'content-type': 'application/x-www-form-urlencoded',
            'Accept': 'text/plain'
        }
        headers['Authorization'] = sign_request_v4('POST', '/', body, epoch_t,
                                                   url_parse_result.netloc,
                                                   Config.service,
                                                   Config.default_region)
        headers['X-Amz-Date'] = get_timestamp(epoch_t)
        if (headers['Authorization'] is None):
            print("Failed to generate v4 signature")
            sys.exit(1)
        response = ConnMan.send_post_request(body, headers)
        if (response['status'] == 201):
            account = CreateAccountResponse(response)

            if account.is_valid_response():
                account.print_account_info()
            else:
                # unlikely message corruption case in network
                message = "Account was created. For account details try account listing."
                CLIResponse.send_success_out(message)
        elif (response['status'] == 503):
            message = "Account wasn't created.\n" \
                      "An error occurred (503) when calling the CreateAccount operation : " + response['reason']
            CLIResponse.send_error_out(message)
        else:
            message = "Account wasn't created.\n"
            error = ErrorResponse(response)
            message += error.get_error_message()
            CLIResponse.send_error_out(message)
Пример #6
0
    def update(self):
        if (self.cli_args.name is None):
            message = "Account name is required for UpdateAccountLoginProfile"
            CLIResponse.send_error_out(message)

        passwordResetRequired = False
        if (self.cli_args.password_reset_required):
            passwordResetRequired = True
        if (self.cli_args.password is None) and (
                self.cli_args.password_reset_required is
                False) and (self.cli_args.no_password_reset_required is False):
            message = "Please provide password or password-reset flag"
            CLIResponse.send_error_out(message)

        # Get host value from url https://iam.seagate.com:9443
        url_parse_result = urllib.parse.urlparse(Config.endpoint)
        epoch_t = datetime.datetime.utcnow()
        if (self.cli_args.password is None):
            body = urllib.parse.urlencode({
                'Action':
                'UpdateAccountLoginProfile',
                'AccountName':
                self.cli_args.name,
                'PasswordResetRequired':
                passwordResetRequired
            })
        else:
            body = urllib.parse.urlencode({
                'Action':
                'UpdateAccountLoginProfile',
                'AccountName':
                self.cli_args.name,
                'Password':
                self.cli_args.password,
                'PasswordResetRequired':
                passwordResetRequired
            })
        headers = {
            'content-type': 'application/x-www-form-urlencoded',
            'Accept': 'text/plain'
        }
        headers['Authorization'] = sign_request_v4('POST', '/', body, epoch_t,
                                                   url_parse_result.netloc,
                                                   Config.service,
                                                   Config.default_region)
        headers['X-Amz-Date'] = get_timestamp(epoch_t)
        if (self.cli_args.session_token is not None):
            headers['X-Amz-Security-Token'] = self.cli_args.session_token

        if (headers['Authorization'] is None):
            message = "Failed to generate v4 signature"
            CLIResponse.send_error_out(message)
        result = ConnMan.send_post_request(body, headers)
        # Validate response
        if (result['status'] == 200):
            message = "Account login profile updated."
            CLIResponse.send_success_out(message)
        elif (result['status'] == 503):
            message = "Failed to update Account login profile.\n" \
                      "An error occurred (503) when calling the UpdateAccountLoginProfile operation : " + result['reason']
            CLIResponse.send_error_out(message)
        else:
            message = "Account login profile wasn't Updated."
            error = ErrorResponse(result)
            message += error.get_error_message()
            CLIResponse.send_error_out(message)
Пример #7
0
    def create(self):
        if (self.cli_args.account_name is None):
            message = "Account Name is required for getting auth credentials"
            CLIResponse.send_error_out(message)

        if (self.cli_args.password is None):
            message = "Account password is required for getting auth credentials"
            CLIResponse.send_error_out(message)

        url_parse_result = urllib.parse.urlparse(Config.endpoint)
        epoch_t = datetime.datetime.utcnow()
        if (self.cli_args.name is None):
            if (self.cli_args.duration is None):
                body = urllib.parse.urlencode({
                    'Action':
                    'GetTempAuthCredentials',
                    'AccountName':
                    self.cli_args.account_name,
                    'Password':
                    self.cli_args.password
                })
            else:
                body = urllib.parse.urlencode({
                    'Action':
                    'GetTempAuthCredentials',
                    'AccountName':
                    self.cli_args.account_name,
                    'Password':
                    self.cli_args.password,
                    'Duration':
                    self.cli_args.duration
                })
        else:
            if (self.cli_args.duration is None):
                body = urllib.parse.urlencode({
                    'Action': 'GetTempAuthCredentials',
                    'AccountName': self.cli_args.account_name,
                    'Password': self.cli_args.password,
                    'UserName': self.cli_args.name
                })
            else:
                body = urllib.parse.urlencode({
                    'Action': 'GetTempAuthCredentials',
                    'AccountName': self.cli_args.account_name,
                    'Password': self.cli_args.password,
                    'Duration': self.cli_args.duration,
                    'UserName': self.cli_args.name
                })

        headers = {
            'content-type': 'application/x-www-form-urlencoded',
            'Accept': 'text/plain'
        }
        headers['Authorization'] = sign_request_v4('POST', '/', body, epoch_t,
                                                   url_parse_result.netloc,
                                                   Config.service,
                                                   Config.default_region)
        headers['X-Amz-Date'] = get_timestamp(epoch_t)
        if (headers['Authorization'] is None):
            message = "Failed to generate v4 signature"
            CLIResponse.send_error_out(message)
        response = ConnMan.send_post_request(body, headers)
        if (response['status'] == 201):
            credentials = GetTempAuthCredentialsResponse(response)
            credentials.print_credentials()
        elif (response['status'] == 503):
            message = "GetTempAuthCredentials not successful\n" \
            + "An error occurred (503) when calling the GetTempAuthCredentials operation : " + response['reason']
            CLIResponse.send_error_out(message)
        else:
            message = "GetTempAuthCredentials not successful\n"
            error = ErrorResponse(response)
            message += error.get_error_message()
            CLIResponse.send_error_out(message)