Skip to content

Commit

Permalink
cherry-pick: home: show version in install api
Browse files Browse the repository at this point in the history
Closes #4026.

Squashed commit of the following:

commit bcd1315
Author: Ainar Garipov <[email protected]>
Date:   Tue Jan 18 14:57:49 2022 +0300

    openapi: fix example

commit b56e27c
Author: Ildar Kamalov <[email protected]>
Date:   Tue Jan 18 14:55:51 2022 +0300

    client: show version on install page

commit 95dfbfa
Author: Ainar Garipov <[email protected]>
Date:   Tue Jan 18 14:29:08 2022 +0300

    home: show version in install api
  • Loading branch information
ainar-g committed Jan 21, 2022
1 parent f41332f commit 48480fb
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 33 deletions.
17 changes: 12 additions & 5 deletions client/src/components/ui/Version.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,25 @@ const Version = () => {
checkUpdateFlag,
} = useSelector((state) => state?.dashboard ?? {}, shallowEqual);

const {
dnsVersion: installDnsVersion,
} = useSelector((state) => state?.install ?? {}, shallowEqual);

const version = dnsVersion || installDnsVersion;

const onClick = () => {
dispatch(getVersion(true));
};

return (
<div className="version">
<div className="version__text">
{dnsVersion
&& <>
<Trans>version</Trans>:&nbsp;
<span className="version__value" title={dnsVersion}>{dnsVersion}</span>
</>}
{version && (
<>
<Trans>version</Trans>:&nbsp;
<span className="version__value" title={version}>{version}</span>
</>
)}
{checkUpdateFlag && <button
type="button"
className="btn btn-icon btn-icon-sm btn-outline-primary btn-sm ml-2"
Expand Down
11 changes: 9 additions & 2 deletions client/src/reducers/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,19 @@ const install = handleActions({
[actions.getDefaultAddressesRequest]: (state) => ({ ...state, processingDefault: true }),
[actions.getDefaultAddressesFailure]: (state) => ({ ...state, processingDefault: false }),
[actions.getDefaultAddressesSuccess]: (state, { payload }) => {
const { interfaces } = payload;
const { interfaces, version } = payload;
const web = { ...state.web, port: payload.web_port };
const dns = { ...state.dns, port: payload.dns_port };

const newState = {
...state, web, dns, interfaces, processingDefault: false,
...state,
web,
dns,
interfaces,
processingDefault: false,
dnsVersion: version,
};

return newState;
},

Expand Down Expand Up @@ -64,6 +70,7 @@ const install = handleActions({
error: '',
},
interfaces: {},
dnsVersion: '',
});

export default combineReducers({
Expand Down
33 changes: 23 additions & 10 deletions internal/home/controlinstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,31 @@ import (
"github.com/AdguardTeam/AdGuardHome/internal/aghalgo"
"github.com/AdguardTeam/AdGuardHome/internal/aghhttp"
"github.com/AdguardTeam/AdGuardHome/internal/aghnet"
"github.com/AdguardTeam/AdGuardHome/internal/version"
"github.com/AdguardTeam/golibs/errors"
"github.com/AdguardTeam/golibs/log"
)

// getAddrsResponse is the response for /install/get_addresses endpoint.
type getAddrsResponse struct {
Interfaces map[string]*aghnet.NetInterface `json:"interfaces"`
WebPort int `json:"web_port"`
DNSPort int `json:"dns_port"`

// Version is the version of AdGuard Home.
//
// TODO(a.garipov): In the new API, rename this endpoint to something more
// general, since there will be more information here than just network
// interfaces.
Version string `json:"version"`

WebPort int `json:"web_port"`
DNSPort int `json:"dns_port"`
}

// handleInstallGetAddresses is the handler for /install/get_addresses endpoint.
func (web *Web) handleInstallGetAddresses(w http.ResponseWriter, r *http.Request) {
data := getAddrsResponse{
Version: version.Version(),

WebPort: defaultPortHTTP,
DNSPort: defaultPortDNS,
}
Expand Down Expand Up @@ -279,10 +290,11 @@ type applyConfigReqEnt struct {
}

type applyConfigReq struct {
Web applyConfigReqEnt `json:"web"`
DNS applyConfigReqEnt `json:"dns"`
Username string `json:"username"`
Password string `json:"password"`
Username string `json:"username"`
Password string `json:"password"`

Web applyConfigReqEnt `json:"web"`
DNS applyConfigReqEnt `json:"dns"`
}

// copyInstallSettings copies the installation parameters between two
Expand Down Expand Up @@ -533,10 +545,11 @@ type applyConfigReqEntBeta struct {
// TODO(e.burkov): This should removed with the API v1 when the appropriate
// functionality will appear in default applyConfigReq.
type applyConfigReqBeta struct {
Web applyConfigReqEntBeta `json:"web"`
DNS applyConfigReqEntBeta `json:"dns"`
Username string `json:"username"`
Password string `json:"password"`
Username string `json:"username"`
Password string `json:"password"`

Web applyConfigReqEntBeta `json:"web"`
DNS applyConfigReqEntBeta `json:"dns"`
}

// handleInstallConfigureBeta is a substitution of /install/configure handler
Expand Down
13 changes: 3 additions & 10 deletions internal/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,10 @@ func Version() (v string) {
return version
}

// Common formatting constants.
const (
sp = " "
nl = "\n"
tb = "\t"
nltb = nl + tb
)

// Constants defining the format of module information string.
const (
modInfoAtSep = "@"
modInfoDevSep = sp
modInfoDevSep = " "
modInfoSumLeft = " (sum: "
modInfoSumRight = ")"
)
Expand Down Expand Up @@ -142,6 +134,7 @@ const (
func Verbose() (v string) {
b := &strings.Builder{}

const nl = "\n"
stringutil.WriteToBuilder(
b,
vFmtAGHHdr,
Expand Down Expand Up @@ -178,7 +171,7 @@ func Verbose() (v string) {
stringutil.WriteToBuilder(b, nl, vFmtDepsHdr)
for _, dep := range info.Deps {
if depStr := fmtModule(dep); depStr != "" {
stringutil.WriteToBuilder(b, nltb, depStr)
stringutil.WriteToBuilder(b, "\n\t", depStr)
}
}

Expand Down
11 changes: 9 additions & 2 deletions openapi/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@

<!-- TODO(a.garipov): Reformat in accordance with the KeepAChangelog spec. -->

## v0.107: API changes
## v0.107.3: API changes

## The new field `"cached"` in `QueryLogItem`
### The new field `"version"` in `AddressesInfo`

* The new field `"version"` in `GET /install/get_addresses` is the version of
the AdGuard Home instance.

## v0.107.0: API changes

### The new field `"cached"` in `QueryLogItem`

* The new field `"cached"` in `GET /control/querylog` is true if the response is
served from cache instead of being resolved by an upstream server.
Expand Down
12 changes: 8 additions & 4 deletions openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1264,7 +1264,7 @@
'type': 'boolean'
'version':
'type': 'string'
'example': '0.1'
'example': 'v0.123.4'
'language':
'type': 'string'
'example': 'en'
Expand Down Expand Up @@ -2221,19 +2221,23 @@
'description': 'AdGuard Home addresses configuration'
'required':
- 'dns_port'
- 'web_port'
- 'interfaces'
- 'version'
- 'web_port'
'properties':
'dns_port':
'type': 'integer'
'format': 'uint16'
'example': 53
'interfaces':
'$ref': '#/components/schemas/NetInterfaces'
'version':
'type': 'string'
'example': 'v0.123.4'
'web_port':
'type': 'integer'
'format': 'uint16'
'example': 80
'interfaces':
'$ref': '#/components/schemas/NetInterfaces'
'AddressesInfoBeta':
'type': 'object'
'description': 'AdGuard Home addresses configuration'
Expand Down

0 comments on commit 48480fb

Please sign in to comment.