Skip to content

Releases: ClessLi/bifrost

v1.1.0-alpha.8

25 Feb 02:37
Compare
Choose a tag to compare
v1.1.0-alpha.8 Pre-release
Pre-release

v1.1.0-alpha.8 - 2025-02-25

Features

  • bifrost: add updating check feature in the bifrostpb.WebServerConfig gRPC service

BREAKING CHANGE

adjusted the gRPC protocol and added the OriginalFingerprints data field to the ServerConfig message structure; Optimized the WebServerConfigService service interface methods for the gRPC service client.

The ServerConfig message structure field has been added as follows:

Addition of message structure fields:

message ServerConfig {
  ...
  bytes OriginalFingerprints = 3;
}

The adjustment of the WebServerConfigService service interface methods for the gRPC service client are as follows:

Before:

type WebServerConfigService interface {
    GetServerNames() (servernames []string, err error)
    Get(servername string) ([]byte, error)
    Update(servername string, config []byte) error
}

After:

import (
    ...
    "github.com/ClessLi/bifrost/pkg/resolv/V3/nginx/configuration"
    utilsV3 "github.com/ClessLi/bifrost/pkg/resolv/V3/nginx/configuration/utils"
    ...
)

type WebServerConfigService interface {
    GetServerNames() (servernames []string, err error)
    Get(servername string) (config configuration.NginxConfig, originalFingerprinter utilsV3.ConfigFingerprinter, err error)
    Update(servername string, config configuration.NginxConfig, originalFingerprints utilsV3.ConfigFingerprints) error
}

v1.1.0-alpha.7

19 Feb 07:15
Compare
Choose a tag to compare
v1.1.0-alpha.7 Pre-release
Pre-release

v1.1.0-alpha.7 - 2025-02-19

Code Refactoring

  • delete mistakenly added structure

Features

  • resolv: make the Context more supportive of functional-style operations on streams of elements

BREAKING CHANGE

removed the Query related methods of the Context interface and added the PosSet interface.

The Query related methods of the Context interface has been removed as follows:

Methods of deletion to Context:

type Context interface {
    ...
    QueryByKeyWords(kw KeyWords) Pos
    QueryAllByKeyWords(kw KeyWords) []Pos
    ...
}

Methods of addition to Context Interface:

type Context interface {
    ...
    ChildrenPosSet() PosSet
    ...
}

Added the PosSet interface as follows:

Interface of addition:

type PosSet interface {
    Filter(fn func(pos Pos) bool) PosSet
    Map(fn func(pos Pos) (Pos, error)) PosSet
    MapToPosSet(fn func(pos Pos) PosSet) PosSet
    QueryOne(kw KeyWords) Pos
    QueryAll(kw KeyWords) PosSet
    List() []Pos
    Targets() []Context
    Append(pos ...Pos) PosSet
    AppendWithPosSet(posSet PosSet) PosSet
    Error() error
}

Methods of addition to Pos Interface:

type Pos interface {
    ...
    QueryOne(kw KeyWords) Pos
    QueryAll(kw KeyWords) PosSet
}

To migrate the code for the Context operations, follow the example below:

Before:

package main

import (
	"fmt"
	"github.com/ClessLi/bifrost/pkg/resolv/V3/nginx/configuration/context_type"

	"github.com/ClessLi/bifrost/pkg/resolv/V3/nginx/configuration"
	"github.com/ClessLi/bifrost/pkg/resolv/V3/nginx/configuration/context"
	"github.com/ClessLi/bifrost/pkg/resolv/V3/nginx/configuration/context/local"
)

func main() {
    conf, err := configuration.NewNginxConfigFromJsonBytes(jsondata)
    if err != nil {
        panic(err)
    }
    for _, pos := range conf.Main().QueryByKeyWords(context.NewKeyWords(context_type.TypeHttp).
	        SetSkipQueryFilter(context.SkipDisabledCtxFilterFunc)).Target().
	    QueryByKeyWords(context.NewKeyWords(context_type.TypeServer).
            SetSkipQueryFilter(context.SkipDisabledCtxFilterFunc)).Target().
        QueryAllByKeyWords(context.NewKeyWords(context_type.TypeDirective).
            SetCascaded(false).
            SetStringMatchingValue("server_name test1.com").
            SetSkipQueryFilter(context.SkipDisabledCtxFilterFunc)) { // query `server` context, its server name is "test1.com"
        server, _ := pos.Position()
        if server.QueryByKeyWords(context.NewKeyWords(context_type.TypeDirective).
                SetCascaded(false).
                SetRegexpMatchingValue("^listen 80$").
            SetSkipQueryFilter(context.SkipDisabledCtxFilterFunc)).Target().Error() != nil { // query `server` context, its listen port is 80
            continue
        }
        // query the "proxy_pass" `directive` context, which is in `if` context(value: "($http_api_name != '')") and `location` context(value: "/test1-location")
        ctx, idx := server.QueryByKeyWords(context.NewKeyWords(context_type.TypeLocation).
                SetRegexpMatchingValue(`^/test1-location$`).
                SetSkipQueryFilter(context.SkipDisabledCtxFilterFunc)).Target().
            QueryByKeyWords(context.NewKeyWords(context_type.TypeIf).
                SetRegexpMatchingValue(`^\(\$http_api_name != ''\)$`).
                SetSkipQueryFilter(context.SkipDisabledCtxFilterFunc)).Target().
            QueryByKeyWords(context.NewKeyWords(context_type.TypeDirective).
                SetStringMatchingValue("proxy_pass").
                SetSkipQueryFilter(context.SkipDisabledCtxFilterFunc)).Position()
        // insert an inline comment after the "proxy_pass" `directive` context
        err = ctx.Insert(local.NewContext(context_type.TypeInlineComment, fmt.Sprintf("[%s]test comments", time.Now().String())), idx+1).Error()
        if err != nil {
			panic(err)
        }
    }
}

After:

package main

import (
	"fmt"
	"github.com/ClessLi/bifrost/pkg/resolv/V3/nginx/configuration/context_type"

	"github.com/ClessLi/bifrost/pkg/resolv/V3/nginx/configuration"
	"github.com/ClessLi/bifrost/pkg/resolv/V3/nginx/configuration/context"
	"github.com/ClessLi/bifrost/pkg/resolv/V3/nginx/configuration/context/local"
)

func main() {
    conf, err := configuration.NewNginxConfigFromJsonBytes(jsondata)
    if err != nil {
        panic(err)
	}
    ctx, idx := conf.Main().ChildrenPosSet().
        QueryOne(nginx_ctx.NewKeyWords(context_type.TypeHttp).
            SetSkipQueryFilter(context.SkipDisabledCtxFilterFunc)).
        QueryAll(nginx_ctx.NewKeyWords(context_type.TypeServer).
            SetSkipQueryFilter(context.SkipDisabledCtxFilterFunc)).
        Filter( // filter out `server` context positions, theirs server name is "test1.com"
            func(pos nginx_ctx.Pos) bool {
            return pos.QueryOne(context.NewKeyWords(context_type.TypeDirective).
                    SetCascaded(false).
                    SetStringMatchingValue("server_name test1.com").
                    SetSkipQueryFilter(context.SkipDisabledCtxFilterFunc)).
                Target().Error() == nil
            },
        ).
        Filter( // filter out `server` context positions, theirs listen port is 80
            func(pos nginx_ctx.Pos) bool {
                return pos.QueryOne(context.NewKeyWords(context_type.TypeDirective).
                        SetCascaded(false).
                        SetRegexpMatchingValue("^listen 80$").
                        SetSkipQueryFilter(context.SkipDisabledCtxFilterFunc)).
                    Target().Error() == nil
            },
        ).
        // query the "proxy_pass" `directive` context position, which is in `if` context(value: "($http_api_name != '')") and `location` context(value: "/test1-location")
        QueryOne(nginx_ctx.NewKeyWords(context_type.TypeLocation).
            SetRegexpMatchingValue(`^/test1-location$`).
            SetSkipQueryFilter(context.SkipDisabledCtxFilterFunc)).
        QueryOne(nginx_ctx.NewKeyWords(context_type.TypeIf).
            SetRegexpMatchingValue(`^\(\$http_api_name != ''\)$`).
            SetSkipQueryFilter(context.SkipDisabledCtxFilterFunc)).
        QueryOne(nginx_ctx.NewKeyWords(context_type.TypeDirective).
            SetStringMatchingValue("proxy_pass").
            SetSkipQueryFilter(context.SkipDisabledCtxFilterFunc)).
        Position()
    // insert an inline comment after the "proxy_pass" `directive` context
    err = ctx.Insert(local.NewContext(context_type.TypeInlineComment, fmt.Sprintf("[%s]test comments", time.Now().String())), idx+1).Error()
    if err != nil {
        panic(err)
    }
}

