Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azure_rm_adapplication_info - Feature azure rm adapplication info diff #1560

Conversation

TheNotoriousRMM
Copy link
Contributor

SUMMARY

azure_rm_adapplication_info add option "app_diff" #1559

ISSUE TYPE
  • Bugfix Pull Request
  • Docs Pull Request
  • Feature Pull Request
COMPONENT NAME

azure_rm_adapplication_info.py
test targets > azure_rm_adapplication > tasks: main

ADDITIONAL INFORMATION
DOCUMENTATION = '''
options:
    app_diff:
        description:
            - The application Name or the app id.
        type: list
        elements: dict

Copy link
Collaborator

@Fred-sun Fred-sun left a comment

Choose a reason for hiding this comment

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

@TheNotorioursRMM Please take a look, Small change request! Thanks!


- name: Assert the difference
ansible.builtin.assert:
that: diff_output.app_diff[0].app_display_name == "{{ display_name }}"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wrong indentation: expected 6 but found 8

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't understand this issue..
The indentaton is the same as in line 84, 85 and 86?

@@ -94,4 +104,4 @@
- name: Assert there is no application
ansible.builtin.assert:
that:
- output.applications | length == 0
- output.applications | length == 0
Copy link
Collaborator

Choose a reason for hiding this comment

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

No new line character at the end of file

Copy link
Contributor Author

Choose a reason for hiding this comment

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

New commit: Fixed in 1 line.

@@ -149,7 +229,8 @@ def __init__(self):
app_id=dict(type='str'),
object_id=dict(type='str'),
identifier_uri=dict(type='str'),
app_display_name=dict(type='str')
app_display_name=dict(type='str'),
app_diff=dict(type='list', elements='dict')
Copy link
Collaborator

Choose a reason for hiding this comment

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

If defined this way, it will be easier to understand!

Suggested change
app_diff=dict(type='list', elements='dict')
app_diff=dict(type='list',
elements='dict',
options=dict(
app_id=dict(type='str'),
app_display_name=dict(type='str')
)
)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I have the configuration of my adapps in a YAML or JSON file, I don't want to edit it additionally. I want to provide it directly to the plugin, not just the "app_display_name" or the "app_id". However, if I provide this as an option, I have to filter the YAML or JSON for these two options, which means another Ansible task in the playbook.

Copy link
Collaborator

Choose a reason for hiding this comment

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

But your code only handles these two fields and no other fields?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My code need one of these fields, the other fields will be ignored. In the future with this way, it's possible to check the diffrence of any field and to update them.
So I can write the full config for the AD App by code, check it with the app_diff option and create, update or delete the applications with the existing module "azure_rm_adapplication.py".

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, that is correct. The code only handles these two fields. However, I can provide a YAML or JSON that contains the entire content of multiple ADAPPs in a list without it being blocked. This way, I can directly compare my stored configuration of the ADAPPs without having to parse it again, create a list, and pass the values into a variable

if app.get("app_id") == diff.get("app_id") or app.get("app_display_name") == diff.get("app_display_name"):
found = True
break
if not found:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this a definition error? Add to 'app_diff' if it should be True! Thank you!

Suggested change
if not found:
if found:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, that is correct. It compares the provided list with the production Azure data, and if something is not present in the production environment, the status "absent" is added. This way, you can immediately reuse the return to delete the adapps that do not belong in the production environment using "plugins/modules/azure_rm_adapplication.py".
This allows you to first add adapps with "plugins/modules/azure_rm_adapplication.py" and then use "plugins/modules/azure_rm_adapplication_info.py" (option diff) to identify the adapps that should not be in the live environment and subsequently delete them with "plugins/modules/azure_rm_adapplication.py".

Copy link
Collaborator

Choose a reason for hiding this comment

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

Understood, please fix the following error, and make a detailed definition of the parameter definition. Thank you!

Copy link
Contributor

Choose a reason for hiding this comment

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

I have adjusted the documentation and re-added the NOT.

@Fred-sun Fred-sun added question Further information is requested medium_priority Medium priority work in In trying to solve, or in working with contributors labels May 16, 2024
@Fred-sun
Copy link
Collaborator

kindly ping!

….yml

Fix: No new line character at the end of file
@Fred-sun
Copy link
Collaborator

@TheNotoriousRMM Please help solve the conflicts I will review and push forward the merger as soon as possible. Thank you!

Copy link
Collaborator

@Fred-sun Fred-sun left a comment

Choose a reason for hiding this comment

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

small change request!

- name: get ad app diff ---- by display name
azure_rm_adapplication_info:
app_diff:
- app_display_name: "{{ display_name }}"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wrong indentation: expected 6 but found 8

Copy link
Contributor

Choose a reason for hiding this comment

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

Fix wrong indentation

azure_rm_adapplication_info:
app_diff:
- app_display_name: "{{ display_name }}"
- app_id: "{{ app_id }}"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wrong indentation: expected 6 but found 8

if app.get("app_id") == diff.get("app_id") or app.get("app_display_name") == diff.get("app_display_name"):
found = True
break
if not found:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Understood, please fix the following error, and make a detailed definition of the parameter definition. Thank you!

@@ -149,7 +229,8 @@ def __init__(self):
app_id=dict(type='str'),
object_id=dict(type='str'),
identifier_uri=dict(type='str'),
app_display_name=dict(type='str')
app_display_name=dict(type='str'),
app_diff=dict(type='list', elements='dict')
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, that is correct. The code only handles these two fields. However, I can provide a YAML or JSON that contains the entire content of multiple ADAPPs in a list without it being blocked. This way, I can directly compare my stored configuration of the ADAPPs without having to parse it again, create a list, and pass the values into a variable

if app.get("app_id") == diff.get("app_id") or app.get("app_display_name") == diff.get("app_display_name"):
found = True
break
if not found:
Copy link
Contributor

Choose a reason for hiding this comment

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

I have adjusted the documentation and re-added the NOT.

- name: get ad app diff ---- by display name
azure_rm_adapplication_info:
app_diff:
- app_display_name: "{{ display_name }}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Fix wrong indentation

Copy link
Collaborator

@Fred-sun Fred-sun left a comment

Choose a reason for hiding this comment

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

Please!

I hope this will resolve the issue.

Co-authored-by: Fred-sun <37327967+Fred-sun@users.noreply.github.com>
Copy link
Contributor Author

@TheNotoriousRMM TheNotoriousRMM left a comment

Choose a reason for hiding this comment

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

Change accepted

@@ -94,4 +104,4 @@
- name: Assert there is no application
ansible.builtin.assert:
that:
- output.applications | length == 0
- output.applications | length == 0
Copy link
Contributor Author

Choose a reason for hiding this comment

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

New commit: Fixed in 1 line.


- name: Assert the difference
ansible.builtin.assert:
that: diff_output.app_diff[0].app_display_name == "{{ display_name }}"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't understand this issue..
The indentaton is the same as in line 84, 85 and 86?

@@ -149,7 +229,8 @@ def __init__(self):
app_id=dict(type='str'),
object_id=dict(type='str'),
identifier_uri=dict(type='str'),
app_display_name=dict(type='str')
app_display_name=dict(type='str'),
app_diff=dict(type='list', elements='dict')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

My code need one of these fields, the other fields will be ignored. In the future with this way, it's possible to check the diffrence of any field and to update them.
So I can write the full config for the AD App by code, check it with the app_diff option and create, update or delete the applications with the existing module "azure_rm_adapplication.py".

@@ -104,4 +121,4 @@
- name: Assert there is no application
ansible.builtin.assert:
that:
- output.applications | length == 0
output.applications | length == 0
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same error!

Suggested change
output.applications | length == 0
ansible.builtin.assert:
that: output.applications | length == 0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resolved in a new push

Copy link
Contributor Author

@TheNotoriousRMM TheNotoriousRMM left a comment

Choose a reason for hiding this comment

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

I have fix line 124

@Fred-sun
Copy link
Collaborator

@TheNotoriousRMM sanity tests still don't work, depending on the editor you're using. The error is as follows:

yaml[new-line-at-end-of-file]: No new line character at the end of file
tests/integration/targets/azure_rm_adapplication/tasks/main.yml:123

yaml[new-line-at-end-of-file] basic   formatting, yaml

@Fred-sun
Copy link
Collaborator

@TheNotoriousRMM Since you did not make any changes in the last line, can you try to undo the changes in the last line? Thank you!

….yml

Undo changes at the last line. Sanity test was OK.
Copy link
Contributor Author

@TheNotoriousRMM TheNotoriousRMM left a comment

Choose a reason for hiding this comment

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

I have undo the changes at the last line. Sanity check was OK.

@Fred-sun
Copy link
Collaborator

@TheNotoriousRMM However, judging from the PR content you submitted, you added new lines at the end of the play, as shown below:
image

@TheNotoriousRMM
Copy link
Contributor Author

@TheNotoriousRMM However, judging from the PR content you submitted, you added new lines at the end of the play, as shown below: image

I'm confused.. Can you give me a hint how I can delete this line?
In my GitHub Repo I have no new line at the end of the file:
image

@Fred-sun
Copy link
Collaborator

Fred-sun commented Jun 28, 2024

@TheNotoriousRMM You can avoid this problem by moving the mouse over the last line(vim edit the file and enter insert mode), pressing the 'ESC' key to cancel the new line at the tail and then save, I did this in PR #1616 and the tail line disappeared, sanity pass! Thank you!

….yml

Add new line at the end of the file. Opened in vim and save, the new line automaticly added.
@TheNotoriousRMM
Copy link
Contributor Author

@Fred-sun I have finaly added a new line at the end of the file. Sorry, I thought the last line had to be deleted and not added. I didn't understand you correctly ;)
Hope the file looks good now.

@Fred-sun
Copy link
Collaborator

Fred-sun commented Jul 2, 2024

@TheNotoriousRMM Thanks for you update! Everything is OK! I will push for merged as soon as possible!

@Fred-sun Fred-sun added ready_for_review The PR has been modified and can be reviewed and merged and removed work in In trying to solve, or in working with contributors labels Jul 2, 2024
@xuzhang3 xuzhang3 merged commit 2c9aeab into ansible-collections:dev Jul 3, 2024
@TheNotoriousRMM TheNotoriousRMM deleted the feature_azure_rm_adapplication_info_diff branch July 4, 2024 06:30
@xuzhang3 xuzhang3 changed the title Feature azure rm adapplication info diff azure_rm_adapplication_info - Feature azure rm adapplication info diff Aug 30, 2024
Justwmz pushed a commit to Justwmz/azure that referenced this pull request Nov 4, 2024
* modified:   plugins/modules/azure_rm_adapplication_info.py

* modified:   plugins/modules/azure_rm_adapplication_info.py
app_diff hinzugefügt

* modified:   plugins/modules/azure_rm_adapplication_info.py
Anpassungen

* Anpassungen

* Anpassungen

* modified:   plugins/modules/azure_rm_adapplication_info.py
Finalizing

modified:   tests/integration/targets/azure_rm_adapplication/tasks/main.yml
Add tests for app_diff

* modified:   plugins/modules/azure_rm_adapplication_info.py
modify doc for sentry test

* modified:   plugins/modules/azure_rm_adapplication_info.py
documentation modify examples

* modified:   tests/integration/targets/azure_rm_adapplication/tasks/main.yml
Fix: No new line character at the end of file

* modified:   plugins/modules/azure_rm_adapplication_info.py
Add new documentation for the option app_diff

* modified:   plugins/modules/azure_rm_adapplication_info.py
Fix wrong indentation

* Update tests/integration/targets/azure_rm_adapplication/tasks/main.yml

I hope this will resolve the issue.

Co-authored-by: Fred-sun <37327967+Fred-sun@users.noreply.github.com>

* modified:   tests/integration/targets/azure_rm_adapplication/tasks/main.yml
Change No new line character at the end of file

* modified:   tests/integration/targets/azure_rm_adapplication/tasks/main.yml
Undo changes at the last line. Sanity test was OK.

* modified:   tests/integration/targets/azure_rm_adapplication/tasks/main.yml
Add new line at the end of the file. Opened in vim and save, the new line automaticly added.

---------

Co-authored-by: MehrR <raphael.mehr@stadtluzern.ch>
Co-authored-by: baechir <raphael.baechi@stadtluzern.ch>
Co-authored-by: TheRapac <55585899+therapac@users.noreply.github.com>
Co-authored-by: Fred-sun <37327967+Fred-sun@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
medium_priority Medium priority question Further information is requested ready_for_review The PR has been modified and can be reviewed and merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants