looker-sdk 0.1.7 → 0.1.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +22 -0
  3. data/lib/looker-sdk/client/dynamic.rb +5 -3
  4. data/lib/looker-sdk/client.rb +16 -7
  5. data/lib/looker-sdk/default.rb +1 -1
  6. data/lib/looker-sdk/error.rb +8 -2
  7. data/lib/looker-sdk/version.rb +1 -1
  8. data/lib/looker-sdk.rb +2 -1
  9. data/test/helper.rb +10 -4
  10. data/test/looker/swagger.json +42011 -1117
  11. data/test/looker/test_client.rb +19 -15
  12. data/test/looker/test_dynamic_client.rb +36 -34
  13. data/test/looker/test_dynamic_client_agent.rb +45 -12
  14. data/test/looker/test_inline_query.rb +97 -0
  15. metadata +14 -45
  16. data/.github/CODEOWNERS +0 -1
  17. data/.github/scripts/wait_for_looker.sh +0 -35
  18. data/.github/workflows/release-metrics.yml +0 -44
  19. data/.github/workflows/release.yml +0 -47
  20. data/.github/workflows/ruby-ci.yml +0 -140
  21. data/.gitignore +0 -60
  22. data/.ruby-gemset +0 -1
  23. data/Gemfile +0 -22
  24. data/Gemfile.lock +0 -73
  25. data/Makefile +0 -81
  26. data/Rakefile +0 -38
  27. data/examples/.netrc +0 -1
  28. data/examples/add_delete_users.rb +0 -118
  29. data/examples/change_credentials_email_address_for_users.rb +0 -47
  30. data/examples/convert_look_to_lookless_tile.rb +0 -71
  31. data/examples/create_credentials_email_for_users.rb +0 -43
  32. data/examples/delete_all_user_sessions.rb +0 -39
  33. data/examples/delete_credentials_google_for_users.rb +0 -43
  34. data/examples/errors.rb +0 -47
  35. data/examples/generate_password_reset_tokens_for_users.rb +0 -43
  36. data/examples/ldap_roles_test.rb +0 -74
  37. data/examples/me.rb +0 -27
  38. data/examples/refresh_user_notification_addresses.rb +0 -34
  39. data/examples/roles_and_users_with_permission.rb +0 -46
  40. data/examples/sdk_setup.rb +0 -45
  41. data/examples/streaming_downloads.rb +0 -44
  42. data/examples/users_with_credentials_email.rb +0 -30
  43. data/examples/users_with_credentials_embed.rb +0 -33
  44. data/examples/users_with_credentials_google.rb +0 -30
  45. data/examples/users_with_credentials_google_without_credentials_email.rb +0 -30
  46. data/looker-sdk.gemspec +0 -32
  47. data/shell/.gitignore +0 -41
  48. data/shell/.netrc +0 -3
  49. data/shell/Gemfile +0 -6
  50. data/shell/Gemfile.lock +0 -60
  51. data/shell/readme.md +0 -18
  52. data/shell/shell.rb +0 -62
  53. data/shell.nix +0 -38
  54. data/test/fixtures/.netrc.template +0 -1
@@ -1,44 +0,0 @@
1
- name: Send publish metrics to bigquery
2
- on:
3
- release:
4
- types: published
5
- jobs:
6
- publish:
7
- runs-on: ubuntu-latest
8
- steps:
9
- - name: Set up Cloud SDK
10
- uses: google-github-actions/setup-gcloud@v0.2.0
11
- with:
12
- project_id: ${{ secrets.GCP_PROJECT_ID }}
13
- service_account_key: ${{ secrets.GCP_BQ_METRICS_KEY }}
14
- export_default_credentials: true
15
-
16
- - name: Debug event json
17
- run: cat $GITHUB_EVENT_PATH
18
-
19
- - name: Check for release key
20
- run: echo "HAS_RELEASE_KEY=$(jq 'has("release")' $GITHUB_EVENT_PATH)" >> $GITHUB_ENV
21
-
22
- - name: Write release json
23
- if: ${{env.HAS_RELEASE_KEY== 'true'}}
24
- run: 'jq -c ''.release |
25
- {
26
- package_name: .name | split(" ")[0],
27
- name,
28
- tag_name,
29
- version: try(.tag_name | split("-v")[1]),
30
- html_url,
31
- target_commitish,
32
- created_at,
33
- published_at,
34
- draft,
35
- prerelease
36
- }'' $GITHUB_EVENT_PATH > releases.json'
37
-
38
- - name: Debug release json
39
- if: ${{env.HAS_RELEASE_KEY== 'true'}}
40
- run: cat releases.json
41
-
42
- - name: Send release.json to BQ
43
- if: ${{env.HAS_RELEASE_KEY== 'true'}}
44
- run: bq load --source_format=NEWLINE_DELIMITED_JSON metrics.releases releases.json
@@ -1,47 +0,0 @@
1
- # .github/workflows/release.yml
2
-
3
- name: release
4
-
5
- on:
6
- push:
7
- branches:
8
- - main
9
-
10
- jobs:
11
- release-please:
12
- runs-on: ubuntu-latest
13
- steps:
14
- - uses: GoogleCloudPlatform/release-please-action@v3
15
- id: release
16
- with:
17
- release-type: ruby
18
- package-name: looker-sdk
19
- bump-minor-pre-major: true
20
- bump-patch-for-minor-pre-major: true
21
- version-file: "lib/looker-sdk/version.rb"
22
- token: ${{ secrets.LOS_AUTO_BOT_RP_TOKEN }}
23
- # Checkout code if release was created
24
- - uses: actions/checkout@v2
25
- if: ${{ steps.release.outputs.release_created }}
26
- # Setup ruby if a release was created
27
- - uses: ruby/setup-ruby@v1
28
- with:
29
- ruby-version: 2.7.7
30
- if: ${{ steps.release.outputs.release_created }}
31
- # Bundle install
32
- - run: bundle install
33
- if: ${{ steps.release.outputs.release_created }}
34
- # Publish
35
- - name: publish gem
36
- run: |
37
- mkdir -p $HOME/.gem
38
- touch $HOME/.gem/credentials
39
- chmod 0600 $HOME/.gem/credentials
40
- printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
41
- gem build *.gemspec
42
- gem push *.gem
43
- env:
44
- # Make sure to update the secret name
45
- # if yours isn't named RUBYGEMS_AUTH_TOKEN
46
- GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
47
- if: ${{ steps.release.outputs.release_created }}
@@ -1,140 +0,0 @@
1
- name: Ruby-CI test matrix
2
-
3
- on:
4
- push:
5
- branches: [ main ]
6
- pull_request:
7
- branches: [ main ]
8
- workflow_dispatch:
9
- env:
10
- LOOKERSDK_BASE_URL: https://localhost:20000
11
- LOOKERSDK_VERIFY_SSL: false
12
- LOOKERSDK_API_VERSION: "4.0"
13
-
14
- jobs:
15
- setup:
16
- uses: looker-open-source/reusable-actions/.github/workflows/supported-versions.yml@main
17
-
18
- test:
19
- name: Ruby-CI ${{ matrix.ruby-version }}/${{ matrix.looker }}
20
- env:
21
- LOOKERSDK_CLIENT_ID: ${{ secrets.LOOKERSDK_CLIENT_ID }}
22
- LOOKERSDK_CLIENT_SECRET: ${{ secrets.LOOKERSDK_CLIENT_SECRET }}
23
- CI_REPORTS: results/Ruby-CI-ruby_${{ matrix.ruby-version }}_Looker_${{ matrix.looker }}
24
-
25
- needs: setup
26
- runs-on: ubuntu-latest
27
- strategy:
28
- matrix:
29
- ruby-version: [2.7.7]
30
- looker: ${{ fromJson(needs.setup.outputs.matrix_json) }}
31
- use_faraday_multipart: ['true', 'false']
32
-
33
- steps:
34
- - name: Cancel Previous Runs
35
- uses: styfle/cancel-workflow-action@0.11.0
36
- with:
37
- access_token: ${{ secrets.GITHUB_TOKEN }}
38
-
39
- - uses: actions/checkout@v3
40
-
41
- - name: Authenticate to Google Cloud
42
- uses: google-github-actions/auth@v1.0.0
43
- with:
44
- credentials_json: ${{ secrets.GCP_AR_READER_SA_KEY }}
45
- project_id: ${{ secrets.GCP_PROJECT_ID }}
46
- create_credentials_file: true
47
- export_environment_variables: true
48
-
49
- - name: Set up Cloud SDK
50
- uses: google-github-actions/setup-gcloud@v1.1.0
51
-
52
- - name: Authenticate Artifact Repository
53
- run: gcloud auth configure-docker us-west1-docker.pkg.dev --quiet
54
-
55
- - name: Pull and run Looker docker image
56
- # TODO: can we cache some layers of the image for faster download?
57
- # we probably don't want to cache the final image for IP security...
58
- run: |
59
- docker pull --quiet us-west1-docker.pkg.dev/cloud-looker-sdk-codegen-cicd/looker/${{ matrix.looker }}
60
- # set $LOOKER_OPTS to --no-ssl if we want to turn off ssl
61
- docker run --name looker-sdk-codegen-ci -d -p 10000:9999 -p 20000:19999 us-west1-docker.pkg.dev/cloud-looker-sdk-codegen-cicd/looker/${{ matrix.looker }}
62
- docker logs -f looker-sdk-codegen-ci --until=30s &
63
-
64
- - name: Set up Ruby ${{ matrix.ruby-version }}
65
- uses: ruby/setup-ruby@v1
66
- with:
67
- ruby-version: ${{ matrix.ruby-version }}
68
- bundler-cache: false
69
-
70
- - name: Install dependencies
71
- run: bundle install
72
-
73
- - name: Mock .netrc
74
- run: |
75
- mkdir -p test/fixtures
76
- echo "machine localhost" > test/fixtures/.netrc
77
- echo " login $LOOKERSDK_CLIENT_ID" >> test/fixtures/.netrc
78
- echo " password $LOOKERSDK_CLIENT_SECRET" >> test/fixtures/.netrc
79
- chmod 600 test/fixtures/.netrc
80
-
81
- - name: Check that Looker is ready
82
- run: |
83
- ${{ github.workspace }}/.github/scripts/wait_for_looker.sh
84
-
85
- - name: Report Failure
86
- run: |
87
- curl --request POST \
88
- --url https://api.github.com/repos/looker-open-source/sdk-codegen/check-runs \
89
- --header "authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
90
- --header "content-type: application/json" \
91
- --header "Accept: application/vnd.github.v3+json" \
92
- --data '{
93
- "name": "Ruby-CI Tests",
94
- "head_sha": "${{ github.event.pull_request.head.sha || github.sha }}",
95
- "conclusion": "failure"
96
- }' \
97
- --fail
98
- if: failure()
99
-
100
- - name: Run tests
101
- run: bundle exec rake test --trace
102
- env:
103
- USE_FARADAY_MULTIPART: ${{ matrix.use_faraday_multipart }}
104
-
105
- - name: remove mock .netrc
106
- if: ${{ always() }}
107
- run: |
108
- rm -f test/fixtures/.netrc
109
-
110
- - name: Upload ts unit test results
111
- if: ${{ always() }}
112
- uses: actions/upload-artifact@v3.1.2
113
- with:
114
- name: ruby-ci-test-results
115
- path: results/
116
-
117
- publish-test-results:
118
- needs: [test]
119
- if: success() || failure()
120
- runs-on: ubuntu-latest
121
-
122
- steps:
123
- - name: Download Artifacts
124
- uses: actions/download-artifact@v3
125
- with:
126
- name: ruby-ci-test-results
127
- path: artifacts
128
-
129
- - name: Publish Test Results
130
- uses: EnricoMi/publish-unit-test-result-action@v1.12
131
- with:
132
- # Cosmetic issue with `check_name` being associated to the wrong
133
- # workflow: https://github.com/EnricoMi/publish-unit-test-result-action/issues/12
134
- check_name: Ruby-CI Tests
135
- github_token: ${{ secrets.GITHUB_TOKEN }}
136
- report_individual_runs: true
137
- hide_comments: orphaned commits
138
- check_run_annotations: 'none'
139
- compare_to_earlier_commit: false
140
- files: 'artifacts/**/*.xml'
data/.gitignore DELETED
@@ -1,60 +0,0 @@
1
- # Numerous always-ignore extensions
2
- *.diff
3
- *.err
4
- *.orig
5
- *.log
6
- *.rej
7
- *.swo
8
- *.swp
9
- *.vi
10
- *~
11
- *.sass-cache
12
- *.iml
13
- .ruby-version
14
-
15
- # OS or Editor folders
16
- .DS_Store
17
- .cache
18
- .project
19
- .settings
20
- .tmproj
21
- nbproject
22
- Thumbs.db
23
-
24
- # Folders to ignore
25
- intermediate
26
- publish
27
- target
28
- .idea
29
- .direnv
30
- .env
31
- out
32
-
33
- # markdown previews
34
- *.md.html
35
-
36
- # bundler suggested ignores
37
- *.gem
38
- *.rbc
39
- .bundle
40
- .config
41
- .yardoc
42
- Gemfile.optional.lock
43
- InstalledFiles
44
- _yardoc
45
- coverage
46
- doc/
47
- lib/bundler/man
48
- pkg
49
- rdoc
50
- spec/reports
51
- test/tmp
52
- test/version_tmp
53
- tmp
54
- *.netrc
55
-
56
- # credentials for testing
57
- .netrc
58
-
59
- # test output
60
- /test/reports/**
data/.ruby-gemset DELETED
@@ -1 +0,0 @@
1
- looker-sdk-ruby
data/Gemfile DELETED
@@ -1,22 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- group :development do
4
- gem 'awesome_print', '~>1.6.1', :require => 'ap'
5
- gem 'redcarpet', '~>3.5.1', :platforms => :ruby
6
- end
7
-
8
- group :development, :test do
9
- gem 'rake', '~> 13.0.3'
10
- end
11
-
12
- group :test do
13
- # gem 'json', '~> 1.7', :platforms => [:jruby] look TODO needed?
14
- gem 'minitest', '~> 5.11.0'
15
- gem 'mocha', '~> 1.1.0'
16
- gem 'rack', '~> 2.2.7'
17
- gem 'rack-test', '~> 1'
18
- gem 'netrc', '~> 0.7.7'
19
- gem 'simplecov', '~> 0.7.1', :require => false
20
- end
21
-
22
- gemspec
data/Gemfile.lock DELETED
@@ -1,73 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- looker-sdk (0.1.7)
5
- faraday (>= 1.2, < 3.0)
6
- sawyer (~> 0.8)
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- addressable (2.8.1)
12
- public_suffix (>= 2.0.2, < 6.0)
13
- awesome_print (1.6.1)
14
- builder (3.2.4)
15
- ci_reporter (2.1.0)
16
- builder (>= 2.1.2)
17
- rexml
18
- ci_reporter_minitest (1.0.0)
19
- ci_reporter (~> 2.0)
20
- minitest (~> 5.0)
21
- faraday (2.7.8)
22
- faraday-net_http (>= 2.0, < 3.1)
23
- ruby2_keywords (>= 0.0.4)
24
- faraday-multipart (1.0.4)
25
- multipart-post (~> 2)
26
- faraday-net_http (3.0.2)
27
- faraday-rack (2.0.0)
28
- faraday (~> 2.0)
29
- metaclass (0.0.4)
30
- minitest (5.11.3)
31
- mocha (1.1.0)
32
- metaclass (~> 0.0.1)
33
- multi_json (1.15.0)
34
- multipart-post (2.3.0)
35
- netrc (0.7.9)
36
- public_suffix (5.0.1)
37
- rack (2.2.7)
38
- rack-test (1.1.0)
39
- rack (>= 1.0, < 3)
40
- rake (13.0.6)
41
- redcarpet (3.5.1)
42
- rexml (3.2.5)
43
- ruby2_keywords (0.0.5)
44
- sawyer (0.9.2)
45
- addressable (>= 2.3.5)
46
- faraday (>= 0.17.3, < 3)
47
- simplecov (0.7.1)
48
- multi_json (~> 1.0)
49
- simplecov-html (~> 0.7.1)
50
- simplecov-html (0.7.1)
51
-
52
- PLATFORMS
53
- arm64-darwin-22
54
- x86_64-linux
55
-
56
- DEPENDENCIES
57
- awesome_print (~> 1.6.1)
58
- ci_reporter_minitest (~> 1.0)
59
- faraday (~> 2.7)
60
- faraday-multipart (~> 1.0)
61
- faraday-rack (~> 2)
62
- looker-sdk!
63
- minitest (~> 5.11.0)
64
- mocha (~> 1.1.0)
65
- netrc (~> 0.7.7)
66
- rack (~> 2.2.7)
67
- rack-test (~> 1)
68
- rake (~> 13.0.3)
69
- redcarpet (~> 3.5.1)
70
- simplecov (~> 0.7.1)
71
-
72
- BUNDLED WITH
73
- 2.4.14
data/Makefile DELETED
@@ -1,81 +0,0 @@
1
- #############################################################################################
2
- # The MIT License (MIT)
3
- #
4
- # Copyright (c) 2014 Zee Spencer
5
- # Copyright (c) 2020 Google LLC
6
- #
7
- # Permission is hereby granted, free of charge, to any person obtaining a copy
8
- # of this software and associated documentation files (the "Software"), to deal
9
- # in the Software without restriction, including without limitation the rights
10
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
- # copies of the Software, and to permit persons to whom the Software is
12
- # furnished to do so, subject to the following conditions:
13
- #
14
- # The above copyright notice and this permission notice shall be included in all
15
- # copies or substantial portions of the Software.
16
- #
17
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
- # SOFTWARE.
24
- #############################################################################################
25
-
26
- # Allows running (and re-running) of tests against several ruby versions,
27
- # assuming you use rbenv instead of rvm.
28
-
29
- # Uses pattern rules (task-$:) and automatic variables ($*).
30
- # Pattern rules: http://ftp.gnu.org/old-gnu/Manuals/make-3.79.1/html_chapter/make_10.html#SEC98
31
- # Automatic variables: http://ftp.gnu.org/old-gnu/Manuals/make-3.79.1/html_chapter/make_10.html#SEC101
32
-
33
- # Rbenv-friendly version identifiers for supported Rubys
34
- 25_version = 2.5.7
35
- jruby_92160_version = jruby-9.2.16.0
36
-
37
- # The ruby version for use in a given rule.
38
- # Requires a matched pattern rule and a supported ruby version.
39
- #
40
- # Given a pattern rule defined as "install-ruby-%"
41
- # When the rule is ran as "install-ruby-193"
42
- # Then the inner addsuffix call evaluates to "193_version"
43
- # And given_ruby_version becomes "1.9.3-p551"
44
- given_ruby_version = $($(addsuffix _version, $*))
45
-
46
- # Instruct rbenv on which Ruby version to use when running a command.
47
- # Requires a pattern rule and a supported ruby version.
48
- #
49
- # Given a pattern rule defined as "test-%"
50
- # When the rule is ran as "test-187"
51
- # Then with_given_ruby becomes "RBENV_VERSION=1.8.7-p375"
52
- with_given_ruby = RBENV_VERSION=$(given_ruby_version)
53
-
54
- # Runs tests for all supported ruby versions.
55
- test: test-25 test-jruby_92160
56
-
57
- # Runs tests against a specific ruby version
58
- test-%:
59
- rm -f Gemfile.lock
60
- $(with_given_ruby) bundle install --quiet
61
- $(with_given_ruby) bundle exec rake
62
-
63
- # Installs all ruby versions and their gems
64
- install: install-25 install-jruby_92160
65
-
66
- # Install a particular ruby version
67
- install-ruby-%:
68
- rm -f Gemfile.lock
69
- rbenv install -s $(given_ruby_version)
70
-
71
- # Install gems into a specific ruby version
72
- install-gems-%:
73
- rm -f Gemfile.lock
74
- $(with_given_ruby) gem update --system
75
- $(with_given_ruby) gem install bundler
76
- $(with_given_ruby) bundle install
77
-
78
- # Installs a specific ruby version and it's gems
79
- # At the bottom so it doesn't match install-gems and install-ruby tasks.
80
- install-%:
81
- make install-ruby-$* install-gems-$*
data/Rakefile DELETED
@@ -1,38 +0,0 @@
1
- ############################################################################################
2
- # The MIT License (MIT)
3
- #
4
- # Copyright (c) 2022 Looker Data Sciences, Inc.
5
- #
6
- # Permission is hereby granted, free of charge, to any person obtaining a copy
7
- # of this software and associated documentation files (the "Software"), to deal
8
- # in the Software without restriction, including without limitation the rights
9
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- # copies of the Software, and to permit persons to whom the Software is
11
- # furnished to do so, subject to the following conditions:
12
- #
13
- # The above copyright notice and this permission notice shall be included in
14
- # all copies or substantial portions of the Software.
15
- #
16
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
- # THE SOFTWARE.
23
- ############################################################################################
24
-
25
- require "bundler/gem_tasks"
26
-
27
- require "rake/testtask"
28
- require 'ci/reporter/rake/minitest'
29
-
30
- task :minitest => 'ci:setup:minitest'
31
- task test: 'minitest'
32
- Rake::TestTask.new do |t|
33
- t.libs << "test"
34
- t.test_files = FileList["test/**/test_*.rb"]
35
- t.verbose = true
36
- end
37
-
38
- task :default => :test
data/examples/.netrc DELETED
@@ -1 +0,0 @@
1
- machine localhost login xyYBxzSPYYP29wQJ3Q5k password VY5sj6z5qjxZsvdvf8yNvKcQ
@@ -1,118 +0,0 @@
1
- ############################################################################################
2
- # The MIT License (MIT)
3
- #
4
- # Copyright (c) 2022 Looker Data Sciences, Inc.
5
- #
6
- # Permission is hereby granted, free of charge, to any person obtaining a copy
7
- # of this software and associated documentation files (the "Software"), to deal
8
- # in the Software without restriction, including without limitation the rights
9
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- # copies of the Software, and to permit persons to whom the Software is
11
- # furnished to do so, subject to the following conditions:
12
- #
13
- # The above copyright notice and this permission notice shall be included in
14
- # all copies or substantial portions of the Software.
15
- #
16
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
- # THE SOFTWARE.
23
- ############################################################################################
24
-
25
- require './sdk_setup'
26
-
27
- ############################################################################################
28
- # simulate a list read from file
29
-
30
- user_list = <<-ENDMARK
31
-
32
- Joe Williams, joe@mycoolcompany.com, Admin
33
- Jane Schumacher, jane@mycoolcompany.com, User SuperDeveloper
34
- Jim Watson, jim@mycoolcompany.com, User
35
- Jim Wu, jimw@mycoolcompany.com, User
36
-
37
- ENDMARK
38
-
39
- ############################################################################################
40
-
41
- def create_users(lines)
42
- # create a hash to use below. role.name => role.id
43
- roles_by_name = Hash[ sdk.all_roles.map{|role| [role.name, role.id] } ]
44
-
45
- # for each line, try to create that user with name, email credentials, and roles
46
- lines.each_line do |line|
47
- line.strip!
48
- next if line.empty?
49
-
50
- # quicky parsing: note lack of error handling!
51
-
52
- name, email, roles = line.split(',')
53
- fname, lname = name.split(' ')
54
- [fname, lname, email, roles].each(&:strip!)
55
-
56
- role_ids = []
57
- roles.split(' ').each do |role_name|
58
- if id = roles_by_name[role_name]
59
- role_ids << id
60
- else
61
- raise "#{role_name} does not exist. ABORTING!"
62
- end
63
- end
64
-
65
- # for display
66
- user_info = "#{fname} #{lname} <#{email}> as #{roles}"
67
-
68
- begin
69
- # call the SDK to create user with names, add email/password login credentials, set user roles
70
- user = sdk.create_user({:first_name => fname, :last_name => lname})
71
- sdk.create_user_credentials_email(user.id, {:email => email})
72
- sdk.set_user_roles(user.id, role_ids)
73
- puts "Created user: #{user_info}"
74
- rescue LookerSDK::Error => e
75
- # if any errors occur above then 'undo' by deleting the given user (if we got that far)
76
- sdk.delete_user(user.id) if user
77
- puts "FAILED to create user: #{user_info} (#{e.message}) "
78
- end
79
- end
80
- end
81
-
82
- ##################################################################
83
-
84
- def delete_users(lines)
85
- # create a hash to use below. user.credentials_email.email => user.id
86
- users_by_email = Hash[ sdk.all_users.map{|user| [user.credentials_email.email, user.id] if user.credentials_email}.compact ]
87
-
88
- lines.each_line do |line|
89
- line.strip!
90
- next if line.empty?
91
-
92
- # quicky parsing: note lack of error handling!
93
- name, email, roles = line.split(',')
94
- fname, lname = name.split(' ')
95
- [fname, lname, email, roles].each(&:strip!)
96
-
97
- # for display
98
- user_info = "#{fname} #{lname} <#{email}>"
99
-
100
- begin
101
- if id = users_by_email[email]
102
- sdk.delete_user(id)
103
- puts "Deleted user: #{user_info}>"
104
- else
105
- puts "Did not find user: #{user_info}>"
106
- end
107
- rescue LookerSDK::Error => e
108
- puts "FAILED to delete user: #{user_info} (#{e.message}) "
109
- end
110
- end
111
- end
112
-
113
- ##################################################################
114
-
115
- # call the methods
116
- create_users(user_list)
117
- puts
118
- delete_users(user_list)
@@ -1,47 +0,0 @@
1
- ############################################################################################
2
- # The MIT License (MIT)
3
- #
4
- # Copyright (c) 2022 Looker Data Sciences, Inc.
5
- #
6
- # Permission is hereby granted, free of charge, to any person obtaining a copy
7
- # of this software and associated documentation files (the "Software"), to deal
8
- # in the Software without restriction, including without limitation the rights
9
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- # copies of the Software, and to permit persons to whom the Software is
11
- # furnished to do so, subject to the following conditions:
12
- #
13
- # The above copyright notice and this permission notice shall be included in
14
- # all copies or substantial portions of the Software.
15
- #
16
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
- # THE SOFTWARE.
23
- ############################################################################################
24
-
25
- require './sdk_setup'
26
-
27
- users = Hash[
28
- sdk.all_users(:fields => 'id, credentials_email').
29
- map{|u| [u.credentials_email.email, u.id] if u.credentials_email }.compact
30
- ]
31
-
32
- $stdin.each_line do |line|
33
- line.chomp!
34
-
35
- _, old_email, new_email = line.split(',', 3).map(&:strip)
36
-
37
- if id = users[old_email]
38
- begin
39
- sdk.update_user_credentials_email(id, {:email => new_email})
40
- puts "Successfully changed '#{old_email}' => '#{new_email}'"
41
- rescue => e
42
- puts "FAILED to changed '#{old_email}' => '#{new_email}' because of: #{e.class}:#{e.message}"
43
- end
44
- else
45
- puts "FAILED: Could not find user with email '#{old_email}'"
46
- end
47
- end