v1.1.0-alpha.6

22 Jan 02:57
Compare
Choose a tag to compare
v1.1.0-alpha.6 Pre-release
Pre-release

v1.1.0-alpha.6 - 2025-01-22

Bug Fixes

  • web_server_bin_cmd: fixed the issue where non-corresponding binary file were used for executing commands on the specified web server; adjusted the web server binary file execution receipt collection and output scheme

v1.1.0-alpha.5

17 Jan 07:27
Compare
Choose a tag to compare
v1.1.0-alpha.5 Pre-release
Pre-release

v1.1.0-alpha.5 - 2025-01-17

Features

  • web_server_bin_cmd: add Web Service Binary Command Execution gRPC Server

BREAKING CHANGE

the bifrost gRPC server APIs have added WebServerBinCMD.Exec server

The protobuf of the bifrost gRPC server APIs has been added as follows:

Protocols of addition:

service WebServerBinCMD {
  rpc Exec(ExecuteRequest) returns (ExecuteResponse) {}
}

message ExecuteRequest {
  string ServerName = 1;
  repeated string Args = 2;
}

message ExecuteResponse {
  bool Successful = 1;
  bytes Stdout = 2;
  bytes Stderr = 3;
}

The bifrost gRPC server APIs client SDK has been added as follows:

Methods of addition to Client Service Factory:

type Factory interface {
    ...
    WebServerBinCMD() WebServerBinCMDService
}

Interface of addition to Client Service:

type WebServerBinCMDService interface {
    Exec(servername string, arg ...string) (isSuccessful bool, stdout, stderr string, err error)
}

v1.1.0-alpha.4

15 Jan 06:14
Compare
Choose a tag to compare
v1.1.0-alpha.4 Pre-release
Pre-release

v1.1.0-alpha.4 - 2025-01-15

Performance Improvements

  • resolv: adjust the mechanism for determining whether the include context is located in the topology
  • resolv: optimizing Nginx configuration context object operation performance expenses

v1.1.0-alpha.3

15 Jan 06:14
Compare
Choose a tag to compare
v1.1.0-alpha.3 Pre-release
Pre-release

[v1.1.0-alpha.3] - 2025-01-10

Bug Fixes

  • fix known vulnerabilities, CVE IDs as follows: CVE-2024-51744, CVE-2023-45288, CVE-2024-45338
  • resolv: adjust the include context loading logic to ensure that the config graph has a unique topology based on the main config as the starting vertex, and stores configs associated with disabled (or unavailable) include contexts.
  • resolv: adjust the include context to load logic from the file system and avoid cycle loading; adjust the main context serialization logic.

Features

  • resolv: nginx configuration Context adds methods for Enable/Disable conversion
  • resolv: change the Include context from statically including sub configs to dynamically including each sub configs the graph data structure of the Main context.

BREAKING CHANGE

changed Nginx configuration Context interface object related methods and its JSON format serialization structure.

