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

Adding nginxcfg to useful scripts #20

Merged
merged 1 commit into from
Apr 8, 2020
Merged

Conversation

LukeShirnia
Copy link
Collaborator

subrepo:
  subdir:   "nginxcfg"
  merged:   "315f8b7"
upstream:
  origin:   "https://github.com/LukeShirnia/nginxcfg.git"
  branch:   "master"
  commit:   "315f8b7"
git-subrepo:
  version:  "0.4.1"
  origin:   "https://github.com/ingydotnet/git-subrepo"
  commit:   "a04d8c2"
[lukeshirnia@rax useful-scripts]$ ./audit.sh --add nginxcfg https://github.com/LukeShirnia/nginxcfg.git

Error: You appear to be working on the master branch!
Updating/adding should be added to a sub branch.

Would you like to autocreate a new branch (nginxcfg-2020-02-25)? (y|n) y
Subrepo 'https://github.com/LukeShirnia/nginxcfg.git' (master) cloned into 'nginxcfg'.

------------------------------------------
Verifying recorded commit...

Commit on file: 315f8b70e3b0087b3a14c14907b9e954d9cb9cb6
/home/lukeshirnia/development/github/git_rackspace/useful-scripts/nginxcfg/.gitrepo

Remote Repo Info (commit)
https://raw.githubusercontent.com/LukeShirnia/nginxcfg/315f8b70e3b0087b3a14c14907b9e954d9cb9cb6/nginxcfg.py
sha1sum: 08e0f432083ba1b48248d29343630b54fe69bdb2

SubRepo (local) Info (nginxcfg-2020-02-25)
/home/lukeshirnia/development/github/git_rackspace/useful-scripts/nginxcfg/nginxcfg.py
sha1sum: 08e0f432083ba1b48248d29343630b54fe69bdb2

Verifying commit: sha1sums match!
nginxcfg-2020-02-25 (local branch) is inline with specified commit hash
------------------------------------------

@LukeHandle LukeHandle self-assigned this Mar 16, 2020
Copy link
Contributor

@LukeHandle LukeHandle left a comment

Choose a reason for hiding this comment

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

A few queries for discussion

except OSError:
return []

def _get_all_config(self, config_file=None):
Copy link
Contributor

Choose a reason for hiding this comment

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

This might be handy as an argument for choosing a non-default config file (custom or source installation).

}


class nginxCfg:
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment: Possibly not needed as a Class -? Lot's of self function referencing, but no __init__ or variable definition.

Comment on lines 92 to 98
config_data = open(config_file, 'r').readlines()

for line in [line.strip().strip(';') for line in config_data]:
if line.startswith('#'):
continue
line = line.split('#')[0]
if line.startswith('include'):
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd generally recommend reading line by line vs. all into memory (not that the performance here requires it).

It is very doable here with no extra change - you are just looping over the readlines() return currently... instead just loop over the file object:

Suggested change
config_data = open(config_file, 'r').readlines()
for line in [line.strip().strip(';') for line in config_data]:
if line.startswith('#'):
continue
line = line.split('#')[0]
if line.startswith('include'):
for line in [l.strip().rstrip(';') for l in open(config_file, 'r')]:
line = line.split('#')[0]
if line.startswith('include'):
line = line.split('#')[0]

(The startswith("#") is also not needed as you already check for "include")

In an ideal world, I'd suggest combining the looping to find includes with the config parsing vs. reading the files twice.

@LukeHandle
Copy link
Contributor

$ git checkout nginxcfg-2020-02-25
$ ./audit.sh --verify nginxcfg

------------------------------------------
Verifying recorded commit...

Commit on file: 315f8b70e3b0087b3a14c14907b9e954d9cb9cb6
https://raw.githubusercontent.com/rackerlabs/useful-scripts/nginxcfg-2020-02-25/nginxcfg/.gitrepo

\e[4mRemote Repo Info (commit)\e[24m
https://raw.githubusercontent.com/LukeShirnia/nginxcfg/315f8b70e3b0087b3a14c14907b9e954d9cb9cb6/nginxcfg.py
sha1sum: 08e0f432083ba1b48248d29343630b54fe69bdb2

\e[4mSubRepo (remote) Info (nginxcfg-2020-02-25)\e[24m
https://raw.githubusercontent.com/rackerlabs/useful-scripts/nginxcfg-2020-02-25/nginxcfg/nginxcfg.py
sha1sum: 08e0f432083ba1b48248d29343630b54fe69bdb2

Verifying commit: sha1sums match!
nginxcfg-2020-02-25 (remote branch) is inline with specified commit hash
------------------------------------------

Verifies, though still pending comment responses

@LukeHandle LukeHandle removed their assignment Mar 19, 2020
subrepo:
  subdir:   "nginxcfg"
  merged:   "1e0ce24"
upstream:
  origin:   "https://github.com/LukeShirnia/nginxcfg.git"
  branch:   "master"
  commit:   "1e0ce24"
git-subrepo:
  version:  "0.4.1"
  origin:   "https://github.com/ingydotnet/git-subrepo"
  commit:   "a04d8c2"
@LukeShirnia LukeShirnia force-pushed the nginxcfg-2020-02-25 branch from 69e4f3c to aa90cb7 Compare April 6, 2020 14:43
Copy link
Contributor

@LukeHandle LukeHandle left a comment

Choose a reason for hiding this comment

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

LGTM, verify...

return server_dict_ret

def get_vhosts(self, exclude_string):
vhosts_list = self._get_vhosts()
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment: All that happens with vhosts_list is you iterate through it. Would probably be preferred to iterating through the function directly.

Further to that, the function itself is a fairly simply loop. It's definitely beneficial to split the code out into functions - though the separation here seems less worthwhile.

        ret = []
        for f in self._get_all_config():
            ret += self._get_vhosts_info(f)
        return ret

I know there are larger plans to further rework bits (more than this minimal touch update), so no requirement for this now.

open_brackets = 0
found_server_block = False
for line_number, line in enumerate(vhost_data):
if line.startswith('#'):
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't appear to be an issue, but this doesn't account for indented comments - it's either not needed because maybe you deal with comments later on, or it's worth adding a line.lstrip() here? 🤷‍♂

    #TESTING Not picked up
#TESTING correctly skipped

@LukeHandle
Copy link
Contributor

▶ ./audit.sh --verify nginxcfg

------------------------------------------
Verifying recorded commit...

Commit on file: 1e0ce24581d72cf109f3d63ffc6938a6e032071f
https://raw.githubusercontent.com/rackerlabs/useful-scripts/nginxcfg-2020-02-25/nginxcfg/.gitrepo

\e[4mRemote Repo Info (commit)\e[24m
https://raw.githubusercontent.com/LukeShirnia/nginxcfg/1e0ce24581d72cf109f3d63ffc6938a6e032071f/nginxcfg.py
sha1sum: 86f6d4942e1e98f26fb0b3b676abb0e211a922d9

\e[4mSubRepo (remote) Info (nginxcfg-2020-02-25)\e[24m
https://raw.githubusercontent.com/rackerlabs/useful-scripts/nginxcfg-2020-02-25/nginxcfg/nginxcfg.py
sha1sum: 86f6d4942e1e98f26fb0b3b676abb0e211a922d9

Verifying commit: sha1sums match!
nginxcfg-2020-02-25 (remote branch) is inline with specified commit hash
------------------------------------------

@LukeHandle LukeHandle merged commit ada52d0 into master Apr 8, 2020
@LukeHandle LukeHandle deleted the nginxcfg-2020-02-25 branch April 8, 2020 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants