Skip to content

Commit

Permalink
Implement source cmds part 2 (#456)
Browse files Browse the repository at this point in the history
Co-authored-by: Natalie Gaston <[email protected]>
Co-authored-by: Sirlapu, Tejaswini <[email protected]>
  • Loading branch information
3 people authored Jan 5, 2024
1 parent cc275f4 commit 32a158f
Show file tree
Hide file tree
Showing 52 changed files with 1,435 additions and 826 deletions.
345 changes: 314 additions & 31 deletions docs/Manifest Parameters.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion autopep8.sh → format-python.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ set -euxo pipefail

for dir in inbc-program inbm inbm-lib ; do
( cd "$dir"
./autopep8.sh
./format-python.sh
)
done
2 changes: 2 additions & 0 deletions inbc-program/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
coverage.xml
*.cover
**/cover/
inbm_lib
inbm_common_lib
158 changes: 156 additions & 2 deletions inbc-program/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
1. [Introduction](#introduction)
2. [Prerequisites](#prerequisites)
3. [Notes](#-notes)
4. [MQTT Communication](#mqtt-communication)
4. [MQTT Communication](#mqtt-communication-)
1. [Publish Channels](#publish-channels)
2. [Subscribe Channels](#subscribe-channels)
5. [Commands](#commands)
Expand All @@ -19,6 +19,14 @@
7. [Configuration Set](#set)
8. [Restart](#restart)
9. [Query](#query)
10. [Source Application Add](#source-application-add)
11. [Source Application Remove](#source-application-remove)
12. [Source Application Update](#source-application-update)
13. [Source Application List](#source-application-list)
14. [Source OS Add](#source-os-add)
15. [Source OS Remove](#source-os-remove)
16. [Source OS Update](#source-os-update)
15. [Source OS List](#source-os-list)
6. [Status Codes](#status-codes)
7. [Return and Exit Codes](#return-and-exit-codes)

Expand Down Expand Up @@ -352,7 +360,7 @@ Remove is only applicable to two config tags, which are trustedRepositories and

### Usage
```
inbc remove
inbc remove
{--path, -p KEY_PATH;...}
```

Expand Down Expand Up @@ -404,6 +412,152 @@ inbc query --option hw
inbc query --option sw
```

## SOURCE APPLICATION ADD
### Description
Downloads and encrypts GPG key and stores it on the system under <em>/usr/share/keyrings</em>. Creates a file under <em>/etc/apt/sources.list.d</em> to store the update source information.
This list file is used during 'sudo apt update' to update the application

### Usage
```
inbc source application add
{--gpgKeyUri, -gku=GPG_KEY_URI}
{--gpgKeyName, -gkn=GPG_KEY_NAME}
{--sources, -s=SOURCES}
{--filename, -f=FILENAME}
```

### Example
#### Add an application source
```
inbc source application add
--gpgKeyUri https://dl-ssl.google.com/linux/linux_signing_key.pub
--gpgKeyName google-chrome.gpg
--sources "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main"
--filename google-chrome.list
```

## SOURCE APPLICATION REMOVE
### Description
Removes the GPG key file from under <em>/usr/share/keyrings</em>. Removes the source file from under /etc/apt/sources.list.d/.

### Usage
```
inbc source application remove
{--gpgKeyName, -gkn=GPG_KEY_NAME}
{--filename, -f=FILE_NAME}
```

### Example
#### Remove an application source
```commandline
inbc source application remove
--gpgKeyName google-chrome.gpg
--filename google-chrome.list
```

## SOURCE APPLICATION UPDATE
### Description
Updates Application sources that are used to update the system
NOTE: Currently this only works on Ubuntu

### Usage
```
inbc source application update
{--filename, -f=FILEPATH}
{--sources, -s=SOURCES}
```

### Examples
#### Update an application source file
```
inbc source application update
--filename google-chrome.list
--sources "deb [arch=amd64] https://dl.google.com/linux/chrome/deb/ stable test" "debsrc [arch=amd64] https://dl.google.com/linux/chrome/deb/ stable test2"
```

## SOURCE APPLICATION LIST
### Description
Lists Application sources
NOTE: Currently this only works on Ubuntu

### Usage
```
inbc source application list
```

### Examples
#### Lists all application source files
```
inbc source application list
```

## SOURCE OS ADD
### Description
Appends new source(s) to the <em>/etc/apt/sources.list</em> file

### Usage
```
inbc source os add
{--sources, -s=SOURCES}
```

### Example
#### Adds two sources
```
inbc source os add
--sources="deb http://archive.ubuntu.com/ubuntu/ jammy-security main restricted" "deb http://archive.ubuntu.com/ubuntu/ jammy-security universe"
```

## SOURCE OS REMOVE
### Description
Removes the provided source(s) from the <em>/etc/apt/sources.list</em> file, if they are present.

### Usage
```
inbc source os remove
{--sources, -s=SOURCES}
```

### Example
#### Removes the two provided source(s) from the <em>/etc/apt/sources.list</em> file
```
inbc source os remove
--sources="deb http://archive.ubuntu.com/ubuntu/ jammy-security main restricted" "deb http://archive.ubuntu.com/ubuntu/ jammy-security universe"
```

## SOURCE OS UPDATE
### Description
Creates a new <em>/etc/apt/sources.list</em> file with only the sources provided

### Usage
```
inbc source os update
{--sources, -s=SOURCES}
```

### Example
#### Creates a new <em>/etc/apt/sources.list</em> file with only the two provided sources
```
inbc source os update
--sources="deb http://archive.ubuntu.com/ubuntu/ jammy-security main restricted" "deb http://archive.ubuntu.com/ubuntu/ jammy-security universe"
```

## SOURCE OS LIST
### Description
Lists OS sources
NOTE: Currently this only works on Ubuntu

### Usage
```commandline
inbc source os list
```

### Examples
#### Lists all OS source files
```
inbc source os list
```

# Status Codes

| Message | Description | Result |
Expand Down
File renamed without changes.
23 changes: 14 additions & 9 deletions inbc-program/inbc/broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,20 @@ def __init__(self, cmd_type: str, parsed_args: Any, tls: bool = True) -> None:
except ValueError:
mqtt_port = DEFAULT_MQTT_PORT

self.mqttc = MQTT(PROG,
MQTT_HOST,
mqtt_port,
MQTT_KEEPALIVE_INTERVAL,
ca_certs=CA_CERTS,
env_config=True,
tls=tls,
client_certs=CLIENT_CERTS,
client_keys=CLIENT_KEYS)
try:
self.mqttc = MQTT(PROG,
MQTT_HOST,
mqtt_port,
MQTT_KEEPALIVE_INTERVAL,
ca_certs=CA_CERTS,
env_config=True,
tls=tls,
client_certs=CLIENT_CERTS,
client_keys=CLIENT_KEYS)
except AttributeError as e:
logger.exception("MQTT error: Check that MQTT Service is running")
raise

self.mqttc.start()
self._subscribe()
self._command = create_command_factory(cmd_type, self)
Expand Down
7 changes: 3 additions & 4 deletions inbc-program/inbc/command/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"""

import logging
import time
from typing import Any, Optional
from abc import ABC, abstractmethod
from inbc import shared
Expand Down Expand Up @@ -48,7 +47,7 @@ def stop_timer(self) -> None:
def invoke_update(self, args: Any) -> None:
"""Trigger the command-line utility tool to invoke update.
Sub-classes will override this method to provide specific implementations.
Subclasses will override this method to provide specific implementations.
@param args: arguments passed to command-line tool.
"""
Expand All @@ -58,7 +57,7 @@ def _send_manifest(self, args: Any, topic: str) -> None:
"""Send a manifest.
This is a default concrete implementation that takes in a topic. It is intended
to be called from a sub-class.
to be called from a subclass.
@param args: arguments passed to command-line tool.
@param topic: topic on which to send the manifest
Expand All @@ -74,7 +73,7 @@ def search_response(self, payload: Any) -> None:
@param payload: payload received in which to search
"""
if self._cmd_type != "query":
if search_keyword(payload, ["SUCCESSFUL"]):
if search_keyword(payload, ["SUCCESSFUL", '"status": 200']):
self.terminate_operation(COMMAND_SUCCESS, InbcCode.SUCCESS.value)
else:
self.terminate_operation(COMMAND_FAIL, InbcCode.FAIL.value)
Expand Down
3 changes: 1 addition & 2 deletions inbc-program/inbc/command/source_command.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Source Command classes to represent command entered by user.
# Copyright (C) 2020-2023 Intel Corporation
# Copyright (C) 2020-2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
"""
from typing import Any
Expand Down Expand Up @@ -33,7 +33,6 @@ def search_response(self, payload: Any) -> None:
@param payload: payload received in which to search
"""
# TODO: Add responses to wait for
super().search_response(payload)

def search_event(self, payload: Any, topic: str) -> None:
Expand Down
34 changes: 17 additions & 17 deletions inbc-program/inbc/parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,46 +65,46 @@ def parse_source_args(self) -> None:

# Application Add Command
app_add_parser = app_subparsers.add_parser('add')
app_add_parser.add_argument('-gpgKeyPath', '--gkp', required=True,
app_add_parser.add_argument('--gpgKeyUri', '-gku', required=True,
type=lambda x: validate_string_less_than_n_characters(
x, 'str', 1500),
help='Path to GPG key')
app_add_parser.add_argument('-gpgKeyName', '--gkn', required=True,
help='Uri from which to download GPG key')
app_add_parser.add_argument('--gpgKeyName', '-gkn', required=True,
type=lambda x: validate_string_less_than_n_characters(
x, 'str', 200),
help='Name to store the GPG key information')
app_add_parser.add_argument('-source', '--s', required=True,
app_add_parser.add_argument('--sources', '-s', required=True, nargs="*", default=[],
type=lambda x: validate_string_less_than_n_characters(
x, 'str', 1000),
help='Source information to store in the file')
app_add_parser.add_argument('-fileName', '--f', required=True,
x, 'List[str]', 3500),
help='List of source information to store in the file')
app_add_parser.add_argument('--filename', '-f', required=True,
type=lambda x: validate_string_less_than_n_characters(
x, 'str', 200),
help='file name to use when storing the source information')
app_add_parser.set_defaults(func=application_add)

# Application Remove Command
app_remove_parser = app_subparsers.add_parser('remove')
app_remove_parser.add_argument('-gpgKeyId', '--gki', required=True,
app_remove_parser.add_argument('--gpgKeyName', '-gkn', required=True,
type=lambda x: validate_string_less_than_n_characters(
x, 'str', 50),
help='GPG Key ID of the source to remove.')
app_remove_parser.add_argument('-fileName', '--f', required=True,
help='GPG key name of the source to remove.')
app_remove_parser.add_argument('--filename', '-f', required=True,
type=lambda x: validate_string_less_than_n_characters(
x, 'str', 200),
help='file name to use when storing the source information')
app_remove_parser.set_defaults(func=application_remove)

# Application Update Command
app_update_parser = app_subparsers.add_parser('update')
app_update_parser.add_argument('-fileName', '--f', required=True,
app_update_parser.add_argument('--filename', '-f', required=True,
type=lambda x: validate_string_less_than_n_characters(
x, 'str', 200),
help='file name to use when storing the source information')
app_update_parser.add_argument('-source', '--s', required=True,
app_update_parser.add_argument('--sources', '-s', required=True, nargs="*", default=[],
type=lambda x: validate_string_less_than_n_characters(
x, 'str', 1000),
help='Source information to store in the file')
x, 'List[str]', 3500),
help='List of source information to store in the file')
app_update_parser.set_defaults(func=application_update)

# Application List Command
Expand All @@ -119,23 +119,23 @@ def parse_source_args(self) -> None:

# OS Add Command
os_add_parser = os_subparsers.add_parser('add')
os_add_parser.add_argument('-sources', '--s', required=True, nargs="*", default=[],
os_add_parser.add_argument('--sources', '-s', required=True, nargs="*", default=[],
type=lambda x: validate_string_less_than_n_characters(
x, 'List[str]', 3500),
help='List of source information to store in the file')
os_add_parser.set_defaults(func=os_add)

# OS Remove Command
os_remove_parser = os_subparsers.add_parser('remove')
os_remove_parser.add_argument('-sources', '--s', required=True, nargs="*", default=[],
os_remove_parser.add_argument('--sources', '-s', required=True, nargs="*", default=[],
type=lambda x: validate_string_less_than_n_characters(
x, 'List[str]', 3500),
help='Source information to remove from the file')
os_remove_parser.set_defaults(func=os_remove)

# OS Update Command
os_update_parser = os_subparsers.add_parser('update')
os_update_parser.add_argument('-sources', '--s', required=True, nargs="*", default=[],
os_update_parser.add_argument('--sources', '-s', required=True, nargs="*", default=[],
type=lambda x: validate_string_less_than_n_characters(
x, 'List[str]', 3500),
help='Source information to replace in the file')
Expand Down
Loading

0 comments on commit 32a158f

Please sign in to comment.