The methods for the Context has been changed as follows:

Methods of addition:

type Context interface {
    ...
    // Enable/Disable conversion methods
    IsEnabled() bool
    Enable() Context
    Disable() Context
}

The difference in the output of the ConfigLines method between enabled and disabled Context objects:

// Code:
exampleCtx := NewContext(context_type.TypeConfig, "conf.d/disabled_location.conf").Insert(
    NewContext(context_type.TypeComment, "disabled config"),
    0,
).Insert(
    NewContext(context_type.TypeLocation, "~ /test").Insert(
        NewContext(context_type.TypeDirective, "return 404"),
        0,
    ),
    1,
).Insert(
    NewContext(context_type.TypeLocation, "~ /has-disabled-ctx").Insert(
        NewContext(context_type.TypeComment, "disabled if ctx"),
        0,
    ).Insert(
        NewContext(context_type.TypeIf, "($is_enabled ~* false)").Disable().Insert(
            NewContext(context_type.TypeDirective, "set $is_enabled true").Disable(),
            0,
        ).Insert(
            NewContext(context_type.TypeDirective, "return 404"),
            1,
        ),
        1,
    ),
    2,
).Insert(
    NewContext(context_type.TypeComment, "}"),
    3,
).Insert(
    NewContext(context_type.TypeComment, "}"),
    4,
)
enabledLines, _ := exampleCtx.ConfigLines(false)
fmt.Println("Enabled Contents:\n" + strings.Join(enabledLines, "\n"))
fmt.Println("")
disabledLines, _ := exampleCtx.Disable().ConfigLines(false)
fmt.Println("Disabled Contents:\n" + strings.Join(disabledLines, "\n"))
// Output:
//  Enabled Contents:
//  # disabled config
//  location ~ /test {
//      return 404;
//  }
//  location ~ /has-disabled-ctx {
//      # disabled if ctx
//      # if ($is_enabled ~* false) {
//      #     # set $is_enabled true;
//      #     return 404;
//      # }
//  }
//  # }
//  # }
//
//  Disabled Contents:
//  # # disabled config
//  # location ~ /test {
//  #     return 404;
//  # }
//  # location ~ /has-disabled-ctx {
//  #     # disabled if ctx
//  #     # if ($is_enabled ~* false) {
//  #     #     # set $is_enabled true;
//  #     #     return 404;
//  #     # }
//  # }
//  # # }
//  # # }

The Context JSON format serialization structure changes as follows:

Before:

