1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
|
%global _empty_manifest_terminate_build 0
Name: python-harmony-service-lib
Version: 1.0.22
Release: 1
Summary: A library for Python-based Harmony services to parse incoming messages, fetch data, stage data, and call back to Harmony
License: License :: OSI Approved :: Apache Software License
URL: https://github.com/nasa/harmony-service-lib-py
Source0: https://mirrors.aliyun.com/pypi/web/packages/c4/99/eddb3900cab82c71feda725393477b6627282e49093a703dcf31dcf9db58/harmony-service-lib-1.0.22.tar.gz
BuildArch: noarch
Requires: python3-boto3
Requires: python3-deprecation
Requires: python3-pynacl
Requires: python3-pystac
Requires: python3-json-logger
Requires: python3-requests
Requires: python3-urllib3
%description
# harmony-service-lib
A library for Python-based Harmony services to parse incoming messages, fetch data, stage data, and call back to Harmony
## Installing
### Using pip
Install the latest version of the package from PyPI using pip:
$ pip install harmony-service-lib
### Other methods:
The package is installable from source via
$ pip install git+https://github.com/harmony/harmony-service-lib-py.git#egg=harmony-service-lib
If using a local source tree, run the following in the source root directory instead:
$ pip install -e .
## Usage
Services that want to work with Harmony can make use of this library to ease
interop and upgrades. To work with Harmony, services must:
1. Receive incoming messages from Harmony. Currently the CLI is the only
supported way to receive messages, though HTTP is likely to follow. `harmony.cli`
provides helpers for setting up CLI parsing while being unobtrusive to non-Harmony
CLIs that may also need to exist.
2. Extend `harmony.BaseHarmonyAdapter` and implement the `#invoke` to
adapt the incoming Harmony message to a service call and adapt the service
result to call to one of the adapter's `#completed_with_*` methods. The adapter
class provides helper methods for retrieving data, staging results, and cleaning
up temporary files, though these can be overridden or ignored if a service
needs different behavior, e.g. if it operates on data in situ and does not
want to download the remote file.
A full example of these two requirements with use of helpers can be found in
[example/example_service.py](example/example_service.py)
## Environment
The following environment variables can be used to control the behavior of the
library and allow easier testing:
REQUIRED:
* `STAGING_BUCKET`: When using helpers to stage service output and pre-sign URLs, this
indicates the S3 bucket where data will be staged
* `STAGING_PATH`: When using helpers to stage output, this indicates the path within
`STAGING_BUCKET` under which data will be staged
* `ENV`: The name of the environment. If 'dev' or 'test', callbacks to Harmony are
not made and data is not staged unless also using localstack
* `OAUTH_UID`, `OAUTH_PASSWORD`: Used to acquire a shared EDL token
needed for downloading granules from EDL token-aware data
sources. Services using data in S3 do not need to set this.
NOTE: If `FALLBACK_AUTHN_ENABLED` is set to True (CAUTION!)
these credentials will be used to download data *as* the EDL
application user. This may cause problems with metrics and can
result in users getting data for which they've not approved a
EULA.
* `OAUTH_CLIENT_ID`: The Earthdata application client ID.
* `OAUTH_HOST`: Set to the correct Earthdata Login URL, depending on
where the service is being deployed. This should be the same
environment where the `OAUTH_*` credentials are valid. Defaults
to UAT.
* `OAUTH_REDIRECT_URI`: A valid redirect URI for the EDL application.
* `SHARED_SECRET_KEY`: The 32-byte encryption key shared between Harmony and backend services.
This is used to encrypt & decrypt the `accessToken` in the Harmony operation message.
In a production environment, this should be injected into the container running the service
Docker image. When running the service within Harmony, the Harmony infrastructure will
ensure that this environment variable is set with the shared secret key, and the Harmony
service library will read and use this key. Therefore, the service developer need not
be aware of this variable or its value.
OPTIONAL:
* `APP_NAME`: Defaults to first argument on commandline. Appears in log records.
* `AWS_DEFAULT_REGION`: (Default: `"us-west-2"`) The region in which S3 calls will be made
* `USE_LOCALSTACK`: (Development) If 'true' will perform S3 calls against localstack rather
than AWS
* `LOCALSTACK_HOST`: (Development) If `USE_LOCALSTACK` `true` and this is set, will
establish `boto` client connections for S3 & SQS operations using this hostname.
* `TEXT_LOGGER`: (Default: True) Setting this to true will cause all
log messages to use a text string format. By default log
messages will be formatted as JSON.
* `HEALTH_CHECK_PATH`: Set this to the path where the health check file should be stored. This
file's mtime is set to the current time whenever a successful attempt is made to to read the
message queue (whether or not a message is retrieved). This file can be used by a container's
health check command. The container is considered unhealthy if the mtime of the file is old -
where 'old' is configurable in the service container. If this variable is not set the path
defaults to '/tmp/health.txt'.
* `MAX_DOWNLOAD_RETRIES`: Number of times to retry HTTP download calls that fail due to transient errors.
OPTIONAL -- Use with CAUTION:
* `FALLBACK_AUTHN_ENABLED`: Default: False. Enable the fallback authentication that
uses the EDL application credentials. See CAUTION note above.
* `EDL_USERNAME`: The Earthdata Login username used for fallback authn.
* `EDL_PASSWORD`: The Earthdata Login password used for fallback authn.
## Development Setup
Prerequisites:
- Python 3.7+, ideally installed via a virtual environment
- A local copy of the code
Install dependencies:
$ make install
Run linter against production code:
$ make lint
Run tests:
$ make test
Build & publish the package:
$ make publish
## Releasing
GitHub release notes will automatically be generated based on pull request subjects.
Pull request subject lines should therefore concisely emphasize library
user-facing behavior and updates they should appear in the changelog. If more
information is needed for release notes, note that in the PR content.
%package -n python3-harmony-service-lib
Summary: A library for Python-based Harmony services to parse incoming messages, fetch data, stage data, and call back to Harmony
Provides: python-harmony-service-lib
BuildRequires: python3-devel
BuildRequires: python3-setuptools
BuildRequires: python3-pip
%description -n python3-harmony-service-lib
# harmony-service-lib
A library for Python-based Harmony services to parse incoming messages, fetch data, stage data, and call back to Harmony
## Installing
### Using pip
Install the latest version of the package from PyPI using pip:
$ pip install harmony-service-lib
### Other methods:
The package is installable from source via
$ pip install git+https://github.com/harmony/harmony-service-lib-py.git#egg=harmony-service-lib
If using a local source tree, run the following in the source root directory instead:
$ pip install -e .
## Usage
Services that want to work with Harmony can make use of this library to ease
interop and upgrades. To work with Harmony, services must:
1. Receive incoming messages from Harmony. Currently the CLI is the only
supported way to receive messages, though HTTP is likely to follow. `harmony.cli`
provides helpers for setting up CLI parsing while being unobtrusive to non-Harmony
CLIs that may also need to exist.
2. Extend `harmony.BaseHarmonyAdapter` and implement the `#invoke` to
adapt the incoming Harmony message to a service call and adapt the service
result to call to one of the adapter's `#completed_with_*` methods. The adapter
class provides helper methods for retrieving data, staging results, and cleaning
up temporary files, though these can be overridden or ignored if a service
needs different behavior, e.g. if it operates on data in situ and does not
want to download the remote file.
A full example of these two requirements with use of helpers can be found in
[example/example_service.py](example/example_service.py)
## Environment
The following environment variables can be used to control the behavior of the
library and allow easier testing:
REQUIRED:
* `STAGING_BUCKET`: When using helpers to stage service output and pre-sign URLs, this
indicates the S3 bucket where data will be staged
* `STAGING_PATH`: When using helpers to stage output, this indicates the path within
`STAGING_BUCKET` under which data will be staged
* `ENV`: The name of the environment. If 'dev' or 'test', callbacks to Harmony are
not made and data is not staged unless also using localstack
* `OAUTH_UID`, `OAUTH_PASSWORD`: Used to acquire a shared EDL token
needed for downloading granules from EDL token-aware data
sources. Services using data in S3 do not need to set this.
NOTE: If `FALLBACK_AUTHN_ENABLED` is set to True (CAUTION!)
these credentials will be used to download data *as* the EDL
application user. This may cause problems with metrics and can
result in users getting data for which they've not approved a
EULA.
* `OAUTH_CLIENT_ID`: The Earthdata application client ID.
* `OAUTH_HOST`: Set to the correct Earthdata Login URL, depending on
where the service is being deployed. This should be the same
environment where the `OAUTH_*` credentials are valid. Defaults
to UAT.
* `OAUTH_REDIRECT_URI`: A valid redirect URI for the EDL application.
* `SHARED_SECRET_KEY`: The 32-byte encryption key shared between Harmony and backend services.
This is used to encrypt & decrypt the `accessToken` in the Harmony operation message.
In a production environment, this should be injected into the container running the service
Docker image. When running the service within Harmony, the Harmony infrastructure will
ensure that this environment variable is set with the shared secret key, and the Harmony
service library will read and use this key. Therefore, the service developer need not
be aware of this variable or its value.
OPTIONAL:
* `APP_NAME`: Defaults to first argument on commandline. Appears in log records.
* `AWS_DEFAULT_REGION`: (Default: `"us-west-2"`) The region in which S3 calls will be made
* `USE_LOCALSTACK`: (Development) If 'true' will perform S3 calls against localstack rather
than AWS
* `LOCALSTACK_HOST`: (Development) If `USE_LOCALSTACK` `true` and this is set, will
establish `boto` client connections for S3 & SQS operations using this hostname.
* `TEXT_LOGGER`: (Default: True) Setting this to true will cause all
log messages to use a text string format. By default log
messages will be formatted as JSON.
* `HEALTH_CHECK_PATH`: Set this to the path where the health check file should be stored. This
file's mtime is set to the current time whenever a successful attempt is made to to read the
message queue (whether or not a message is retrieved). This file can be used by a container's
health check command. The container is considered unhealthy if the mtime of the file is old -
where 'old' is configurable in the service container. If this variable is not set the path
defaults to '/tmp/health.txt'.
* `MAX_DOWNLOAD_RETRIES`: Number of times to retry HTTP download calls that fail due to transient errors.
OPTIONAL -- Use with CAUTION:
* `FALLBACK_AUTHN_ENABLED`: Default: False. Enable the fallback authentication that
uses the EDL application credentials. See CAUTION note above.
* `EDL_USERNAME`: The Earthdata Login username used for fallback authn.
* `EDL_PASSWORD`: The Earthdata Login password used for fallback authn.
## Development Setup
Prerequisites:
- Python 3.7+, ideally installed via a virtual environment
- A local copy of the code
Install dependencies:
$ make install
Run linter against production code:
$ make lint
Run tests:
$ make test
Build & publish the package:
$ make publish
## Releasing
GitHub release notes will automatically be generated based on pull request subjects.
Pull request subject lines should therefore concisely emphasize library
user-facing behavior and updates they should appear in the changelog. If more
information is needed for release notes, note that in the PR content.
%package help
Summary: Development documents and examples for harmony-service-lib
Provides: python3-harmony-service-lib-doc
%description help
# harmony-service-lib
A library for Python-based Harmony services to parse incoming messages, fetch data, stage data, and call back to Harmony
## Installing
### Using pip
Install the latest version of the package from PyPI using pip:
$ pip install harmony-service-lib
### Other methods:
The package is installable from source via
$ pip install git+https://github.com/harmony/harmony-service-lib-py.git#egg=harmony-service-lib
If using a local source tree, run the following in the source root directory instead:
$ pip install -e .
## Usage
Services that want to work with Harmony can make use of this library to ease
interop and upgrades. To work with Harmony, services must:
1. Receive incoming messages from Harmony. Currently the CLI is the only
supported way to receive messages, though HTTP is likely to follow. `harmony.cli`
provides helpers for setting up CLI parsing while being unobtrusive to non-Harmony
CLIs that may also need to exist.
2. Extend `harmony.BaseHarmonyAdapter` and implement the `#invoke` to
adapt the incoming Harmony message to a service call and adapt the service
result to call to one of the adapter's `#completed_with_*` methods. The adapter
class provides helper methods for retrieving data, staging results, and cleaning
up temporary files, though these can be overridden or ignored if a service
needs different behavior, e.g. if it operates on data in situ and does not
want to download the remote file.
A full example of these two requirements with use of helpers can be found in
[example/example_service.py](example/example_service.py)
## Environment
The following environment variables can be used to control the behavior of the
library and allow easier testing:
REQUIRED:
* `STAGING_BUCKET`: When using helpers to stage service output and pre-sign URLs, this
indicates the S3 bucket where data will be staged
* `STAGING_PATH`: When using helpers to stage output, this indicates the path within
`STAGING_BUCKET` under which data will be staged
* `ENV`: The name of the environment. If 'dev' or 'test', callbacks to Harmony are
not made and data is not staged unless also using localstack
* `OAUTH_UID`, `OAUTH_PASSWORD`: Used to acquire a shared EDL token
needed for downloading granules from EDL token-aware data
sources. Services using data in S3 do not need to set this.
NOTE: If `FALLBACK_AUTHN_ENABLED` is set to True (CAUTION!)
these credentials will be used to download data *as* the EDL
application user. This may cause problems with metrics and can
result in users getting data for which they've not approved a
EULA.
* `OAUTH_CLIENT_ID`: The Earthdata application client ID.
* `OAUTH_HOST`: Set to the correct Earthdata Login URL, depending on
where the service is being deployed. This should be the same
environment where the `OAUTH_*` credentials are valid. Defaults
to UAT.
* `OAUTH_REDIRECT_URI`: A valid redirect URI for the EDL application.
* `SHARED_SECRET_KEY`: The 32-byte encryption key shared between Harmony and backend services.
This is used to encrypt & decrypt the `accessToken` in the Harmony operation message.
In a production environment, this should be injected into the container running the service
Docker image. When running the service within Harmony, the Harmony infrastructure will
ensure that this environment variable is set with the shared secret key, and the Harmony
service library will read and use this key. Therefore, the service developer need not
be aware of this variable or its value.
OPTIONAL:
* `APP_NAME`: Defaults to first argument on commandline. Appears in log records.
* `AWS_DEFAULT_REGION`: (Default: `"us-west-2"`) The region in which S3 calls will be made
* `USE_LOCALSTACK`: (Development) If 'true' will perform S3 calls against localstack rather
than AWS
* `LOCALSTACK_HOST`: (Development) If `USE_LOCALSTACK` `true` and this is set, will
establish `boto` client connections for S3 & SQS operations using this hostname.
* `TEXT_LOGGER`: (Default: True) Setting this to true will cause all
log messages to use a text string format. By default log
messages will be formatted as JSON.
* `HEALTH_CHECK_PATH`: Set this to the path where the health check file should be stored. This
file's mtime is set to the current time whenever a successful attempt is made to to read the
message queue (whether or not a message is retrieved). This file can be used by a container's
health check command. The container is considered unhealthy if the mtime of the file is old -
where 'old' is configurable in the service container. If this variable is not set the path
defaults to '/tmp/health.txt'.
* `MAX_DOWNLOAD_RETRIES`: Number of times to retry HTTP download calls that fail due to transient errors.
OPTIONAL -- Use with CAUTION:
* `FALLBACK_AUTHN_ENABLED`: Default: False. Enable the fallback authentication that
uses the EDL application credentials. See CAUTION note above.
* `EDL_USERNAME`: The Earthdata Login username used for fallback authn.
* `EDL_PASSWORD`: The Earthdata Login password used for fallback authn.
## Development Setup
Prerequisites:
- Python 3.7+, ideally installed via a virtual environment
- A local copy of the code
Install dependencies:
$ make install
Run linter against production code:
$ make lint
Run tests:
$ make test
Build & publish the package:
$ make publish
## Releasing
GitHub release notes will automatically be generated based on pull request subjects.
Pull request subject lines should therefore concisely emphasize library
user-facing behavior and updates they should appear in the changelog. If more
information is needed for release notes, note that in the PR content.
%prep
%autosetup -n harmony-service-lib-1.0.22
%build
%py3_build
%install
%py3_install
install -d -m755 %{buildroot}/%{_pkgdocdir}
if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
pushd %{buildroot}
if [ -d usr/lib ]; then
find usr/lib -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
if [ -d usr/lib64 ]; then
find usr/lib64 -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
if [ -d usr/bin ]; then
find usr/bin -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
if [ -d usr/sbin ]; then
find usr/sbin -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
touch doclist.lst
if [ -d usr/share/man ]; then
find usr/share/man -type f -printf "\"/%h/%f.gz\"\n" >> doclist.lst
fi
popd
mv %{buildroot}/filelist.lst .
mv %{buildroot}/doclist.lst .
%files -n python3-harmony-service-lib -f filelist.lst
%dir %{python3_sitelib}/*
%files help -f doclist.lst
%{_docdir}/*
%changelog
* Tue Jun 20 2023 Python_Bot <Python_Bot@openeuler.org> - 1.0.22-1
- Package Spec generated
|