{
  "main-config":"C:\\test\\nginx.conf",
  "configs":{
    "C:\\test\\nginx.conf":{
      "context-type":"config",
      "value":"C:\\test\\nginx.conf",
      "params":[
        {
          "context-type":"http",
          "params":[
            {
              "context-type":"server",
              "params":[
                {
                  "context-type":"directive",
                  "value":"listen 80"
                },
                {
                  "context-type":"directive",
                  "value":"server_name example.com"
                },
                {
                  "context-type":"include",
                  "value":"conf.d/disabled_location.conf"
                },
                {
                  "context-type":"include",
                  "value":"conf.d/strange_location.conf"
                }
              ]
            },
            {
              "context-type":"comment",
              "value":"disabled server context"
            },
            {
              "context-type":"comment",
              "value":"server { # disabled server"
            },
            {
              "context-type":"comment",
              "value":" listen 8080;"
            },
            {
              "context-type":"comment",
              "value":" server_name example.com;"
            },
            {
              "context-type":"comment",
              "value":" # location ~ /disabled-location {"
            },
            {
              "context-type":"comment",
              "value":" # proxy_pass http://disabled-url;"
            },
            {
              "context-type":"comment",
              "value":" # }"
            },
            {
              "context-type":"comment",
              "value":" include conf.d/disabled_location.conf;"
            },
            {
              "context-type":"comment",
              "value":" include conf.d/strange_location.conf;"
            },
            {
              "context-type":"comment",
              "value":"}"
            }
          ]
        }
      ]
    },
    "conf.d/disabled_location.conf":{
      "context-type":"config",
      "value":"conf.d/disabled_location.conf",
      "params":[
        {
          "context-type":"comment",
          "value":"# disabled config"
        },
        {
          "context-type":"comment",
          "value":"location ~ /test {"
        },
        {
          "context-type":"comment",
          "value":"return 404;"
        },
        {
          "context-type":"comment",
          "value":"}"
        },
        {
          "context-type":"comment",
          "value":"location ~ /has-disabled-ctx {"
        },
        {
          "context-type":"comment",
          "value":"# disabled if ctx"
        },
        {
          "context-type":"comment",
          "value":"# if ($is_enabled ~* false) {"
        },
        {
          "context-type":"comment",
          "value":"# # set $is_enabled true;"
        },
        {
          "context-type":"comment",
          "value":"# return 404;"
        },
        {
          "context-type":"comment",
          "value":"# }"
        },
        {
          "context-type":"comment",
          "value":"}"
        },
        {
          "context-type":"comment",
          "value":"# }"
        },
        {
          "context-type":"comment",
          "value":"}"
        }
      ]
    },
    "conf.d/strange_location.conf":{
      "context-type":"config",
      "value":"conf.d/strange_location.conf",
      "params":[
        {
          "context-type":"comment",
          "value":"strange config"
        },
        {
          "context-type":"location",
          "value":"~ /normal-loc",
          "params":[
            {
              "context-type":"directive",
              "value":"return 200"
            }
          ]
        },
        {
          "context-type":"comment",
          "value":"location ~ /strange-loc {"
        },
        {
          "context-type":"comment",
          "value":" if ($strange ~* this_is_a_strange_if_ctx) {"
        },
        {
          "context-type":"comment",
          "value":" return 404;"
        },
        {
          "context-type":"comment",
          "value":" proxy_pass http://strange_url;"
        },
        {
          "context-type":"comment",
          "value":"}"
        }
      ]
    }
  }
}

After (unconverted):

{
    "main-config":"C:\\test\\nginx.conf",
    "configs":{
        "C:\\test\\nginx.conf":{
            "enabled":true,
            "context-type":"config",
            "value":"C:\\test\\nginx.conf",
            "params":[
                {
                    "enabled":true,
                    "context-type":"http",
                    "params":[
                        {
                            "enabled":true,
                            "context-type":"server",
                            "params":[
                                {
                                    "enabled":true,
                                    "context-type":"directive",
                                    "value":"listen 80"
                                },
                                {
                                    "enabled":true,
                                    "context-type":"directive",
                                    "value":"server_name example.com"
                                },
                                {
                                    "enabled":true,
                                    "context-type":"include",
                                    "value":"conf.d/disabled_location.conf"
                                },
                                {
                                    "enabled":true,
                                    "context-type":"include",
                                    "value":"conf.d/strange_location.conf"
                                }
                            ]
                        },
                        {
                            "context-type":"comment",
                            "value":"disabled server context"
                        },
                        {
                            "context-type":"comment",
                            "value":"server { # disabled server"
                        },
                        {
                ...
Read more

v1.0.12

24 Apr 01:37
Compare
Choose a tag to compare

v1.0.12 - 2024-04-24

Features

  • resolv: refactored the Context JSON format serialization structure to simplify serialization/deserialization operations, making the serialization structure more universal and unified.

BREAKING CHANGE

Changed the serialization structure of the Context JSON format, as well as the new functions for the Directive and Comment context objects.

The Context JSON format serialization structure changes as follows:

Before:

{
    "main-config": "C:\\test\\test.conf",
    "configs":
    {
        "C:\\test\\test.conf":
        [
            {
                "http":
                {
                    "params":
                    [
                        {
                            "inline": true, "comments": "test comment"
                        },
                        {
                            "server":
                            {
                                "params":
                                [
                                    {
                                        "directive": "server_name", "params": "testserver"
                                    },
                                    {
                                        "location": {"value": "~ /test"}
                                    },
                                    {
                                        "include":
                                        {
                                            "value": "conf.d\\include*conf",
                                            "params": ["conf.d\\include.location1.conf", "conf.d\\include.location2.conf"]
                                        }
                                    }
                                ]
                            }
                        }
                    ]
                }
            }
        ],
        "conf.d\\include.location1.conf":
        [
            {
                "location": {"value": "~ /test1"}
            }
        ],
        "conf.d\\include.location2.conf":
        [
            {
                "location": {"value": "^~ /test2"}
            }
        ]
    }
}

After:

{
    "main-config": "C:\\test\\test.conf",
    "configs":
    {
        "C:\\test\\test.conf":
        {
            "context-type": "config",
            "value": "C:\\test\\test.conf",
            "params":
            [
                {
                    "context-type": "http",
                    "params":
                    [
                        {
                            "context-type": "inline_comment", "value": "test comment"
                        },
                        {
                            "context-type": "server",
                            "params":
                            [
                                {
                                    "context-type": "directive", "value": "server_name testserver"
                                },
                                {
                                    "context-type": "location", "value": "~ /test"
                                },
                                {
                                    "context-type": "include",
                                    "value": "conf.d\\include*conf",
                                    "params": ["conf.d\\include.location1.conf", "conf.d\\include.location2.conf"]
                                }
                            ]
                        }
                    ]
                }
            ]
        },
        "conf.d\\include.location1.conf":
        {
            "context-type": "config",
            "value": "conf.d\\include.location1.conf",
            "params":
            [
                {
                    "context-type": "location", "value": "~ /test1"
                }
            ]
        },
        "conf.d\\include.location2.conf":
        {
            "context-type": "config",
            "value": "conf.d\\include.location2.conf",
            "params":
            [
                {
                    "context-type": "location", "value": "^~ /test2"
                }
            ]
        }
    }
}

The code migration example for creating function calls for Directive and Comment context objects is as follows:

Before:

import (
	"github.com/ClessLi/bifrost/pkg/resolv/V3/nginx/configuration/context/local"
)

// new directive context
newDirective := local.NewDirective("some_directive", "some params")
// new comment context
newComment := local.NewComment("some comments", false)
newComment := local.NewComment("some inline comments", true)

After:

import (
	"github.com/ClessLi/bifrost/pkg/resolv/V3/nginx/configuration/context/local"
	"github.com/ClessLi/bifrost/pkg/resolv/V3/nginx/configuration/context_type"
)

// new directive context
newDirective := local.NewContext(context_type.TypeDirective, "some_directive some params")
// new comment context
newComment := local.NewContext(context_type.TypeComment, "some comments")
newInlineComment := local.NewContext(context_type.TypeInlineComment, "some inline comments")

v1.0.11

01 Apr 09:54
Compare
Choose a tag to compare

v1.0.11 - 2024-04-01

Other Changes

  • fix to skip contaminated version numbers on pkg.go.dev.

BREAKING CHANGE

disable contaminated product package versions v1.0.9 and v1.0.10 on pkg.go.dev.

Code migration requires changing the version of the bifrost package from v1.0.9 or v1.0.10 to v1.0.11, as shown in the following example:

go.mod:

require (
	github.com/ClessLi/bifrost v1.0.11
)

v1.0.9

01 Apr 02:02
Compare
Choose a tag to compare

v1.0.9 - 2024-04-01

Bug Fixes

  • fix 1 Dependabot alert.
  • resolv: fix string containing matching logic in the KeyWords.Match() method.

Features

  • resolv: interface the Main Context.
  • resolv: preliminary completion of the development and testing of the resolve V3 version, as well as the update of the bifrost service to the resolve V3 version.
  • resolv: complete the writing of the KeyWords class and conduct preliminary unit testing of related methods for this class
  • resolv: preliminary completion of V3 local library unit testing and repair.
  • resolv: complete functional unit testing of V3 local.Include Context.
  • resolv: add V3 resolv lib.
  • resolv: add V3 resolv lib.

BREAKING CHANGE

replacing the nginx configuration resolving library from version V2 to V3.

To migrate the code follow the example below:

Before:

import (
	"github.com/ClessLi/bifrost/pkg/resolv/V2/nginx/configuration"
)

nginxConfFromPath, err := configuration.NewConfigurationFromPath(configAbsPath)
nginxConfFromJsonBytes, err := configuration.NewConfigurationFromJsonBytes(configJsonBytes)

After:

import (
	"github.com/ClessLi/bifrost/pkg/resolv/V3/nginx/configuration"
)

nginxConfFromPath, err := configuration.NewNginxConfigFromFS(configAbsPath)
nginxConfFromJsonBytes, err := configuration.NewNginxConfigFromJsonBytes(configJsonBytes)

Example for querying and inserting context:

import (
	"fmt"

	"github.com/ClessLi/bifrost/pkg/resolv/V3/nginx/configuration"
	"github.com/ClessLi/bifrost/pkg/resolv/V3/nginx/configuration/context"
	"github.com/ClessLi/bifrost/pkg/resolv/V3/nginx/configuration/context/local"
)

conf, err := configuration.NewNginxConfigFromJsonBytes(jsondata)
if err != nil {
	t.Fatal(err)
}
for _, pos := range conf.Main().QueryByKeyWords(context.NewKeyWords(context_type.TypeHttp)).Target().
	QueryByKeyWords(context.NewKeyWords(context_type.TypeServer)).Target().
	QueryAllByKeyWords(context.NewKeyWords(context_type.TypeDirective).SetStringMatchingValue("server_name test1.com")) {  // query `server` context, its server name is "test1.com"
	server, _ := pos.Position()
	if server.QueryByKeyWords(context.NewKeyWords(context_type.TypeDirective).SetRegexpMatchingValue("^listen 80$")).Target().Error() != nil// query `server` context, its listen port is 80
		continue
	}
	// query the "proxy_pass" `directive` context, which is in `if` context(value: "($http_api_name != '')") and `location` context(value: "/test1-location")
	ctx, idx := server.QueryByKeyWords(context.NewKeyWords(context_type.TypeLocation).SetRegexpMatchingValue(`^/test1-location$`)).Target().
		QueryByKeyWords(context.NewKeyWords(context_type.TypeIf).SetRegexpMatchingValue(`^\(\$http_api_name != ''\)$`)).Target().
		QueryByKeyWords(context.NewKeyWords(context_type.TypeDirective).SetStringMatchingValue("proxy_pass")).Position()
	// insert an inline comment after the "proxy_pass" `directive` context
	err = ctx.Insert(local.NewComment(fmt.Sprintf("[%s]test comments", time.Now().String()), true), idx+1).Error()
	if err != nil {
		return err
	}
}

Examples for building nginx context object:

import (
	"github.com/ClessLi/bifrost/pkg/resolv/V3/nginx/configuration/context/local"
	"github.com/ClessLi/bifrost/pkg/resolv/V3/nginx/configuration/context_type"
)

// new main context
newMainContext, err := local.NewMain("/usr/local/nginx/conf/nginx.conf")
// new directive context
newDirective := local.NewDirective("some_directive", "some params")
// new comment context
newComment := local.NewComment("some comments", false)
// new other context
newConfig := local.NewContext(context_type.TypeConfig, "conf.d/location.conf")
newInclude := local.NewContext(context_type.TypeInclude, "conf.d/*.conf")
newHttp := local.NewContext(context_type.TypeHttp, "")
...

v1.0.8

06 Jun 06:57
Compare
Choose a tag to compare

v1.0.8 - 2022-06-06

Bug Fixes

  • fix Go-Yaml vulnerability, CVE ID: CVE-2022-28948